Wpf 工具提示样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20138528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wpf ToolTip Style
提问by raijan_cv
I have one ToggleButton
with ToolTip
, content of ToolTip
is bind with Text
property. Now I need to style my ToolTip
within ToggleButton
. I know its not allow me apply style within ToggleButton
for ToolTip
and I don't know how to do it.
我有一个ToggleButton
with ToolTip
,内容ToolTip
是与Text
属性绑定的。现在我需要设计我的ToolTip
内在ToggleButton
. 我知道它不允许我在ToggleButton
for 中应用样式ToolTip
,我不知道该怎么做。
Here is what my code looks like:
这是我的代码的样子:
<ToggleButton
x:Name="btn"
Margin="10,0,0,20"
Style="{StaticResource bubbleStyle}"
ToolTip="{Binding ElementName=tbText, Path=Text, Mode=TwoWay}" />
回答by sthotakura
If I understand your question correctly, you want to define a style for ToolTip
within your ToggleButton
.
如果我正确理解你的问题,你想ToolTip
在你的ToggleButton
.
Try this:
尝试这个:
<ToggleButton Content="ON" Grid.Row="1" ToolTip="{Binding ElementName=tbText, Path=Text}">
<ToggleButton.Resources>
<Style TargetType="ToolTip" BasedOn="{StaticResource {x:Type ToolTip}}">
<Setter Property="Background" Value="Red" />
</Style>
</ToggleButton.Resources>
</ToggleButton>
回答by J R B
You can set style inline or can create in windows resources with Type. in Type you have to assign ToggleButton .
您可以设置内联样式,也可以使用类型在 Windows 资源中创建。在 Type 中,您必须分配 ToggleButton 。
Inline-
排队-
<ToggleButton >
<ToggleButton.ToolTip>
<ToolTip>
<StackPanel>
<TextBlock FontWeight="Bold">TEXT HERE</TextBlock>
<TextBlock>SECOND TEXT HERE.</TextBlock>
</StackPanel>
</ToolTip>
</ToggleButton.ToolTip>
In Window Resource (as describe by @aDoubleSo)
在窗口资源中(如@aDoubleSo 所述)
<Window.Resources>
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="HasDropShadow" Value="True" />
</Style>
<Window.Resources>
回答by aDoubleSo
You have to declare the style and all tooltips of your control will be shown in this style.
您必须声明样式,并且控件的所有工具提示都将以这种样式显示。
<Window.Resources>
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="HasDropShadow" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<!-- define your control template -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Window.Resources>