I'm creating a WPF Application.
I have a View which implements two different User-Controls. The Data Context for each Control needs to be the same, because when I change values in one control it should effect the other one. As soon as I select a date in my view the DataContext (which is a List of information) should be set to each control. I already tried Binding the List to the Control. What kinda worked. The Listbox showed that there were elements but the content was not visible.
<ListView x:Name="ListViewEmployees" ItemsSource="{Binding Employees}">
<ListView.Items>
<Label x:Name="EmployeeId" Content="{Binding Path=EmployeeId}" Visibility="Collapsed" />
<Label x:Name="ShortForm" Content="{Binding Path=ShortForm}" Width="40"/>
<Label x:Name="Degree" Content="{Binding Path=Degree}" Width="90"/>
<Label x:Name="WorkingHours" Content="{Binding Path=WorkingHours}" Width="30"/>
</ListView.Items>
</ListView>
So my question is, as soon as I pass the date to my controller and he gets the needed information from the database whats the way to pass the List to my user controls. Do I need to create an Interface which is implemented by the UserControls?
I used the MVVM pattern a lot. But for this university thing we have to use mvc. A little advice would be great.
cheers
You've bound the ItemsSource of the ListView to a collection of Employee objects, then immediately attempted to fill it with Label objects. That's not going to work - if your ItemsSource is bound to a collection all you have to do is fill that collection in your VM/controller, not manually specify XAML items. The closest approximation to what I think you're trying to do is to use a DataTemplate to display the properties of each Employee object:
For my test case I created a garbage class called Employee with property names matching yours, then created an ObservableCollection, then filled it with test values. The binding took care of the rest.