2013-11-22 113 views
3

嗨,我有一个ToggleButtonToolTipToolTip的内容绑定与Text属性。现在我需要在ToggleButton内对我的ToolTip进行设计。我知道它不允许我在ToggleButton之内申请ToolTip的款式,我不知道该怎么做?任何建议,非常感谢。Wpf工具提示样式

这里是我的代码看起来

<ToggleButton x:Name="btn" ToolTip="{Binding ElementName=tbText, Path=Text, Mode=TwoWay}" Margin="10,0,0,20" Style="{StaticResource bubbleStyle}" />   

回答

5

如果我正确理解你的问题,你要内定义样式ToolTip你的ToggleButton

试试这个:

<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> 
+0

感谢ü@sthotakura,其做工精细 –

0

您必须声明的风格和你的控制所有的提示将在这种风格被显示。

<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> 
0

您可以设置内联样式或可以在Windows中使用Type创建资源。在Type中你必须分配ToggleButton。

Inline-

<ToggleButton > 
    <ToggleButton.ToolTip> 
    <ToolTip> 
     <StackPanel> 
      <TextBlock FontWeight="Bold">TEXT HERE</TextBlock> 
      <TextBlock>SECOND TEXT HERE.</TextBlock> 
     </StackPanel> 
    </ToolTip> 
</ToggleButton.ToolTip> 

在窗口资源(由@aDoubleSo的描述)

<Window.Resources> 
    <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip"> 
    <Setter Property="OverridesDefaultStyle" Value="true" /> 
    <Setter Property="HasDropShadow" Value="True" /> 
</Style> 
<Window.Resources>