shabanmehmet avatar image
0 Votes"
shabanmehmet asked PeterFleischer-3316 commented

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"
d:DesignHeight="200" Width="204"

 <Grid >
         <RowDefinition Height="20"/>
         <RowDefinition Height="*"/>
     <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"/>
         <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 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"/>

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


· 1
5 |1600 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