开发者

Filtering in Silverlight with RIA Services

I have a small SL application that uses RIA services to display employee data (Northwind database) in a data grid. I have a text filter, that works fine against varchar columns but does not filter against a nullable int column. Here is the xaml:

<UserControl xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Ria" 
         xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Controls.Ria"  
         xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="FilteringSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:web="clr-namespace:FilteringSample.Web"
xmlns:converter="clr-namespace:FilteringSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<UserControl.Resources>
    <converter:StringToIntConverter x:Key="MyConverter"></converter:StringToIntConverter>
</UserControl.Resources>
    <Grid x:Name="LayoutRoot">
<StackPanel Orientation="Vertical" Height="Auto" Grid.Column="0">
        <StackPanel Orientation="Horizontal">
            <Button x:Name="saveButton" Width="75" Height="30" Content="Save" Margin="5" Click="saveButton_Click"/>
            <Button x:Name="rejectButton" Width="75" Height="30" Content="Reject" Margin="5" Click="rejectButton_Click"/>
            <TextBlock x:Name="changeText" VerticalAlignment="Center" Width="Auto"/>
            <TextBox x:Name="Filter" Width="100" Text="" />
            <riaControls:DomainDataSource x:Name="DataSource1" QueryName="GetEmployeesQuery" LoadingData="DataSource1_LoadingData"   >
                <riaControls:DomainDataSource.DomainContext>
                    <!--<web:CustomerContext></web:CustomerContext>-->
                    <web:EmployeeContext></web:EmployeeContext>
                </riaControls:DomainDataSource.DomainContext>

                <riaControls:DomainDataSource.FilterDescriptors>
                    <riaData:FilterDescriptorCollection LogicalOperator="Or">                                                
                        <riaData:FilterDescriptor PropertyPath="FirstName" Operator="Contains">
                            <riaControls:ControlParameter ControlName="Filter" PropertyName="Text" RefreshEventName="TextChanged" />
                        </riaData:FilterDescriptor>
                        <riaData:FilterDescriptor PropertyPath="Title" Operator="开发者_运维百科Contains">
                            <riaControls:ControlParameter ControlName="Filter" PropertyName="Text" RefreshEventName="TextChanged" />
                        </riaData:FilterDescriptor>
                        <riaData:FilterDescriptor PropertyPath="TestFilter" Operator="Contains">
                            <riaControls:ControlParameter ControlName="Filter" PropertyName="Text" RefreshEventName="TextChanged"/>
                        </riaData:FilterDescriptor>

                    </riaData:FilterDescriptorCollection>
                </riaControls:DomainDataSource.FilterDescriptors>
            </riaControls:DomainDataSource>

        </StackPanel>
        <data:DataGrid Name="MyGrid" ItemsSource="{Binding Data, ElementName=DataSource1}">
        </data:DataGrid>
        <!--<data:DataPager PageSize="20" Source="{Binding Data, ElementName=DataSource1}" Margin="0,-1,0,0" />--> 
    </StackPanel>

Any help will be appreciated. Thanks


I think that you need a ValueConverter that converts the text of the TestFilter to int before it is passed to LINQ.


You should be able to mix and match types in the filters without any problems. You also don't need a value converter to convert from string to an int, the FilterDescriptor will parse the value automatically.

The XAML you are showing doesn't show any int fields though. What operator are you trying to use for the filter? It would have to be a numeric operator like IsEqualTo, IsGreaterThan, etc.

What is the result? Does it load with no data, fail to load, or ignore the filter?

You might want to try handling the LoadingData event and looking at the EntityQuery exposed on the event args to see what was composed for the query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜