question

shabanmehmet avatar image
0 Votes"
shabanmehmet asked ·

WPF Binding multiple usercontrol to one viewmodel

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-wpf
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, it is not clear which DataContext you use (local from UserControl or global from MainWindow) and where are located "TrpUI" and "LoadContainorList".

0 Votes 0 · ·

0 Answers