I want to define a style for the datagrid columns that get the text of the tooltip through an attached property. But I get the text System.Windows.Style
instead of the text.
The code is this. XML resource file that defines the style:
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="DataGridColumnHeaderConTooltip">
<Setter Property="ToolTip">
<Setter.Value>
<Style TargetType="ToolTip">
<Setter Property="ToolTipService.ShowOnDisabled" Value="true"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<!--Para poder utilizar el attached propery, se tiene que utilizar PlacementTarget, y además indicar que el source
es el control padre, que es el tooltip, porque el TextBlck no pertenece al mismo visual tree.-->
<TextBlock Text="{Binding PlacementTarget.(ap:CabeceraDatagridAttachedProperty.Tooltip), RelativeSource={RelativeSource AncestorType=ToolTip}}" MaxWidth="400" TextWrapping='Wrap' />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
The code in the xaml:
<DataGridTextColumn Header="Cantidad Para Descontar" Binding="{Binding CantidadParaDescontar, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Width="AUTO" IsReadOnly="false"
ap:CabeceraDatagridAttachedProperty.Tooltip="tooltip cabecera por attached property"
HeaderStyle="{StaticResource DataGridColumnHeaderConTooltip}">
The attached property:
namespace GTS.CMMS.Client.AttachedProperties
{
public static class CabeceraDatagridAttachedProperty
{
public static readonly DependencyProperty TooltipProperty =
DependencyProperty.RegisterAttached(
"Tooltip",
typeof(string),
typeof(CabeceraDatagridAttachedProperty));
public static string GetTooltip(DependencyObject obj)
{
return (string)obj.GetValue(TooltipProperty);
}
public static void SetTooltip(DependencyObject obj, string value)
{
obj.SetValue(TooltipProperty, value);
}
}
}