Question

I have the following style, but when the mouse over trigger is true, no underline shows up on the text.

<Style x:Key="HyperlinkToggleButtonStyle" TargetType="ToggleButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <TextBlock x:Name="TextBlock">
                            <ContentPresenter Content="{TemplateBinding  Content}" ContentTemplate="{TemplateBinding  ContentTemplate}"/>
                </TextBlock>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="false">
            <Setter Property="Background" Value="{StaticResource StandardBackground}"/>
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontStyle" Value="Normal"/>
            <Setter Property="FontWeight" Value="Normal"/>                                         
        </Trigger>

        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" Value="{StaticResource StandardBackground}"/>
            <Setter Property="Foreground" Value="{StaticResource StandardBlue}" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontStyle" Value="Normal"/>
            <Setter Property="FontWeight" Value="Normal"/>
            <Setter Property="TextBlock.TextDecorations" Value="Underline"/>
        </Trigger>
    </Style.Triggers>
</Style>
Was it helpful?

Solution

This might not be an ideal solution, but you could define the trigger in your control template. Don't forget to reference your TextBlock with the TargetName property on the setter.

    <Setter Property="Template">
        <Setter.Value>
           <ControlTemplate TargetType="ToggleButton">
              <TextBlock x:Name="TextBlock">
                        <ContentPresenter Content="{TemplateBinding  Content}" ContentTemplate="{TemplateBinding  ContentTemplate}"/>
              </TextBlock>
              <ControlTemplate.Triggers>
                 <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="TextBlock" Property="TextBlock.TextDecorations" Value="Underline"/>
                 </Trigger>
              </ControlTemplate.Triggers>
           </ControlTemplate>
        </Setter.Value>
     </Setter>

OTHER TIPS

The TextDecorations property is not inherited so setting the value on the Button (which is what your trigger is targeting), will not accomplish what you want. You can probably use a StoryBoard to do that, but I can't remember if a storyboard can target an element defined in a template (only way to find out is to do it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top