简体   繁体   English

WPF列表在列表中绑定

[英]WPF Listing Binding within a list

I'm starting to go nuts here, I'm new to WPF and this seems so difficult. 我开始疯狂了,我是WPF的新手,这看起来很难。 I come from MVC and what I'm looking to do is a snap in Razor. 我来自MVC,我想要做的是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. 我正在使用ItemsControl,但是一直在设置TreeView上的错误,或者所有内容都渲染到我的网格的一个单元格中,彼此在顶部。 I ended up moving to the ItemsControl after running into issues with the below code, but this just confused me more :(. 我结束了移动到ItemsControl的运行遇到与下面的代码之后,但这个只是困惑我更:(。

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. 我得到FundFamilyCredit.FundFamilyName来绑定,但我没有得到BrokerCreditList与DataTemplate绑定的约定。
Thanks! 谢谢!

XAML 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>

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设置为第二行

  <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM