Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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# DevExpress LookUpEdit中的自定义搜索/筛选_C#_Wpf_Mvvm_Devexpress - Fatal编程技术网

C# DevExpress LookUpEdit中的自定义搜索/筛选

C# DevExpress LookUpEdit中的自定义搜索/筛选,c#,wpf,mvvm,devexpress,C#,Wpf,Mvvm,Devexpress,我有一个LookUpEdit控件,封装了GridControl和DataPagerControl,从而实现了分页功能,如下所示: <Test:LookUpEditEx CustomFilterCommand="{Binding FilterData}" Margin="10" Width="250" ItemsSource="{Binding Locations}" TabIndex="2" NullText="{x:Static p

我有一个LookUpEdit控件,封装了GridControl和DataPagerControl,从而实现了分页功能,如下所示:

 <Test:LookUpEditEx CustomFilterCommand="{Binding FilterData}" Margin="10" Width="250" ItemsSource="{Binding Locations}" TabIndex="2"
                           NullText="{x:Static p:Resources.LblNone}" DisplayMember="LocationCode" SelectedItem="{Binding SelectedLocation}" AutoPopulateColumns="False"
                    HorizontalAlignment="Left" VerticalAlignment="Center" ValueMember="LocationId">
            <Test:LookUpEditEx.Buttons>
                <dxe:ButtonInfo ButtonKind="Simple" Content=" X " Command="{Binding Path=ClearLocation}" />
            </Test:LookUpEditEx.Buttons>
            <Test:LookUpEditEx.PopupContentTemplate>
                <ControlTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <dxg:GridControl Margin="5" Height="240" x:Name="PART_GridControl" Grid.Row="0">
                            <i:Interaction.Behaviors>
                                <Pager:CustomSortingBehavior CustomSortingCommand="{Binding SortLocations}" />
                            </i:Interaction.Behaviors>
                            <dxg:GridControl.View>
                                <dxg:TableView AllowColumnFiltering="False" IsColumnMenuEnabled="False" ShowGroupPanel="False" AutoWidth="True" />
                            </dxg:GridControl.View>
                            <dxg:GridControl.Columns>
                                <dxg:GridColumn FieldName="LocationCode" />
                                <dxg:GridColumn FieldName="ParentLocationCode" />
                            </dxg:GridControl.Columns>
                        </dxg:GridControl>
                        <dxe:DataPager x:Name="dataPager" AutoEllipsis="True" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Center"
                                             PageIndex="{Binding PageIndex, Mode=TwoWay}" Margin="5">
                            <i:Interaction.Behaviors>
                                <Pager:SourcesBehavior x:Name="LocationDataPagerSource" TotalSourcesCount="{Binding TotalLocationCount}"
                                                           Sources="{Binding Locations}" />
                            </i:Interaction.Behaviors>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="PageIndexChanging">
                                    <local_interaction:EventToCommandEx Command="{Binding LocationPageIndexChangeCommand}"
                                                             EventArgsConverter="{StaticResource PageIndexChangeConverter}"  PassEventArgsToCommand="True" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </dxe:DataPager>
                    </Grid>
                </ControlTemplate>
            </Test:LookUpEditEx.PopupContentTemplate>
        </Test:LookUpEditEx>
“FilteredLookupitstrategy”看起来像:

using DevExpress.Xpf.Grid.LookUp;
using System.Windows.Input;

namespace ABC
{
    public class FilteredLookUpEditStrategy : LookUpEditStrategy
    {
        private ICommand filterCommand = null;

        public FilteredLookUpEditStrategy(LookUpEdit editor, ICommand filterCommand)
            : base(editor)
        {
            this.filterCommand = filterCommand;
        }

        public override void AutoSeachTextChanged(string text)
        {
            this.filterCommand.Execute(string.Empty);
        }
    }
}
但是当我执行时,我将dependencProperty“CustomFilterCommand”设置为NULL。请让我知道如何着手解决这个问题,或者有更好的方法吗


谢谢

好吧,我的答案是,如果其他人也面临同样的问题。我们只需要通过继承LookUpEdit创建一个自定义控件,如下所示:

namespace ABC
{
    public class LookUpEditEx : LookUpEdit
    {
        public static readonly DependencyProperty CustomFilterCommandProperty =
        DependencyProperty.Register("CustomFilterCommand", typeof(ICommand), typeof(LookUpEditEx),
        new PropertyMetadata(null));

        public ICommand CustomFilterCommand
        {
            get
            {
                return (ICommand)GetValue(CustomFilterCommandProperty);
            }
            set
            {
                SetValue(CustomFilterCommandProperty, value);
            }
        }

        protected override void OnAutoSearchTextChanged(string displayText)
        {            
            if (CustomFilterCommand != null)
                CustomFilterCommand.Execute(displayText);
        }
    }
}
namespace ABC
{
    public class LookUpEditEx : LookUpEdit
    {
        public static readonly DependencyProperty CustomFilterCommandProperty =
        DependencyProperty.Register("CustomFilterCommand", typeof(ICommand), typeof(LookUpEditEx),
        new PropertyMetadata(null));

        public ICommand CustomFilterCommand
        {
            get
            {
                return (ICommand)GetValue(CustomFilterCommandProperty);
            }
            set
            {
                SetValue(CustomFilterCommandProperty, value);
            }
        }

        protected override void OnAutoSearchTextChanged(string displayText)
        {            
            if (CustomFilterCommand != null)
                CustomFilterCommand.Execute(displayText);
        }
    }
}