In UWP I am trying to change default template of tooltip.
I have managed it, but now I need to set tooltip arrow to point out to the control it belongs to.
My style is defined as this:
<Style TargetType="ToolTip">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeHighBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ToolTipBorderThemeThickness}" />
<Setter Property="FontFamily" Value="Roboto" />
<Setter Property="FontSize" Value="{ThemeResource ToolTipContentThemeFontSize}" />
<Setter Property="Padding" Value="40,40,40,35"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid Background="Transparent">
<Grid
MinWidth="100"
MinHeight="90"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}"
Padding="15"
Background="Transparent">
And so on and on...
But now I am trying to make UserControl bind with TemplateBinding property.
I have created UserControl that have some dependecncy property. Like this:
public PlacementMode TooltipPlacement
{
get { return (PlacementMode)GetValue(TooltipPlacementProperty); }
set { SetValue(TooltipPlacementProperty, value); CalculateArrowVisibility(); }
}
public static readonly DependencyProperty TooltipPlacementProperty =
DependencyProperty.Register("TooltipPlacement", typeof(PlacementMode), typeof(ArrowDown), null);
CalculateArrowVisibility() is a method that will calculate the arrow location depending on TooltipPlacement.
And that control is in style defined as this:
<local:ArrowDown x:Name="arrow" TooltipPlacement="{TemplateBinding Placement}"/>
But it is not bound, I have tried other TemplateProperties but no luck also.
Where is the problem here?
You are very close excpet the way you delcare the dependency property is wrong.
You should never modify its getter and setter. Instead, call your CalculateArrowVisibility
method inside its property changed callback like this -
public PlacementMode TooltipPlacement
{
get => (PlacementMode)GetValue(TooltipPlacementProperty);
set => SetValue(TooltipPlacementProperty, value);
}
public static readonly DependencyProperty TooltipPlacementProperty =
DependencyProperty.Register("TooltipPlacement", typeof(PlacementMode), typeof(ArrowDown),
new PropertyMetadata(null, TooltipPlacementChangedCallback));
private static void TooltipPlacementChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (ArrowDown)d;
self.CalculateArrowVisibility();
}