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

Custom Filtering datacontext problem

6 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Samuel
Top achievements
Rank 1
Samuel asked on 10 Dec 2014, 04:58 PM
I am using SL5 and MVVM pattern.  I have created a custom user control, StringFilterControl, which implements the IFilteringControl for use in the RadGridView filters.  However, my user control requires access to my View Model for some data.  I created a dependency property in the StringFilterControl so I could bind this property to a property on my View Model.  However, I cannot seem to get the data context correct.  Defining the element name in the XAML binding doesn't find LayoutRoot.  I also tried using the RelativeSource binding option but it fails and it appears that the parent of the filter popup is null.

Please tell me there is a way to get the datacontext of my view model from within the filtering control...

Sam.

Partial Public Class StringFilterControl
        Inherits UserControl
        Implements IFilteringControl
 
        Private memberName As String
 
        Public Sub New()
            InitializeComponent()
        End Sub
 
 
#Region " IsActive Property "
 
        Public Shared ReadOnly IsActiveProperty = DependencyProperty.Register("IsActive",
                                                                              GetType(Boolean),
                                                                              GetType(StringFilterControl),
                                                                              New System.Windows.PropertyMetadata(False))
 
        Public Property IsActive As Boolean Implements IFilteringControl.IsActive
            Get
                Return CBool(GetValue(IsActiveProperty))
            End Get
            Set(value As Boolean)
                SetValue(IsActiveProperty, value)
            End Set
        End Property
 
#End Region
 
#Region " Options Property "
 
        Public Shared ReadOnly OptionsProperty = DependencyProperty.Register("Options",
                                                                              GetType(IEnumerable(Of String)),
                                                                              GetType(StringFilterControl),
                                                                              New PropertyMetadata(Nothing))
 
        Public Property Options As IEnumerable(Of String)
            Get
                Return GetValue(OptionsProperty)
            End Get
            Set(value As IEnumerable(Of String))
                SetValue(OptionsProperty, value)
            End Set
        End Property
 
#End Region
 
 
...
 
End Class



<
telerik:RadGridView x:Name="GridView1"
                                 Grid.Row="1"
                                 AlternateRowBackground="AliceBlue"
                                 AlternationCount="2"
                                 AutoGenerateColumns="False"
                                 BorderBrush="Gray"
                                 BorderThickness="1"
                                 ItemsSource="{Binding Plans}"
                                 RowIndicatorVisibility="Collapsed"
                                 SelectedItem="{Binding SelectedItem,
                                                        Mode=TwoWay}"
                                 ShowGroupPanel="False"
                                 Sorting="OnGridSorting">
                <telerik:RadGridView.SortDescriptors>
                    <telerik:SortDescriptor Member="QAPlanName" SortDirection="Ascending" />
                </telerik:RadGridView.SortDescriptors>
 
                <telerik:RadGridView.Columns>
                 
 
                    <telerik:GridViewDataColumn x:Name="QAPlanName"
                                                Width="*"
                                                DataMemberBinding="{Binding QAPlanName}"
                                                FilterMemberPath="QAPlanName"
                                                Header="Plan Name"
                                                IsReadOnly="True"
                                                IsSortable="True"
                                                ShowDistinctFilters="False"
                                                ShowFieldFilters="True"
                                                SortMemberPath="QAPlanName">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <HyperlinkButton Width="Auto"
                                                 HorizontalAlignment="Left"
                                                 VerticalAlignment="Center"
                                                 Click="OnPlanClick"
                                                 Content="{Binding QAPlanName}"
                                                 Tag="{Binding QAPlanID}" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                        <telerik:GridViewDataColumn.FilteringControl>
                            <local:StringFilterControl Options="{Binding StringOptions, ElementName=LayoutRoot}" />
                        </telerik:GridViewDataColumn.FilteringControl>
                    </telerik:GridViewDataColumn>
 
</telerik:RadGridView

6 Answers, 1 is accepted

Sort by
0
Samuel
Top achievements
Rank 1
answered on 12 Dec 2014, 04:25 PM
Still waiting for some help on this....
0
Yoan
Telerik team
answered on 13 Dec 2014, 03:22 PM
Hello Samuel,

You can try to expose your ViewModel as a resource and use it a Source of the binding:
<telerik:GridViewDataColumn.FilteringControl>
                            <local:StringFilterControl Options="{Binding StringOptions, Source={StaticResource MyViewModel}}" />
                        </telerik:GridViewDataColumn.FilteringControl>

Please let me know how this works for you.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Samuel
Top achievements
Rank 1
answered on 15 Dec 2014, 01:14 PM
Thanks for the response.  However, this also did not work.
0
Yoan
Telerik team
answered on 16 Dec 2014, 04:10 PM
Hi,

Could you try isolating the problem in a sample project and send it to us? We will debug it on our side and will assist you further. You can check this blog post which demonstrates how to isolate a problem in a sample project. Please note that you need to open a new support ticket in order to attach the sample project.

I'm looking forward to hearing from you.


Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alex
Top achievements
Rank 1
answered on 19 Jan 2016, 06:50 PM
Hi. I am having similar issue. I am using 2015.1.225.45 version. Did you find any resolution on this problem?
0
Stefan
Telerik team
answered on 22 Jan 2016, 11:49 AM
Hi Alex,

Generally, setting explicitly the Source of the Binding to be the view model should be working as expected. Would it be possible for you to demonstrate your project setup in a sample application, and send it over as an attachment in a new support thread? You can check out the blog post referred in the previous answer of my colleague for more information on isolating a problem in a demo project.

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
Samuel
Top achievements
Rank 1
Answers by
Samuel
Top achievements
Rank 1
Yoan
Telerik team
Alex
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or