WPF嵌套列表视图 - 家长的ListView了selectedValue [英] WPF Nested ListViews - selectedValue of parent ListView

查看:164
本文介绍了WPF嵌套列表视图 - 家长的ListView了selectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表视图,包含其项模板子列表视图父。

I have two list views, a parent that contains a child list view with its item template.

<ListView Name="TopView">
    <ListView.ItemTemplate>
        <DataTemplate>
             <ListView ItemsSource="{Binding SubList}"Focusable="False">
                  <ListView.Background>
                        <SolidColorBrush Color="Transparent"/>                                                  
                  </ListView.Background>
                  <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Path=Number}" Grid.Column="0" />
                                <TextBlock Text="{Binding Path=Type}" Grid.Column="1" />
                                <TextBlock Text="{Binding Path=Code}" Grid.Column="2"  />
                            </Grid>
                        </DataTemplate>
                  </ListView.ItemTemplate>
             </ListView>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

每当尝试使用TopView.SelectedValue,返回的值总是空。

Whenever attempting to use TopView.SelectedValue, the value returned is always null.

我怎样才能让家长的ListView被接受的选择事件,而不是孩子的ListView唯一的ListView?我想,我需要做的事件路由的东西,但我不知道是什么。

How can I make the parent ListView be the only ListView to accept selection events instead of the child ListView? I figure I need to do something with event routing but I'm not sure what.

推荐答案

好了,没想到你手动灌装混合数据绑定。我假设你内心的列表视图消耗选择的事件。你必须泡沫,一个爬在树上,直到你打冠捷。处理它应提高下一个列表视图时,IIRC后在内部ListView控件的句柄的e.handled属性设置为false。

Ok, did not expect that you mix databinding with manual filling. I assume that your inner Listview consumes the select-event. You'll have to bubble that one up in the tree until you hit TopView. set the e.handled property in the inner Listview's handler to false after processing it should raise the event for the next listview, iirc.

private void handleInner(object o, RoutedEventArgs e)
{
    InnerControl innerControl = e.OriginalSource as InnerControl;
    if (innerControl  != null)
    {
        //do whatever
    }
    e.Handled = false;
}

这篇关于WPF嵌套列表视图 - 家长的ListView了selectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆