I'm trying to use RibbonMenu but I'm having a lot of trouble changing the mouseOver background.
For the moment I've done something like this:
<Fluent:Ribbon
Grid.Row="0"
IsToolBarVisible="False"
Style="{DynamicResource RibbonStyle1}">
<Fluent:RibbonTabItem Header="File">
<Fluent:RibbonGroupBox Header="Strumenti">
<Fluent:Button
Width="90"
Header="Esporta"
Icon="/icons/icons_esporta_48x48.png"
LargeIcon="/icons/icons_esporta_48x48.png"
Style="{DynamicResource RibbonButtonStyle}" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
<Fluent:RibbonTabItem Header="Visualizza">
<Fluent:RibbonGroupBox Header="Industria">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Presse"
Icon="/icons/Pressa_3D_81px.png"
LargeIcon="/icons/Pressa_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Compattatori"
Icon="/icons/Compattatore_3D_81px.png"
LargeIcon="/icons/Compattatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Troncatori"
Icon="/icons/Troncatore_3D_81px.png"
LargeIcon="/icons/Troncatore_3D_81px.png" />
<Fluent:Button
Width="90"
Header="Centraline"
Icon="/icons/Centralina_3D_81px.png"
LargeIcon="/icons/Centralina_3D_81px.png" />
<Fluent:Button
Width="90"
Header="Nastri"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Impianti"
Icon="/icons/icons_impianto_50x50.png"
LargeIcon="/icons/icons_impianto_50x50.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Sfaldatori"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Macchine Varie"
Icon="/icons/icons_macchineVarie_64x64.png"
LargeIcon="/icons/icons_macchineVarie_64x64.png" />
</Fluent:RibbonGroupBox>
<Fluent:RibbonGroupBox Header="Informatica">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="IoT"
Icon="/icons/icons_iot_64x64.png"
LargeIcon="/icons/icons_iot_64x64.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Siti WEB"
Icon="/icons/icons_sitiWeb_50x50.png"
LargeIcon="/icons/icons_sitiWeb_50x50.png" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
<Fluent:RibbonTabItem Header="Inserisci">
<Fluent:RibbonGroupBox Header="Industria">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Pressa"
Icon="/icons/Pressa_3D_81px.png"
LargeIcon="/icons/Pressa_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Compattatore"
Icon="/icons/Compattatore_3D_81px.png"
LargeIcon="/icons/Compattatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Troncatore"
Icon="/icons/Troncatore_3D_81px.png"
LargeIcon="/icons/Troncatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Centralina"
Icon="/icons/Centralina_3D_81px.png"
LargeIcon="/icons/Centralina_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Nastro"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Impianto"
Icon="/icons/icons_impianto_50x50.png"
LargeIcon="/icons/icons_impianto_50x50.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Sfaldatore"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Macchina Varia"
Icon="/icons/icons_macchineVarie_64x64.png"
LargeIcon="/icons/icons_macchineVarie_64x64.png" />
</Fluent:RibbonGroupBox>
<Fluent:RibbonGroupBox Header="Informatica">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="IoT"
Icon="/icons/icons_iot_64x64.png"
LargeIcon="/icons/icons_iot_64x64.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Siti WEB"
Icon="/icons/icons_sitiWeb_50x50.png"
LargeIcon="/icons/icons_sitiWeb_50x50.png" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
</Fluent:Ribbon>
The resourceDictionary
is the following:
<ResourceDictionary
xmlns=";
xmlns:x=";
xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent">
<ControlTemplate x:Key="Fluent.Ribbon.Templates.FocusVisual.Empty" TargetType="{x:Type Control}">
<Rectangle Fill="#00000000" Stroke="Transparent" />
</ControlTemplate>
<Style x:Key="Fluent.Ribbon.Styles.FocusVisual.Empty" TargetType="{x:Type Control}">
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.FocusVisual.Empty}" />
</Style>
<ControlTemplate x:Key="Fluent.Ribbon.Templates.MenuSeparator" TargetType="{x:Type Separator}">
<Grid Height="Auto">
<Path
Height="1"
Margin="32,1,3,2"
VerticalAlignment="Center"
Data="F0 M 0,0 L 1,0 "
Fill="{x:Null}"
Stretch="Fill"
Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.Border}"
StrokeDashArray="2 2" />
</Grid>
</ControlTemplate>
<Style x:Key="Fluent.Ribbon.Styles.MenuSeparator" TargetType="{x:Type Separator}">
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.MenuSeparator}" />
</Style>
<ControlTemplate x:Key="Fluent.Ribbon.Templates.Ribbon" TargetType="{x:Type Fluent:Ribbon}">
<ControlTemplate.Resources>
<Style BasedOn="{StaticResource Fluent.Ribbon.Styles.MenuSeparator}" TargetType="{x:Type Separator}" />
</ControlTemplate.Resources>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="PART_LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Fluent:RibbonTabControl
x:Name="PART_RibbonTabControl"
AreTabHeadersVisible="{TemplateBinding AreTabHeadersVisible}"
ContentHeight="{TemplateBinding ContentHeight}"
ContextMenu="{Binding ContextMenu, ElementName=PART_LayoutRoot}"
IsDisplayOptionsButtonVisible="{TemplateBinding IsDisplayOptionsButtonVisible}"
IsMouseWheelScrollingEnabled="{TemplateBinding IsMouseWheelScrollingEnabled}"
IsMouseWheelScrollingEnabledEverywhere="{TemplateBinding IsMouseWheelScrollingEnabledEverywhere}"
IsToolBarVisible="{TemplateBinding IsToolBarVisible}"
Menu="{TemplateBinding Menu}" />
<ContentControl
x:Name="quickAccessToolBarHolder"
Grid.Row="1"
Height="{TemplateBinding QuickAccessToolBarHeight}"
HorizontalAlignment="Left">
<Fluent:QuickAccessToolBar
x:Name="PART_QuickAccessToolBar"
HorizontalAlignment="Left"
Focusable="False"
IsMenuDropDownVisible="{TemplateBinding IsQuickAccessToolBarMenuDropDownVisible}"
ShowAboveRibbon="{Binding ShowQuickAccessToolBarAboveRibbon, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</ContentControl>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsQuickAccessToolBarVisible" Value="False">
<Setter TargetName="PART_QuickAccessToolBar" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsBackstageOrStartScreenOpen" Value="True">
<Setter TargetName="PART_QuickAccessToolBar" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsCollapsed" Value="True">
<Setter TargetName="PART_RibbonTabControl" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="QuickAccessToolBar" Value="{x:Null}">
<Setter TargetName="quickAccessToolBarHolder" Property="Content" Value="{x:Null}" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="ShowQuickAccessToolBarAboveRibbon" Value="True">
<Setter TargetName="quickAccessToolBarHolder" Property="Content" Value="{x:Null}" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsSimplified" Value="True">
<Setter TargetName="PART_RibbonTabControl" Property="ContentHeight" Value="42" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="RibbonStyle1" TargetType="{x:Type Fluent:Ribbon}">
<Setter Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Ribbon.Background}" />
<Setter Property="Fluent:FrameworkHelper.UseLayoutRounding" Value="True" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Fluent.Ribbon.Styles.FocusVisual.Empty}" />
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.LabelText}" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="QuickAccessToolBarHeight" Value="{Binding TitleBar.ActualHeight, FallbackValue=23, RelativeSource={RelativeSource AncestorType={x:Type Fluent:IRibbonWindow}, Mode=FindAncestor}}" />
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.Ribbon}" />
<Setter Property="TitleBar" Value="{Binding TitleBar, FallbackValue={x:Null}, RelativeSource={RelativeSource AncestorType={x:Type Fluent:IRibbonWindow}, Mode=FindAncestor}}" />
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
<Style x:Key="RibbonButtonStyle" TargetType="{x:Type Fluent:Button}">
<Setter Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Background}" />
<Setter Property="BorderBrush" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Border}" />
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.LabelText}" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Fluent.Ribbon.Styles.FocusVisual.Empty}" />
<Setter Property="Width" Value="90" />
<Setter Property="Padding" Value="5" />
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.Button}" />
<Style.Triggers>
<!-- Cambia il colore di sfondo e bordo quando il mouse è sopra il bottone -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGray" />
<Setter Property="BorderBrush" Value="White" />
</Trigger>
<!-- Cambia quando il bottone è premuto -->
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="LightGray" />
<Setter Property="BorderBrush" Value="DarkGray" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
I only have to change the background and foreground of the button (Fluent:Button
) with the mouse pass. Another good thing is to change the background when pressed.
Another question: is there a possibility to keep the button "selected" once I pressed it? Maybe changing the color or something similar? What am I doing wrong?
Thank you
I'm trying to use RibbonMenu but I'm having a lot of trouble changing the mouseOver background.
For the moment I've done something like this:
<Fluent:Ribbon
Grid.Row="0"
IsToolBarVisible="False"
Style="{DynamicResource RibbonStyle1}">
<Fluent:RibbonTabItem Header="File">
<Fluent:RibbonGroupBox Header="Strumenti">
<Fluent:Button
Width="90"
Header="Esporta"
Icon="/icons/icons_esporta_48x48.png"
LargeIcon="/icons/icons_esporta_48x48.png"
Style="{DynamicResource RibbonButtonStyle}" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
<Fluent:RibbonTabItem Header="Visualizza">
<Fluent:RibbonGroupBox Header="Industria">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Presse"
Icon="/icons/Pressa_3D_81px.png"
LargeIcon="/icons/Pressa_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Compattatori"
Icon="/icons/Compattatore_3D_81px.png"
LargeIcon="/icons/Compattatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Troncatori"
Icon="/icons/Troncatore_3D_81px.png"
LargeIcon="/icons/Troncatore_3D_81px.png" />
<Fluent:Button
Width="90"
Header="Centraline"
Icon="/icons/Centralina_3D_81px.png"
LargeIcon="/icons/Centralina_3D_81px.png" />
<Fluent:Button
Width="90"
Header="Nastri"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Impianti"
Icon="/icons/icons_impianto_50x50.png"
LargeIcon="/icons/icons_impianto_50x50.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Sfaldatori"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Macchine Varie"
Icon="/icons/icons_macchineVarie_64x64.png"
LargeIcon="/icons/icons_macchineVarie_64x64.png" />
</Fluent:RibbonGroupBox>
<Fluent:RibbonGroupBox Header="Informatica">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="IoT"
Icon="/icons/icons_iot_64x64.png"
LargeIcon="/icons/icons_iot_64x64.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Siti WEB"
Icon="/icons/icons_sitiWeb_50x50.png"
LargeIcon="/icons/icons_sitiWeb_50x50.png" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
<Fluent:RibbonTabItem Header="Inserisci">
<Fluent:RibbonGroupBox Header="Industria">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Pressa"
Icon="/icons/Pressa_3D_81px.png"
LargeIcon="/icons/Pressa_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Compattatore"
Icon="/icons/Compattatore_3D_81px.png"
LargeIcon="/icons/Compattatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Troncatore"
Icon="/icons/Troncatore_3D_81px.png"
LargeIcon="/icons/Troncatore_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Centralina"
Icon="/icons/Centralina_3D_81px.png"
LargeIcon="/icons/Centralina_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Nastro"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Impianto"
Icon="/icons/icons_impianto_50x50.png"
LargeIcon="/icons/icons_impianto_50x50.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Sfaldatore"
Icon="/icons/Nastro_3D_81px.png"
LargeIcon="/icons/Nastro_3D_81px.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Macchina Varia"
Icon="/icons/icons_macchineVarie_64x64.png"
LargeIcon="/icons/icons_macchineVarie_64x64.png" />
</Fluent:RibbonGroupBox>
<Fluent:RibbonGroupBox Header="Informatica">
<Fluent:Button
Width="90"
Cursor="Hand"
Header="IoT"
Icon="/icons/icons_iot_64x64.png"
LargeIcon="/icons/icons_iot_64x64.png" />
<Fluent:Button
Width="90"
Cursor="Hand"
Header="Siti WEB"
Icon="/icons/icons_sitiWeb_50x50.png"
LargeIcon="/icons/icons_sitiWeb_50x50.png" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
</Fluent:Ribbon>
The resourceDictionary
is the following:
<ResourceDictionary
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent">
<ControlTemplate x:Key="Fluent.Ribbon.Templates.FocusVisual.Empty" TargetType="{x:Type Control}">
<Rectangle Fill="#00000000" Stroke="Transparent" />
</ControlTemplate>
<Style x:Key="Fluent.Ribbon.Styles.FocusVisual.Empty" TargetType="{x:Type Control}">
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.FocusVisual.Empty}" />
</Style>
<ControlTemplate x:Key="Fluent.Ribbon.Templates.MenuSeparator" TargetType="{x:Type Separator}">
<Grid Height="Auto">
<Path
Height="1"
Margin="32,1,3,2"
VerticalAlignment="Center"
Data="F0 M 0,0 L 1,0 "
Fill="{x:Null}"
Stretch="Fill"
Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.Border}"
StrokeDashArray="2 2" />
</Grid>
</ControlTemplate>
<Style x:Key="Fluent.Ribbon.Styles.MenuSeparator" TargetType="{x:Type Separator}">
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.MenuSeparator}" />
</Style>
<ControlTemplate x:Key="Fluent.Ribbon.Templates.Ribbon" TargetType="{x:Type Fluent:Ribbon}">
<ControlTemplate.Resources>
<Style BasedOn="{StaticResource Fluent.Ribbon.Styles.MenuSeparator}" TargetType="{x:Type Separator}" />
</ControlTemplate.Resources>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="PART_LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Fluent:RibbonTabControl
x:Name="PART_RibbonTabControl"
AreTabHeadersVisible="{TemplateBinding AreTabHeadersVisible}"
ContentHeight="{TemplateBinding ContentHeight}"
ContextMenu="{Binding ContextMenu, ElementName=PART_LayoutRoot}"
IsDisplayOptionsButtonVisible="{TemplateBinding IsDisplayOptionsButtonVisible}"
IsMouseWheelScrollingEnabled="{TemplateBinding IsMouseWheelScrollingEnabled}"
IsMouseWheelScrollingEnabledEverywhere="{TemplateBinding IsMouseWheelScrollingEnabledEverywhere}"
IsToolBarVisible="{TemplateBinding IsToolBarVisible}"
Menu="{TemplateBinding Menu}" />
<ContentControl
x:Name="quickAccessToolBarHolder"
Grid.Row="1"
Height="{TemplateBinding QuickAccessToolBarHeight}"
HorizontalAlignment="Left">
<Fluent:QuickAccessToolBar
x:Name="PART_QuickAccessToolBar"
HorizontalAlignment="Left"
Focusable="False"
IsMenuDropDownVisible="{TemplateBinding IsQuickAccessToolBarMenuDropDownVisible}"
ShowAboveRibbon="{Binding ShowQuickAccessToolBarAboveRibbon, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</ContentControl>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsQuickAccessToolBarVisible" Value="False">
<Setter TargetName="PART_QuickAccessToolBar" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsBackstageOrStartScreenOpen" Value="True">
<Setter TargetName="PART_QuickAccessToolBar" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsCollapsed" Value="True">
<Setter TargetName="PART_RibbonTabControl" Property="Visibility" Value="Collapsed" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="QuickAccessToolBar" Value="{x:Null}">
<Setter TargetName="quickAccessToolBarHolder" Property="Content" Value="{x:Null}" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="ShowQuickAccessToolBarAboveRibbon" Value="True">
<Setter TargetName="quickAccessToolBarHolder" Property="Content" Value="{x:Null}" />
<Setter TargetName="quickAccessToolBarHolder" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsSimplified" Value="True">
<Setter TargetName="PART_RibbonTabControl" Property="ContentHeight" Value="42" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="RibbonStyle1" TargetType="{x:Type Fluent:Ribbon}">
<Setter Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Ribbon.Background}" />
<Setter Property="Fluent:FrameworkHelper.UseLayoutRounding" Value="True" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Fluent.Ribbon.Styles.FocusVisual.Empty}" />
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.LabelText}" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="QuickAccessToolBarHeight" Value="{Binding TitleBar.ActualHeight, FallbackValue=23, RelativeSource={RelativeSource AncestorType={x:Type Fluent:IRibbonWindow}, Mode=FindAncestor}}" />
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.Ribbon}" />
<Setter Property="TitleBar" Value="{Binding TitleBar, FallbackValue={x:Null}, RelativeSource={RelativeSource AncestorType={x:Type Fluent:IRibbonWindow}, Mode=FindAncestor}}" />
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
<Style x:Key="RibbonButtonStyle" TargetType="{x:Type Fluent:Button}">
<Setter Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Background}" />
<Setter Property="BorderBrush" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Border}" />
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.LabelText}" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Fluent.Ribbon.Styles.FocusVisual.Empty}" />
<Setter Property="Width" Value="90" />
<Setter Property="Padding" Value="5" />
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.Button}" />
<Style.Triggers>
<!-- Cambia il colore di sfondo e bordo quando il mouse è sopra il bottone -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGray" />
<Setter Property="BorderBrush" Value="White" />
</Trigger>
<!-- Cambia quando il bottone è premuto -->
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="LightGray" />
<Setter Property="BorderBrush" Value="DarkGray" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
I only have to change the background and foreground of the button (Fluent:Button
) with the mouse pass. Another good thing is to change the background when pressed.
Another question: is there a possibility to keep the button "selected" once I pressed it? Maybe changing the color or something similar? What am I doing wrong?
Thank you
Share Improve this question edited Mar 12 at 9:16 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 12 at 9:13 user27828246user27828246 91 silver badge3 bronze badges 01 Answer
Reset to default 0If you want to handle specific states (IsPressed
AND IsMouseOver
, etc) you can use MultiTrigger
s. The order you define the triggers also matters since the ones declared first can be overridden by the ones below them.
In the example below, the Background
will be DarkSlateGray
while the button is being pressed AND the mouse is over.
As for the selected part, you should be able to just use a Trigger
on IsFocused
to handle the "selected" state, controls will remain focused after being clicked.
<Style x:Key="RibbonButtonStyle" TargetType="{x:Type Fluent:Button}">
<Setter Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Background}" />
<Setter Property="BorderBrush" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Normal.Border}" />
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.LabelText}" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Fluent.Ribbon.Styles.FocusVisual.Empty}" />
<Setter Property="Width" Value="90" />
<Setter Property="Padding" Value="5" />
<Setter Property="Template" Value="{DynamicResource Fluent.Ribbon.Templates.Button}" />
<Style.Triggers>
<!-- Hover -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGray" />
<Setter Property="BorderBrush" Value="White" />
</Trigger>
<!-- Pressed -->
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="LightGray" />
<Setter Property="BorderBrush" Value="DarkGray" />
</Trigger>
<!-- Hover + Pressed -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsPressed" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="DarkSlateGray" />
</MultiTrigger>
</Style.Triggers>
</Style>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744762665a4592265.html
评论列表(0条)