Skip to main content

Microsoft Silverlight

Answered Question FilterDescriptor returns nullRSS Feed

(0)

vitorcastelo
vitorcas...

Member

Member

0 points

5 Posts

FilterDescriptor returns null

Hi all,

I have a ComboBox with three options that defines which operator should be used with a FilterDescriptor. That FilterDescriptor is linked to a DatePicker. I'm trying to do that in code-behind, but with any luck so far. 

In my XAML file I have the following code:

<riaControls:DomainDataSource x:Name="dds" AutoLoad="True" QueryName="Query" LoadSize="20">

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

                               <riaData:FilterDescriptor x:Name="filter1" PropertyPath="Date" >
                                    <riaData:ControlParameter ControlName="dtpDate" RefreshEventName="SelectedDateChanged" />
                                </riaData:FilterDescriptor>

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

</riaControls:DomainDataSource>

<!-- Filter: dates -->
<TextBlock Text="Date: " />
<ComboBox x:Name="cmbDate" DropDownClosed="cmbDate_DropDownClosed">
   <ComboBox.Items>
      <ComboBoxItem Content="All dates" IsSelected="True"/>
      <ComboBoxItem Content="Equal to"/>
      <ComboBoxItem Content="Since"/>
      <ComboBoxItem Content="Until"/>
   </ComboBox.Items>
</ComboBox>
<controls:DatePicker Name="dtpDate" />

I am trying to set the Operator for the filter1 FilterDescriptor on the DropDownClosed Event as follows:

            int idx = cmbDate.SelectedIndex;

            if (idx == 1) // Equal to option
                filter1.Operator = FilterOperator.IsEqualTo;
           
            if (idx == 2) // Since option
                filter1.Operator = FilterOperator.IsGreaterThanOrEqualTo;

            if (idx == 3) // Until option
                filter1.Operator = FilterOperator.IsLessThanOrEqualTo;

The lines above are short versions, but I think they illustrate what I'm trying to do.

filter1 results NULL whatever I do. I've tried other approaches but with no success. Can anyone help me with this? I don't even know if this is the best way to do what I want. I'm open to suggestions. Smile

Thanks in advance.

Ardman
Ardman

Contributor

Contributor

3344 points

926 Posts

Re: FilterDescriptor returns null

 Have you tried to refresh your DomainDataSource after you've set the Filter Descriptor?

vitorcastelo
vitorcas...

Member

Member

0 points

5 Posts

Re: FilterDescriptor returns null

Hello Ardman, can you explain better what you mean. I'm sorry but I'm pretty new to this Silverlight and RIA services world... :)

Ardman
Ardman

Contributor

Contributor

3344 points

926 Posts

Re: Re: FilterDescriptor returns null

Certainly, when you change the Filter operator, clear the data from the DomainDataSource and then call the Load method to refresh the data.

vitorcastelo
vitorcas...

Member

Member

0 points

5 Posts

Re: Re: Re: FilterDescriptor returns null

Ok! :) I did it, but it results the same. I thought that when we referenced filter1 it would be recognized as the filter1 from the XAML file and all we had to do was changing its OPERATOR property, but it isn't recognized as being that object. When filter1.Operator line is executed returns 'Object reference not set to an instance of an object'...

Ardman
Ardman

Contributor

Contributor

3344 points

926 Posts

Re: Re: Re: Re: FilterDescriptor returns null

I'm not sure if this will work, but if you wanted to get the Filter from the DomainDataSource, you could try:

FilterDescriptor filterDesc = this.FindName("filter1") asFilterDescriptor;

filterDesc.Operator = FilterOperator.IsLessThanOrEqualTo;

But, I'm not sure this will work.

vitorcastelo
vitorcas...

Member

Member

0 points

5 Posts

Re: Re: Re: Re: Re: FilterDescriptor returns null

It didn't work. :( Thanks anyway Ardman. :) I am still trying to discover how to do this. If you have any other ideas I'll be much appreciated. :) Cheers

Ardman
Ardman

Contributor

Contributor

3344 points

926 Posts

Re: Re: Re: Re: Re: Re: FilterDescriptor returns null

If you remove the Filter Descpritor from the XAML and set it in the code only, does this work?

vitorcastelo
vitorcas...

Member

Member

0 points

5 Posts

Answered Question

Re: Re: Re: Re: Re: Re: FilterDescriptor returns null

Hi again! Problem solved! I created a FilterDescriptionCollection object which has all the filter descriptors in my DomainDataSource. All I did was to look inside that collection for a filter descriptor with the appropriate PropertyPath. This is the complete routine: FilterDescriptorCollection fdCol = ddsDataSource.FilterDescriptors; FilterDescriptor fdDate = null; foreach (FilterDescriptor fd in fdCol) { if (fd.PropertyPath == "Date") fdDate = fd; } int idx = cmbDate.SelectedIndex; if (idx == 1) // equal to fdDate.Operator = FilterOperator.IsEqualTo; if (idx == 2) // since fdDate.Operator = FilterOperator.IsGreaterThanOrEqualTo; if (idx == 3) // until fdDate.Operator = FilterOperator.IsLessThanOrEqualTo; this worked just fine. Thanks for your help anyway! :)

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities