0

我有一个嵌套的 ListView,但 ItemSource 绑定永远不会触发。我在这里错过了什么吗?在这里你可以看到我的父列表视图,它绑定得很好。但是嵌套的没有。

<ListView ItemsSource="{Binding Items}">
        <ListView.View>
            <GridView>
                <GridViewColumn>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="25"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <StackPanel Orientation="Horizontal" Grid.Row="0">
                                    <CheckBox IsChecked="True" Margin="0,0,5,0"></CheckBox>
                                    <TextBlock Text="{Binding Name}" Margin="0,0,15,0"/>
                                    <TextBlock Text="Task Set Loop: "/>
                                    <TextBox Text="{Binding Scenarios}"/>
                                </StackPanel>
                                <ListView Grid.Row="1" ItemsSource="{Binding ChildItems, Converter={StaticResource DebugBindingConverter}}">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" Grid.Row="0">
                                                <CheckBox IsChecked="True" Margin="0,0,5,0"></CheckBox>
                                                <TextBlock Text="{Binding Name}" Margin="0,0,15,0"/>
                                                <ComboBox SelectedItem="{Binding DependentTaskName}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
4

2 回答 2

0

我对 ChildItems 的绑定处于错误的级别。将该行更改为:

<ListView Grid.Row="1" ItemsSource="{Binding Path=DataContext.ChildItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
于 2012-06-06T11:49:18.727 回答
0

对于 UWP 我们可以这样得到

<GridView x:Name="abc" ItemsSource="{Binding Path=DataContext.Companies,RelativeSource={RelativeSource Mode=TemplatedParent}}"></GridView>
于 2016-05-12T12:34:43.173 回答