This is a migrated thread and some comments may be shown as answers.

GridViewDataColumn data binding for CustomFilteringControl NOT works

5 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
skrec
Top achievements
Rank 1
skrec asked on 14 Jan 2016, 03:55 PM

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?

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 18 Jan 2016, 11:24 AM
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
0
skrec
Top achievements
Rank 1
answered on 18 Jan 2016, 04:01 PM

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>

0
Dilyan Traykov
Telerik team
answered on 21 Jan 2016, 02:48 PM
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
0
skrec
Top achievements
Rank 1
answered on 26 Jan 2016, 11:41 AM

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.

0
Stefan
Telerik team
answered on 29 Jan 2016, 08:10 AM
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
Tags
GridView
Asked by
skrec
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
skrec
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or