Custom Filtering datacontext problem

7 posts, 0 answers
  1. Samuel
    Samuel avatar
    13 posts
    Member since:
    Dec 2011

    Posted 10 Dec 2014 Link to this post

    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
  2. Samuel
    Samuel avatar
    13 posts
    Member since:
    Dec 2011

    Posted 12 Dec 2014 Link to this post

    Still waiting for some help on this....
  3. DevCraft banner
  4. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 13 Dec 2014 Link to this post

    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.

     
  5. Samuel
    Samuel avatar
    13 posts
    Member since:
    Dec 2011

    Posted 15 Dec 2014 in reply to Yoan Link to this post

    Thanks for the response.  However, this also did not work.
  6. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 16 Dec 2014 Link to this post

    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.

     
  7. Alex
    Alex avatar
    6 posts
    Member since:
    Jul 2015

    Posted 19 Jan in reply to Samuel Link to this post

    Hi. I am having similar issue. I am using 2015.1.225.45 version. Did you find any resolution on this problem?
  8. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 22 Jan Link to this post

    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
Back to Top
DevCraft banner