I created a simple MVPM wpf project. The main idea is to display data on the client's annual income and on the loans that he has with various banks.
The model consists of 2 classes, financial and financial. ViewModel consists of 2 classes FinancialVM and FinancialLoanVM
The following are the VM classes:
namespace WpfTester.ViewModel{ public class FinancialVM { public Model.Financial Financial { get; set; } public ObservableCollection<ViewModel.FinancialLoanVM> FinancialLoanVMs { get; set; } public FinancialVM() {
}
The user interface has financial control of the user, with it the datacontext bound to FinancialVM and the FinancialLoan User control with the datacontext bound to FinancialLoanVM.
The problem is the face, this is the list. I programmed it that the financialLoans user controls are elements, but the associated data does not fall into the DataContext FinancialLoanUC. I guess the trick is all in the data list part. Any ideas on how I can make this work?
<UserControl.DataContext> <ViewModel:FinancialVM/> </UserControl.DataContext> <Grid d:DataContext="{d:DesignInstance Type=ViewModel:FinancialVM}" > <Grid.RowDefinitions> <RowDefinition Height="23"/> <RowDefinition/> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal"> <TextBlock Text="Income= "/> <Label Content="{Binding Path=Financial.Income}"/> </StackPanel> <ListBox Grid.Row="1" ItemsSource="{Binding Path=FinancialLoanVMs}"> <ListBox.ItemTemplate> <DataTemplate> <View:FinancialLoanUC DataContext="{Binding }" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>
source share