Infragistics XamTreeGrid-如何知道何时完成过滤

时间:2018-11-01 14:02:55

标签: c# wpf infragistics

我当前在我的应用程序中使用XamTreeGrid,并且我的AllowRecordFiltering属性设置为true。 XamTreeGrid中的数据是两层,父层和子层。我看到的是,每当从XamTreeGrid的过滤下拉列表中选择一个与子级别匹配的过滤器时,所有与该过滤器匹配的父记录都会展开。

我不希望父记录扩大。可以通过预订XamTreeGrid.RecordExpanding事件并将RecordExpandingEventArgs.Cancel设置为true来解决。这样可以防止发生过滤时父记录的扩展;但是,这带来了另一个问题:父记录永远无法扩展。是否有属性可以检查XamTreeGrid是否完成过滤或在过滤完成时触发的事件?如果有的话,只要过滤操作尚未完成,我就只能有条件地将RecordExpandingEventArgs.Cancel设置为true。我已经尝试订阅RecordFilterChanging和RecordFilterChanged事件,但是它们都在RecordExpanding事件被触发之前被触发了。

我已经制作了一个简单的应用程序,可以再现我的问题。 Here is a video of me reproducing the problem

下面是重现问题的简单应用程序的代码。

MainWindow.xaml

<Window x:Class="TreeGrid.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TreeGrid"
        xmlns:igdp="http://infragistics.com/DataPresenter"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        d:DataContext="{d:DesignInstance local:MainViewModel, d:IsDesignTimeCreatable=False}">
    <Window.DataContext>
        <local:MainViewModel />
    </Window.DataContext>
    <igdp:XamTreeGrid DataSource="{Binding Parents}"
                      RecordExpanding="OnRecordExpanding">
        <igdp:XamTreeGrid.FieldLayoutSettings>
            <igdp:FieldLayoutSettings AutoGenerateFields="False"
                                      AllowFieldMoving="No"/>
        </igdp:XamTreeGrid.FieldLayoutSettings>

        <igdp:XamTreeGrid.ViewSettings>
            <igdp:TreeViewSettings>
                <igdp:TreeViewSettings.TreeLinePen>
                    <Pen Thickness="0" />
                </igdp:TreeViewSettings.TreeLinePen>
            </igdp:TreeViewSettings>
        </igdp:XamTreeGrid.ViewSettings>

        <igdp:XamTreeGrid.FieldSettings>
            <igdp:FieldSettings AllowEdit="False"
                                AllowRecordFiltering="True"/>
        </igdp:XamTreeGrid.FieldSettings>

        <igdp:XamTreeGrid.FieldLayouts>
            <igdp:FieldLayout Key="Parent">
                <igdp:TextField Name="ParentNumber" />
                <igdp:TextField Name="ChildNumber" BindingType="Unbound" />
                <igdp:Field Name="Children" />
            </igdp:FieldLayout>

            <igdp:FieldLayout Key="Child" ParentFieldLayoutKey="Parent">
                <igdp:TextField Name="ChildNumber" />
            </igdp:FieldLayout>
        </igdp:XamTreeGrid.FieldLayouts>
    </igdp:XamTreeGrid>
</Window>

MainWindow.xaml.cs

public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void OnRecordExpanding(object sender, RecordExpandingEventArgs e)
    {
        if(/* some way to know if filtering is not finished */)
        {
            e.Cancel = true;
            return;
        }

        /* Rest of logic here... */
    }
}

MainViewModel.cs

public class MainViewModel : ViewModelBase
{
    public ObservableCollection<Parent> Parents { get; } = new ObservableCollection<Parent>();

    public MainViewModel()
    {
        for(int i = 0; i < 10; i++)
        {
            var parent = new Parent(i);

            for(int j = 0; j < 2; j++)
            {
                parent.Children.Add(new Child(j));
            }
            Parents.Add(parent);
        }
    }
}

父母

public class Parent : ViewModelBase
{
    private int _parentNumber;

    public int ParentNumber
    {
        get { return _parentNumber; }
        set { Set(ref _parentNumber, value); }
    }

    public ObservableCollection<Child> Children { get; } = new ObservableCollection<Child>();

    public Parent(int parentNumber)
    {
        ParentNumber = parentNumber;
    }
}

Child.cs

public class Child : ViewModelBase
{
    private int _childNumber;

    public int ChildNumber
    {
        get { return _childNumber; }
        set { Set(ref _childNumber, value); }
    }

    public Child(int childNumber)
    {
        ChildNumber = childNumber;
    }
}

0 个答案:

没有答案