Reputation: 875
I'm starting to go nuts here, I'm new to WPF and this seems so difficult. I come from MVC and what I'm looking to do is a snap in Razor. I am trying to bind the below:
public ObservableCollection<FundFamilySum> FundFamilyCredits { get; set; }
that property as a property:
public ObservableCollection<BrokerCredit> BrokerCreditList { get; set; }
I'd also like to bind this to a 'child' data template. How does one go about binding enumerable properties of enumerable classes? I'm playing around with ItemsControl, but keep getting errors on the TreeView already being set or everything renders into one cell of my grid, ontop of each other. I ended up moving to the ItemsControl after running into issues with the below code, but this just confused me more :(.
I would really appreciate any guidance in this matter as I just can't get the breakdown. I get the FundFamilyCredit.FundFamilyName
to bind, but I don't get the convention for the BrokerCreditList
to bind with a DataTemplate.
Thanks!
XAML
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="8*"></ColumnDefinition>
</Grid.ColumnDefinitions>-->
<TextBlock Text="{Binding Path=FundFamilyName}" Grid.Row="0" Grid.Column="0" Background="White" FontSize="14" Foreground="Black"></TextBlock>
<ItemsControl ItemsSource="{Binding Path=BrokerCreditList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Background="White" Foreground="Black" FontSize="14" Text="{Binding Path=BrokerName}"></TextBlock>
<Rectangle Width="20" Height="20" Grid.Row="0" Grid.Column="1"></Rectangle>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Upvotes: 1
Views: 714
Reputation: 6455
I think you got almost everything right. As i see it, only thing wrong is you are missing one row definition and you didn't setup inner ItemsControl into second row
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition> <!-- NEW ROW HERE-->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="8*"></ColumnDefinition>
</Grid.ColumnDefinitions>-->
<TextBlock Text="{Binding Path=FundFamilyName}" Grid.Row="0" Grid.Column="0" Background="White" FontSize="14" Foreground="Black"></TextBlock>
<!--ITEMS CONTROL INTO SECOND ROW-->
<ItemsControl Grid.Row="1" ItemsSource="{Binding Path=BrokerCreditList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Background="White" Foreground="Black" FontSize="14" Text="{Binding Path=BrokerName}"></TextBlock>
<Rectangle Width="20" Height="20" Grid.Row="0" Grid.Column="1"></Rectangle>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Upvotes: 3