GridViewDataColumn data binding for CustomFilteringControl NOT works

6 posts, 0 answers
  1. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 14 Jan Link to this post

    Hi,

    I have defined custom filtering control like this. It's a custom control.

    public class SalusGridViewCustomFilteringControl : FilteringControl
        {
            private GridViewDataControl _parentGrid;
            private GridViewBoundColumnBase _parentColumn;
            private readonly List<FilterDescriptor> _filterDescriptors = new List<FilterDescriptor>();
     
            static SalusGridViewCustomFilteringControl()
            {
                DefaultStyleKeyProperty.OverrideMetadata(typeof(SalusGridViewCustomFilteringControl), new FrameworkPropertyMetadata(typeof(SalusGridViewCustomFilteringControl)));
            }
     
    ...
     
    public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register(
                "Items", typeof (ObservableCollection<AgendaActivityType>), typeof (SalusGridViewCustomFilteringControl), new PropertyMetadata(default(ObservableCollection<AgendaActivityType>)));
     
            public ObservableCollection<AgendaActivityType> Items
            {
                get { return (ObservableCollection<AgendaActivityType>) GetValue(ItemsProperty); }
                set { SetValue(ItemsProperty, value); }
            }
     
    ...

     But when I use it as filtering control for column like this:

     

    <telerik:GridViewDataColumn.FilteringControl>
                                           <controls:SalusGridViewCustomFilteringControl Items="{Binding AgendaItemTypes}" ItemContainerStyle="{StaticResource AgendaFilteringItemStyle}"/>
                                       </telerik:GridViewDataColumn.FilteringControl>

     Binding to AgendaItemTypes not works. Ok it is because telerik FilteringControl class, which is base class for my custom filtering control, sets DataContext to FilteringViewModel. FilteringViewModel does not contains property AgendaItemTypes.

    But when I change binding of Items property to element which has right datacontext i.e. like this:

    <telerik:GridViewDataColumn.FilteringControl>
                                            <controls:SalusGridViewCustomFilteringControl Items="{Binding ElementName=AgendaModule_AgendaPlannedActivityView_GridView, Path=DataContext.AgendaItemTypes}" ItemContainerStyle="{StaticResource AgendaFilteringItemStyle}"/>
                                        </telerik:GridViewDataColumn.FilteringControl>

     Binding still not work. Can someone give me advice please?

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 18 Jan Link to this post

    Hello Petr,

    I've attached a sample project to show you how to achieve the desired behaviour.
    Can you please have a look at it and let me know if it works for you?

    Regards,
    Dilyan Traykov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 18 Jan in reply to Dilyan Traykov Link to this post

    Hi, thans for reply.

    Attached example work, but it is not answer to my question?

    I have asked for not working binding, for filtering control created as custom control, when binding is applied in control usage.

    <controls:SalusGridViewCustomFilteringControl

        Items="{Binding AgendaItemTypes}" ItemContainerStyle="{StaticResource AgendaFilteringItemStyle}"/>
    </telerik:GridViewDataColumn.FilteringControl>

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 21 Jan Link to this post

    Hello,

    I have modified the project to better suit your requirements and attached it to my reply. Could you please have a look at it and let me know if this approach works for you.

    I would like to ask whether there is any particular reason why you'd prefer this approach over setting the ItemsSource directly in the ListBox of the filtering control as I've done in my previous reply?

    Regards,
    Dilyan Traykov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 26 Jan in reply to Dilyan Traykov Link to this post

    Hello,

    I have checked attached project created by you and thanks for that.

    But I did not want to bind to static resource. As I mentioned above I want use filtering control like this.

    1.<telerik:GridViewDataColumn.FilteringControl>
    2.  <controls:SalusGridViewCustomFilteringControl Items="{Binding AgendaItemTypes}" ItemContainerStyle="{StaticResource AgendaFilteringItemStyle}"/>
    3.</telerik:GridViewDataColumn.FilteringControl>

     And WHY I prefer this approach? Because I want to create custom filtering control without hardcoded items source.

    For example: I have defined custom filtering control which contains items control and I want to set datasource of items control from outside - most like from view model via wpf databinding. MVVM approach.

  7. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 29 Jan Link to this post

    Hello,

    I'm afraid there's no way to achieve that, as you need to set the DataContext of the control which is null by default. However, setting the Source of the Binding does not violate the MVVM pattern in any manner and you can bind the items of the FilteringControl to the view model through it.

    All the best,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready