WPF Binding multiple usercontrol to one viewmodel

Shaban Mehmet 1 Reputation point
2020-04-24T07:27:33.197+00:00

My program is basicly a truck diary. I have a main page that is set up like a diary with days of the week listed. In them days of the week I have a custom control called TripUI which is setup in a listview and bound to a ObservableCollection from my viewmodel. Im having trouble binding this usercontrol to my viewmodel. I can populate the list with the usercontrol but no data is displayed to the info inside my usercontrol. Thanks in advance, Shaban.

Here is my user control xaml

<UserControl x:Class="TripUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialdesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:KBTTruckManager"
mc:Ignorable="d"
d:DesignHeight="200" Width="204"
x:Name="TripUI">

<Grid >
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Border CornerRadius="5" BorderBrush="Black" Grid.RowSpan="2" Background="#FFA8A7A7"/>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
        <Button x:Name="BtnView" Width="20" Height="20" Foreground="Black" Background="{x:Null}" BorderBrush="{x:Null}" ToolTip="Add Containers" Margin="5,0,0,0" Command="{Binding AddContainer}">
            <materialdesign:PackIcon Kind="Plus" VerticalAlignment="Center" HorizontalAlignment="Center" Height="20" Width="20"/>
        </Button>
        <TextBlock Text="{Binding ElementName=TrpUI,Path=Truck}" Margin="5,0,0,0"/>
        <TextBlock Text="{Binding ElementName=TrpUI,Path= TripID}" Margin="5,0,0,0"/>
        <!--<TextBlock Text="{Binding Trailor}" Margin="5,0,0,0"/>-->
    </StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
        <Button x:Name="BtnDelete" Width="20" Height="20" Foreground="Black" Background="{x:Null}" BorderBrush="{x:Null}" ToolTip="Delete Trip"  Margin="5,0,0,0" Command="{Binding BtnDeleteTrip}">
            <materialdesign:PackIcon Kind="Delete" VerticalAlignment="Center" HorizontalAlignment="Center" Height="20" Width="20"/>
        </Button>
    </StackPanel>

        <ListBox x:Name="LoadList" ItemsSource="{Binding LoadContainorList}" Grid.Row="1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                <!--<local:ContainerUI />-->
            </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

</Grid>

</UserControl>

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,696 questions
{count} votes