如何将列表视图项的选择冒泡限制为其子列表视图?

时间:2019-10-21 08:19:42

标签: c# xaml listview uwp

我有一个列表视图,而每个父列表视图项都有一个子列表视图。当我在父级列表视图中选择一个项目时,它的子级列表视图项也正在被选择。

有没有办法防止这种冒泡?

以下是作为用户控件的父级listview项的片段:

NestedControl.xaml ”递归重复。

   <Grid Margin="20,0,0,0"
          VerticalAlignment="Center" BorderBrush="#F0F0F0" BorderThickness="0,1,0,0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <RelativePanel VerticalAlignment="Center" Grid.Column="1"
                                       >
        <TextBlock x:Name="Name" Text="{Binding Name,Mode=OneWay}" TextTrimming="CharacterEllipsis"
                                       VerticalAlignment="Center" Opacity="0.5" Margin="0,0,0,10"/>
        <Image x:Name="Dot1" Source="{Image Path here}" 
                                           Height="6" Width="6"
                                           VerticalAlignment="Center" Margin="10,8,0,10" 
                                           RelativePanel.RightOf="Name"/>
    </RelativePanel>
    <ListView SelectionMode="Single" ItemsSource="{Binding NestedEntities,Mode=OneWay}" Grid.Row="1"
              x:Name="NestedListView" Grid.ColumnSpan="3">
        <ListView.ItemContainerTransitions>
            <TransitionCollection/>
        </ListView.ItemContainerTransitions>
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalAlignment" Value="Stretch"/>
                <Setter Property="Margin" Value="0"/>
                <Setter Property="Padding" Value="0,0,0,0"/>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.ItemTemplate>
            <DataTemplate x:DataType="entity:Detail">
                <controls:NestedControl/>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</Grid>

Nested list view

在上图中,当我选择“主要项目5”时,将加载嵌套列表视图,并且父列表视图项将得到扩展。

0 个答案:

没有答案