I am using MVVM and would like to move the event handling out of the view. I am trying to handle the PageIndexChanged event of the RadDataPager by using a custom binding. The handler sets the ItemsSource of a RadGridView and the ItemCount of the pager (i.e. I am doing the paging myself). To set it up I use a style:
<Window.Resources>
<Style TargetType="{x:Type telerik:RadDataPager}"
x:Key="indexChangedStyle">
<Setter Property="local:PageIndexChangedBehavior.SetPageIndexChanged"
Value="True" />
</Style>
</Window.Resources>
<telerik:RadDataPager x:Name="dataPager"
Grid.Row="1"
DisplayMode="All"
PageSize="10"
Style="{StaticResource indexChangedStyle}">
In the custom behavior I do this:
public static readonly DependencyProperty SetPageIndexChangedProperty =
DependencyProperty.RegisterAttached(
"SetPageIndexChanged",
typeof(bool),
typeof(PageIndexChangedBehavior),
new UIPropertyMetadata(true, OnSetPageIndexChanged));
private static void OnSetPageIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
RadDataPager pager = obj as RadDataPager;
if (pager == null)
return;
if (e.NewValue is bool == false)
return;
if ((bool)e.NewValue)
pager.PageIndexChanged += pager_PageIndexChanged;
else
pager.PageIndexChanged -= pager_PageIndexChanged;
}
OnSetPageIndexChanged() never gets called. Will this methodology work? Is there a better way?
Thanks.
Andrea