Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DependencyProperty的PropertyChangedCallback忽略延迟绑定_C#_Wpf_Xaml - Fatal编程技术网

C# DependencyProperty的PropertyChangedCallback忽略延迟绑定

C# DependencyProperty的PropertyChangedCallback忽略延迟绑定,c#,wpf,xaml,C#,Wpf,Xaml,我有一个带有文本框的用户控件和一个基本上是带有CollectionView的ListBox的自定义列表控件。我想使用CollectionView的过滤功能,并使用文本框中的文本过滤可见元素 xaml的简化表示法: <TextBox x:Name="FilterTextControl"/> <CustomControls:OverviewControl x:Name="ProfileOverviewControl" FilterText="{Binding Ele

我有一个带有文本框的用户控件和一个基本上是带有CollectionView的ListBox的自定义列表控件。我想使用CollectionView的过滤功能,并使用文本框中的文本过滤可见元素

xaml的简化表示法:

<TextBox x:Name="FilterTextControl"/>
<CustomControls:OverviewControl
    x:Name="ProfileOverviewControl"
    FilterText="{Binding ElementName=FilterTextControl, Path=Text, Mode=OneWay, Delay=5000}"
    Items="{Binding AllItems}"/>
OnFilterEvent方法:

    private void GroupedProfiles_OnFilter(object sender, FilterEventArgs e)
    {
        e.Accepted = string.IsNullOrEmpty(FilterText) || e.Item.ToString().Contains(FilterText);
    }
问题

正如您在FilterText的绑定中看到的,我有5000ms的延迟。出于测试目的,我将其设置为5000ms,而不是合理的500ms。 为了使过滤器工作,我需要刷新CollectionView。 但是,PropertyChangedCallback会在每次更改后立即触发,而不是使用延迟绑定对其进行限制


我不太明白这种行为。如果延迟绑定就是这样工作的,那么是否有其他方法来限制CollectionView刷新?

尝试像这样反转绑定。这样,延迟将在文本框上更改。现在,延迟取决于过滤器属性更改(如果从概览控件更改)


多么好的主意!非常简单,完全符合我的要求!
public string FilterText
{
    get => (string)GetValue(FilterTextProperty);
    set => SetValue(FilterTextProperty, value);
}

public static readonly DependencyProperty FilterTextProperty =
    DependencyProperty.Register(nameof(FilterText), typeof(string), 
    typeof(ProfileOverviewControl), new FrameworkPropertyMetadata(OnFilterTextChanged));

private static void OnFilterTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
     var intanceOfThisClass = (ProfileOverviewControl)d;
        if (_collectionViewSource == null) 
        _collectionViewSource = intanceOfThisClass.FindResource("GroupedProfiles") as CollectionViewSource;
     _collectionViewSource?.View?.Refresh();
}
    private void GroupedProfiles_OnFilter(object sender, FilterEventArgs e)
    {
        e.Accepted = string.IsNullOrEmpty(FilterText) || e.Item.ToString().Contains(FilterText);
    }
<TextBox x:Name="FilterTextControl" Text="{Binding ElementName=ProfileOverviewControl, Path=FilterText, Delay=5000}"/>
<CustomControls:OverviewControl
    x:Name="ProfileOverviewControl"
    Items="{Binding AllItems}"/>