Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Last active August 29, 2015 14:12
Show Gist options
  • Save Jalalx/c91b31c0282108849a5d to your computer and use it in GitHub Desktop.
Save Jalalx/c91b31c0282108849a5d to your computer and use it in GitHub Desktop.
MetroStyle ribbon for Microsoft WPF Ribbon Controls
ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Ribbon">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<!-- TODO Template
But how does this work? :/
-->
</Style>
</ResourceDictionary>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="RibbonGroup">
<Setter Property="Background" Value="Transparent" />
<Setter Property="MouseOverBackground" Value="Transparent"/>
<Setter Property="MouseOverBorderBrush" Value="Transparent"/>
</Style>
</ResourceDictionary>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFRibbon">
<BooleanToVisibilityConverter x:Key="VisiableConverter" />
<Style TargetType="RibbonTab">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RibbonTab">
<!-- This is allways rendering the tabs, so we have to hide them if they are not selected -->
<Grid Visibility="{TemplateBinding Property=IsSelected, Converter={StaticResource VisiableConverter}}">
<ItemsPresenter Margin="2" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="RibbonTabHeader">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Padding" Value="20,4,20,4" />
<Setter Property="BorderThickness" Value="1,1,1,0" />
<Setter Property="Margin" Value="1,0,1,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RibbonTabHeader">
<ControlTemplate.Resources>
<SolidColorBrush x:Key="CheckedBackground" Color="#FFF5F6F7" />
<SolidColorBrush x:Key="CheckedBorderBrush" Color="#FFDBDCDD" />
<SolidColorBrush x:Key="FocusedBackground" Color="#FFFDFDFF" />
<SolidColorBrush x:Key="FocusedBorderBrush" Color="#FFEDEEEE" />
<SolidColorBrush x:Key="MouseOverBackground" Color="#FFFDFDFF" />
<SolidColorBrush x:Key="MouseOverBorderBrush" Color="#FFEDEEEE" />
</ControlTemplate.Resources>
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center"
ContentSource="{Binding Label}" RecognizesAccessKey="True"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsRibbonTabSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource CheckedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource CheckedBorderBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsRibbonTabSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MouseOverBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource MouseOverBorderBrush}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment