如何使用UXDataFilter控件进行各种数据过滤操作

作者:控件中国网   出处:控件中国网   2016-07-11 14:36:00   阅读:4

UXDataFilter控件是Intersoft ClientUI界面套包产品下的一款子控件产品,可以与其他数据处理类控件一起绑定使用进行各种数据过滤操作,UXDataFilter同时支持客户端和服务器端数据操作,当设置 QueryOperation属性为Client时进行客户端数据处理,开发人员通过设置不同的过滤表达式对数据进行各种过滤操作,下面的代码讲述了如何利用 UXListBox控件和UXDataFilter控件进行数据过滤操作,具体如下:
datafilter[1].jpg
C#代码:
using System.Collections;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using HowToSamples.Web;
using Intersoft.Client.Data.ComponentModel;
 
namespace HowToSamples.ViewModels
{
    public class FilteringUXListBoxViewModel : ViewModelBase
    {
        public FilteringUXListBoxViewModel()
        {
            this.Manager = new NorthwindDomainContext();
            this.LoadCustomers();
        }
 
        private IEnumerable _customers;
 
        private NorthwindDomainContext Manager { get; set; }
 
        public IEnumerable Customers
        {
            get { return this._customers; }
            set
            {
                if (this._customers != value)
                {
                    this._customers = value;
                    this.OnPropertyChanged("Customers");
                }
            }
        }
 
        public virtual void LoadCustomers()
        {
            if (Intersoft.Client.Framework.ISControl.IsInDesignModeStatic)
                return;
 
            var query = this.Manager.GetCustomersQuery().OrderBy(c => c.ContactName);
 
            this.Manager.Load(
               query,
               op =>
               {
                   if (op.IsComplete)
                   {
                       this.Customers = new PagedCollectionView(op.Entities);
                   }
                   else
                   {
                       MessageBox.Show(op.Error.ToString());
                   }
               },
 
               true);
        }
    }
}
XAML代码:
<UserControl x:Class="HowToSamples.FilteringUXListBox"
    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:Intersoft="http://intersoft.clientui.com/schemas"
    xmlns:ViewModels="clr-namespace:HowToSamples.ViewModels"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot">
        <Grid.DataContext>
            <ViewModels:FilteringUXListBoxViewModel/>
        </Grid.DataContext>
 
        <Intersoft:DockPanel FillChildMode="Custom" MaxWidth="700" Margin="12">
 
            <Intersoft:UXDataFilter CollectionView="{Binding Customers}"
                                    Header="By Alphabet" Margin="8,0" Width="120" VerticalAlignment="Center">
                <Intersoft:UXDataFilterItem Content="A - E">
                    <Intersoft:UXDataFilterItem.Filter>
                        <Intersoft:CompositeFilterDescription LogicalOperator="Or">
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="A"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="B"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="C"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="D"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="E"/>
                        </Intersoft:CompositeFilterDescription>
                    </Intersoft:UXDataFilterItem.Filter>
                </Intersoft:UXDataFilterItem>
                <Intersoft:UXDataFilterItem Content="F - J">
                    <Intersoft:UXDataFilterItem.Filter>
                        <Intersoft:CompositeFilterDescription LogicalOperator="Or">
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="F"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="G"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="H"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="I"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="J"/>
                        </Intersoft:CompositeFilterDescription>
                    </Intersoft:UXDataFilterItem.Filter>
                </Intersoft:UXDataFilterItem>
                <Intersoft:UXDataFilterItem Content="K - O">
                    <Intersoft:UXDataFilterItem.Filter>
                        <Intersoft:CompositeFilterDescription LogicalOperator="Or">
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="K"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="L"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="M"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="N"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="O"/>
                        </Intersoft:CompositeFilterDescription>
                    </Intersoft:UXDataFilterItem.Filter>
                </Intersoft:UXDataFilterItem>
                <Intersoft:UXDataFilterItem Content="P - T">
                    <Intersoft:UXDataFilterItem.Filter>
                        <Intersoft:CompositeFilterDescription LogicalOperator="Or">
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="P"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="Q"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="R"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="S"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="T"/>
                        </Intersoft:CompositeFilterDescription>
                    </Intersoft:UXDataFilterItem.Filter>
                </Intersoft:UXDataFilterItem>
                <Intersoft:UXDataFilterItem Content="U - Z">
                    <Intersoft:UXDataFilterItem.Filter>
                        <Intersoft:CompositeFilterDescription LogicalOperator="Or">
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="U"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="V"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="W"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="X"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="Y"/>
                            <Intersoft:FilterDescription PropertyName="ContactName" Operator="StartsWith"  Value="Z"/>
                        </Intersoft:CompositeFilterDescription>
                    </Intersoft:UXDataFilterItem.Filter>
                </Intersoft:UXDataFilterItem>
            </Intersoft:UXDataFilter>
 
            <Intersoft:UXListBox ItemsSource="{Binding Customers}" Margin="8"
                                 Intersoft:DockPanel.IsFillElement="True">
                <Intersoft:UXListBox.ItemContainerStyle>
                    <Style TargetType="Intersoft:UXListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    </Style>
                </Intersoft:UXListBox.ItemContainerStyle>
                <Intersoft:UXListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="128">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Image HorizontalAlignment="Left" VerticalAlignment="Center" Source="{Binding Path=PhotoPath}" Margin="8,8,8,8"/>
                            <Grid Grid.Column="1" Margin="16,8,16,8">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock HorizontalAlignment="Left" FontSize="16" FontWeight="Normal" Text="{Binding Path=ContactName}" TextWrapping="NoWrap"/>
                                <StackPanel Grid.Row="1" Orientation="Horizontal">
                                    <TextBlock Foreground="#FF7D7D7D" Text="{Binding Path=ContactTitle}" TextWrapping="NoWrap"/>
                                    <TextBlock Foreground="#FF7D7D7D" Text=", "/>
                                    <TextBlock Foreground="#FF7D7D7D" Text="{Binding Path=CompanyName}" TextWrapping="NoWrap"/>
                                </StackPanel>
                                <Border Grid.Row="3" Grid.RowSpan="2" Background="#7FF0F0F0" CornerRadius="4"
                                        HorizontalAlignment="Right" VerticalAlignment="Bottom">
                                    <StackPanel Margin="4">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Phone : " TextWrapping="NoWrap"/>
                                            <TextBlock Text="{Binding Path=Phone}" TextWrapping="NoWrap"/>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Fax : " TextWrapping="NoWrap"/>
                                            <TextBlock Text="{Binding Path=Fax}" TextWrapping="NoWrap"/>
                                        </StackPanel>
                                    </StackPanel>
                                </Border>
                            </Grid>
                            <Intersoft:UXSeparator VerticalAlignment="Bottom" Grid.ColumnSpan="2" Margin="0,0,0,-4" Opacity="0.4"/>
                        </Grid>
                    </DataTemplate>
                </Intersoft:UXListBox.ItemTemplate>
            </Intersoft:UXListBox>
        </Intersoft:DockPanel>
    </Grid>
</UserControl>
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat