WPF扩大内需列表视图特定扩展 [英] WPF Expand specific Expander inside Listview

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

问题描述

我有一个列表视图中的groupstyle,我已经定义(低于code)的扩展,我编程许多项目添加到被添加到相应的扩展器和扩展器是否不FO新项目存在的ListView ,它就会被动态地创建。

I have a listview in which's groupstyle, i have defined an expander(code below), i programmatically add many items to the listview which get added to the appropriate expander and if the expander does not exist fo the new item, it gets created dynamically.

<ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True" >
                                            <Expander.Header>
                                                <DockPanel>
                                                    <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                                </DockPanel>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>

所以,需要做的事情是,当添加一个新的项目,重点应转移到该项目,并扩展应扩大而崩溃一切...

So what needs to be done is that when a new item is added, the focus should divert to that item and the expander should be expanded while collapsing all else...

推荐答案

使用绑定,看看是否列出的SelectedItem是我们必然要在集团的一部分。

Use a binding to see if the lists SelectedItem is part of the Group that we are bound to.

<Expander IsExpanded="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListView, AncestorLevel=1}, Path=SelectedItem, Converter={StaticResource yourConverter}, ConverterParameter={Binding}}" >

您将绑定IsExpanded到列表中的SelectedItem,与绑定到视图模型,并有转换器只需检查,看看是否匹配参数转换器参数。

You will Bind IsExpanded to the lists SelectedItem, with a converter parameter that is bound to the viewmodel and have the converter simply check to see if the arguments match.

该转换器只返回true或false

The converter simply returns true or false

public class yourConvertor : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((GroupItem)parameter).Contains(value);
    }
 }

这篇关于WPF扩大内需列表视图特定扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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