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.
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