Hello Telerik Team,
I want to add a button on a gridview column header. For that I wrote a custom control that inherits from GridViewDataColumn. The custom control sets the GridViewHeaderCellStyle and implements a command.
Here the style:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:controls="clr-namespace:MyControls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office2016;component/Themes/Telerik.Windows.Controls.GridView.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="telerik:GridViewHeaderCell" BasedOn="{StaticResource GridViewHeaderCellStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<TextBlock Text="myText"/>
<telerik:RadButton Content="myButton" Command="{Binding TestCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=controls:hGridViewDataColumn}}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
And the custom control:
namespace MyControls
{
public class hGridViewDataColumn : GridViewDataColumn
{
static hGridViewDataColumn()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(hGridViewDataColumn), new FrameworkPropertyMetadata(typeof(hGridViewDataColumn)));
}
public hGridViewDataColumn()
{
HeaderCellStyle = FindResource("hGridViewHeaderCellStyle") as Style;
}
private ICommand _testCommand;
public ICommand TestCommand
{
get
{
return ...;
}
}
}
}
Unfortunately the binding doesn't work. What's wrong?