Welcome to the Xceed Community | Help
Community Search  
More Search Options

AutoFilterControl doesn't seem to work with non-static binding

Sort Posts: Previous Next
  •  03-06-2009, 3:05 PM Post no. 19108

    AutoFilterControl doesn't seem to work with non-static binding

    I followed both the CustomFiltering sample and your online documentation (http://doc.xceedsoft.com/products/XceedWpfDataGrid/Xceed.Wpf.DataGrid~Xceed.Wpf.DataGrid.AutoFilterControl.html) and found out that the filter doen't seem to work with non-static binding.

    For instance, I took the CustomFiltering sample and added my own very simplified source code (please see attached files). I explain. First, I modified the MainWindow to point to my test page and then initialized the test page as followed:
    public TestPage() {
        this.InitializeComponent();
        DataContext =
    new TestPageDataContext();
    }

    The custom data object TestPageDataContext contains a public property Results which returns a list of custom type ResultInfo which holds two public properties: RuleID (int), RuleNumber (string).

    In XAML, I modified the DataGridCollectionViewSource's source as followed: Source="{Binding Results}". By default, it binds to the page's DataContext with Results as path. I configured the AutoFilterControl and DataGridCollectionViewSource to filter the column RuleNumber. 

    When I run the sample, the table gets generated and populated correctly, but not the combobox filter, it appears to be empty. If I add to my code-behind a static property Data as followed:
    private static TestPageDataContext _data = null;
    public static TestPageDataContext Data {
        get {
            if (null == _data) _data = new TestPageDataContext();
            return _data;
        }
        
    set { _data = value; }
    }


    And modify the DataGridCollectionViewSource's source to be instead: Source="{Binding Source={x:Static local:TestPage.Data}, Path=Results}", it then works perfectly with the filter combobox filled with data.

    My question, why is it working with static binding and not the other way?
  •  03-06-2009, 4:04 PM Post no. 19115 in reply to 19108

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Were there any errors in the output window? You should be able to bind to a non-static property.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-06-2009, 4:24 PM Post no. 19117 in reply to 19115

    Re: AutoFilterControl doesn't seem to work with non-static binding

    No errors at all. Have you try it?
  •  03-09-2009, 10:02 AM Post no. 19134 in reply to 19115

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Is there anyone that wants to try it and if it works for them, tell me how they did it?
  •  03-09-2009, 11:02 AM Post no. 19135 in reply to 19134

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Hi Pascal,

      What version of the DataGridControl are you using? When does the Results property initialized? I recreated a project using a data source configured as you described and using version 3.1.9117 of the DataGridControl, it works correctly. Here is the code of the window and the data source item:

     

    <Window x:Class="WPFApp.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
            Title="WPFApp">
        <Window.Resources>
            <xcdg:DataGridCollectionViewSource x:Key="cvs_Data"
                                             Source="{Binding Results}"
                                             AutoFilterMode="And"/>
        </Window.Resources>    

        <Grid MaxHeight="400">
            <xcdg:DataGridControl x:Name="testGrid"
                                   ItemsSource="{Binding Source={StaticResource cvs_Data}}"/>
        </Grid>
    </Window>

     

    public partial class Window1 : System.Windows.Window
    {
      public Window1()
      {
        InitializeComponent();
        this.DataContext = new TestPageDataContext();
     }
    }

    public class TestPageDataContext
    {
      public TestPageDataContext()
      {
        this.Results = new List<ResultInfo>();

        for( int i = 0; i < 100; i++ )
        {
          ResultInfo result = new ResultInfo();
          result.RuleID = i;
          result.RuleNumber = "Rule number " + i;

          this.Results.Add( result );
        }
      }

      public List<ResultInfo> Results
      {
        get;
        private set;
      }
    }

    public class ResultInfo
    {
      public int RuleID
      {
        get;
        set;
      }

      public string RuleNumber
      {
        get;
        set;
      }
    }

     


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  03-10-2009, 10:19 AM Post no. 19150 in reply to 19135

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Hi Christian,

    Thank you for trying. I am using Datagrid version 3.1.9069.1401. But I actually did the exact same thing as you and initialize the Resuts property in the TestPageDataContext constructor. And yes, the datagrid gets fill and display the data correctly, but what about the filter? Have you tried to configure a custom autofiltercontrol and see if it contains filter values. My problem is there.

    Here is how I configured it:

    <Page.Resources>
         <xcdg:DataGridCollectionViewSource x:Key="cvs_results"
                                             Source="{Binding Results}"
                                             AutoFilterMode="And"
                                             AutoCreateItemProperties="False"
                                             DefaultCalculateDistinctValues="False"
                                             DistinctValuesConstraint="Filtered">
             <xcdg:DataGridCollectionViewSource.ItemProperties>
                 <xcdg:DataGridItemProperty Name="RuleID"
                                           Title="Rule"
                                           CalculateDistinctValues="True">
                 </xcdg:DataGridItemProperty>
                 <xcdg:DataGridItemProperty Name="RuleNumber"
                                           Title="Number"
                                           CalculateDistinctValues="True">
                 </xcdg:DataGridItemProperty>
             </xcdg:DataGridCollectionViewSource.ItemProperties>
         </xcdg:DataGridCollectionViewSource>
     </Page.Resources>

    <xcdg:AutoFilterControl x:Name="ruleAutoFilterControl"
                            AutoFilterColumn="{Binding ElementName=grid, Path=Columns[RuleNumber]}"
                            AutoFilterContext="{Binding ElementName=grid, Path=(xcdg:DataGridControl.DataGridContext)}">
        <xcdg:AutoFilterControl.Template>
            <ControlTemplate TargetType="{x:Type xcdg:AutoFilterControl}">
                <ComboBox x:Name="PART_DistinctValuesHost"/>
            </ControlTemplate>
        </xcdg:AutoFilterControl.Template>
    </xcdg:AutoFilterControl>

     

    If in the contrary I do the following, it works perfectly:

    <xcdg:DataGridCollectionViewSource x:Key="cvs_results"
                                             Source="{Binding Source={x:Static local:TestPage.Data}, Path=Results}"
                                             AutoFilterMode="And"
                                             AutoCreateItemProperties="False"
                                             DefaultCalculateDistinctValues="False"
                                             DistinctValuesConstraint="Filtered">
             <xcdg:DataGridCollectionViewSource.ItemProperties>
                 <xcdg:DataGridItemProperty Name="RuleID"
                                           Title="Rule"
                                           CalculateDistinctValues="True">
                 </xcdg:DataGridItemProperty>
                 <xcdg:DataGridItemProperty Name="RuleNumber"
                                           Title="Number"
                                           CalculateDistinctValues="True">
                 </xcdg:DataGridItemProperty>
             </xcdg:DataGridCollectionViewSource.ItemProperties>
         </xcdg:DataGridCollectionViewSource>
     </Page.Resources>

     

    Code behind:

    private static TestPageDataContext _data = null;

    public static TestPageDataContext Data
    {
       get
       {
           if (null == _data) _data = new TestPageDataContext();
           return _data;
       }
       set { _data = value; }
    }

     

    So they only difference is the Collection view source binding. There must be something I don't see.

  •  03-10-2009, 1:22 PM Post no. 19168 in reply to 19150

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Hi,

     We received your code and verified using version 3.1.9069 and I was able to reproduce the behavior with this version of the DataGridControl. But using the latest, 3.1.9117, the same code works correctly. The DataGridCollectionView was refreshed lately in the original release therefore avoiding the creation of the DataGridControl.Columns before you bind the AutoFilterControl.AutoFilterColumn. 

    Since the AutoFilterColumn binding was not established initialy, the property changed is not correctly processed within the AutoFilterControl.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  03-10-2009, 1:51 PM Post no. 19172 in reply to 19168

    Re: AutoFilterControl doesn't seem to work with non-static binding

    Good news then. So finally it was a bug in that version. I should update to the new version and test it.

    Thank you. You have been very helpful.

     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.