Last active
March 26, 2018 15:34
-
-
Save punker76/7d554d1e02eb17e1646a5f8fe79058d7 to your computer and use it in GitHub Desktop.
Custom WindowCommands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<controls:MetroWindow.Resources> | |
<ControlTemplate x:Key="WindowCommandsButtonTemplate" TargetType="{x:Type Button}"> | |
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}"> | |
<controls:ContentControlEx x:Name="PART_ContentControlEx" | |
Padding="{TemplateBinding Padding}" | |
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" | |
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" | |
Content="{TemplateBinding Content}" | |
ContentCharacterCasing="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:WindowCommands}}, Path=(controls:ControlsHelper.ContentCharacterCasing)}" | |
ContentStringFormat="{TemplateBinding ContentStringFormat}" | |
ContentTemplate="{TemplateBinding ContentTemplate}" | |
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" | |
RecognizesAccessKey="True" | |
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsMouseOver" Value="True"> | |
<Setter TargetName="RootGrid" Property="Background" Value="{DynamicResource AccentBaseColorBrush}" /> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
<ControlTemplate x:Key="WindowCommandsToggleButtonTemplate" TargetType="{x:Type ToggleButton}"> | |
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}"> | |
<controls:ContentControlEx x:Name="PART_ContentControlEx" | |
Padding="{TemplateBinding Padding}" | |
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" | |
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" | |
Content="{TemplateBinding Content}" | |
ContentCharacterCasing="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:WindowCommands}}, Path=(controls:ControlsHelper.ContentCharacterCasing)}" | |
ContentStringFormat="{TemplateBinding ContentStringFormat}" | |
ContentTemplate="{TemplateBinding ContentTemplate}" | |
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" | |
RecognizesAccessKey="True" | |
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsChecked" Value="True"> | |
<Setter TargetName="PART_ContentControlEx" Property="FontStyle" Value="Italic" /> | |
</Trigger> | |
<Trigger Property="IsMouseOver" Value="True"> | |
<Setter TargetName="RootGrid" Property="Background" Value="{DynamicResource AccentBaseColorBrush}" /> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
<Style x:Key="WindowCommandsControlStyle" TargetType="{x:Type Control}"> | |
<Setter Property="Background" Value="{DynamicResource TransparentWhiteBrush}" /> | |
<Setter Property="Foreground" Value="{Binding Foreground, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type controls:WindowCommands}}}" /> | |
<Setter Property="HorizontalContentAlignment" Value="Center" /> | |
<Setter Property="Padding" Value="8 0 8 0" /> | |
<Setter Property="VerticalContentAlignment" Value="Center" /> | |
<Style.Triggers> | |
<Trigger Property="IsEnabled" Value="False"> | |
<Setter Property="Foreground" Value="{DynamicResource GrayBrush4}" /> | |
</Trigger> | |
</Style.Triggers> | |
</Style> | |
<ControlTemplate x:Key="LightWindowCommandsTemplate" TargetType="controls:WindowCommands"> | |
<ItemsPresenter /> | |
<ControlTemplate.Resources> | |
<ResourceDictionary> | |
<Style BasedOn="{StaticResource WindowCommandsControlStyle}" TargetType="{x:Type Button}"> | |
<Setter Property="Template" Value="{StaticResource WindowCommandsButtonTemplate}" /> | |
</Style> | |
<Style BasedOn="{StaticResource WindowCommandsControlStyle}" TargetType="{x:Type ToggleButton}"> | |
<Setter Property="Template" Value="{StaticResource WindowCommandsToggleButtonTemplate}" /> | |
</Style> | |
</ResourceDictionary> | |
</ControlTemplate.Resources> | |
</ControlTemplate> | |
</controls:MetroWindow.Resources> | |
<controls:MetroWindow.RightWindowCommands> | |
<controls:WindowCommands Template="{StaticResource LightWindowCommandsTemplate}"> | |
<Button Content="Test" /> | |
<ToggleButton Content="Toggle" /> | |
</controls:WindowCommands> | |
</controls:MetroWindow.RightWindowCommands> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment