User avatar
Matso
Topic Author
Posts: 13
Joined: 19 Jul 2018, 11:52

Focused button mouse-over state issue

16 Jan 2019, 11:16

Can I disable a mouse-over state on a focused button?

MK
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Focused button mouse-over state issue

16 Jan 2019, 18:54

The appearance of a control is determined by its ControlTemplate (set in the Template property), so you can tweak the look all you want. Read more about it in Styles and Templates tutorial.

For example, our internal style defines a default template for the Button like this:
<ControlTemplate x:Key="MyButtonTemplate" TargetType="{x:Type Button}">
    <Border x:Name="Bg"
        Background="{TemplateBinding Background}"
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}"
        Padding="{TemplateBinding Padding}"
        CornerRadius="1">
        <ContentPresenter
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="BorderBrush" Value="{StaticResource OverBdBrush}"/>
            <Setter Property="Background" Value="{StaticResource OverBgBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource OverFgBrush}"/>
        </Trigger>
        <Trigger Property="IsPressed" Value="True">
            <Setter Property="BorderBrush" Value="{StaticResource PressBdBrush}"/>
            <Setter Property="Background" Value="{StaticResource PressBgBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource OverFgBrush}"/>
        </Trigger>
        <Trigger Property="IsKeyboardFocused" Value="True">
            <Setter Property="BorderBrush" Value="{StaticResource FocusBdBrush}"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="BorderBrush" Value="{StaticResource DisabledBdBrush}"/>
            <Setter Property="Background" Value="{StaticResource DisabledBgBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource DisabledFgBrush}"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
You can start from there and modify the setters for the IsKeyboardFocused trigger to adapt it to your needs.

Then you can use that template in any button like this:
<Button Template="{StaticResource MyButtonTemplate}" ... />
 
User avatar
Matso
Topic Author
Posts: 13
Joined: 19 Jul 2018, 11:52

Re: Focused button mouse-over state issue

17 Jan 2019, 09:48

Can I disable/enable states of a button with trigger setters? I mean I would like to disable MouseOver state of a button when it enters Focused state, and enable it back when it leaves the state.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Focused button mouse-over state issue

17 Jan 2019, 10:03

You can use MultiTrigger to change appearance of the Button when IsMouseOver=True but only if IsKeyboardFocused=False:
<MultiTrigger>
  <MultiTrigger.Conditions>
    <Condition Property="IsMouseOver" Value="True"/>
    <Condition Property="IsKeyboardFocused" Value="False"/>
  <MultiTrigger.Conditions>
  <!-- setters for MouseOver state -->
</MultiTrigger>
Is that what you are looking for?
 
User avatar
Matso
Topic Author
Posts: 13
Joined: 19 Jul 2018, 11:52

Re: Focused button mouse-over state issue

17 Jan 2019, 10:29

That is indeed helpful. Thanks!
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Focused button mouse-over state issue

17 Jan 2019, 15:16

Thanks for your feedback!

Who is online

Users browsing this forum: No registered users and 34 guests