0
我想在我的按鈕旁邊添加一些文本,但我想使用該文本的工具提示,或者更好,但可以在控件屬性中添加另一個標籤。ControlTemplate從按鈕綁定到ToolTip屬性
然後我想引用我的控件模板中此標記所以它會把我旁邊的按鈕上的文本,這裏是我的按鈕XAML:
<Button Style="{StaticResource MainMenuButton}" ToolTip="Home" Content="" />
這是我的風格:
<Style x:Key="MainMenuButton" TargetType="Button">
<Setter Property="FontFamily" Value="{StaticResource FontAwesome}" />
<Setter Property="FontSize" Value="27" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#545863" />
<Setter Property="Padding" Value="15" />
<Setter Property="Margin" Value="5" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" x:Name="border"
CornerRadius="40"
BorderThickness="0"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
Margin="{TemplateBinding Margin}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.FontWeight="Bold" />
</Border>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=DataContex.ToolTip}"
FontSize="16"/>
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#757b8d" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#29a1d5" />
</Trigger>
</Style.Triggers>
</Style>
我現在在那裏的代碼不起作用:{Binding RelativeSource={RelativeSource Self}, Path=DataContex.ToolTip}
。