Wpf ToolTip Style

我只是一个虾纸丫 提交于 2020-04-09 18:36:11

问题


Hi 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 dont know how to do it? Any suggestions are much appreciated.

Here is my code looks

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

回答1:


If I understand your question correctly, you want to define a style for ToolTip within your 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>



回答2:


You can set style inline or can create in windows resources with Type. in Type you have to assign 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)

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



回答3:


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>


来源:https://stackoverflow.com/questions/20138528/wpf-tooltip-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!