Skip to content

Commit

Permalink
Fixes #954
Browse files Browse the repository at this point in the history
Added support for ToggleButtons in WindowCommands and also modified WindowCommands code for supporting all ButtonBase controls.
  • Loading branch information
AzureKitsune committed Feb 19, 2014
1 parent 6eb3fb0 commit 4ba6b5e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
5 changes: 3 additions & 2 deletions MahApps.Metro/Controls/MetroWindowHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace MahApps.Metro.Controls
Expand Down Expand Up @@ -87,9 +88,9 @@ private static void ChangeWindowCommandButtonsBrush(this MetroWindow window, Bru
window.InvokeCommandButtons(x => x.SetValue(Control.ForegroundProperty, brush));
}

private static void InvokeCommandButtons(this MetroWindow window, Action<Button> action)
private static void InvokeCommandButtons(this MetroWindow window, Action<ButtonBase> action)
{
foreach (Button b in ((WindowCommands)window.WindowCommandsPresenter.Content).FindChildren<Button>())
foreach (ButtonBase b in ((WindowCommands)window.WindowCommandsPresenter.Content).FindChildren<ButtonBase>())
{
action(b);
}
Expand Down
48 changes: 48 additions & 0 deletions MahApps.Metro/Themes/MetroWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,54 @@
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ToggleButton}">
<!--Modified version of spiritdead's code-->
<Setter Property="Background" Value="{DynamicResource TransparentWhiteBrush}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter x:Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
RecognizesAccessKey="True"
Opacity=".5"
Margin="11,1,11,1" />
<Rectangle x:Name="border"
SnapsToDevicePixels="True"
IsHitTestVisible="False"
Opacity=".2"
Width="1"
Height="15"
VerticalAlignment="Stretch"
HorizontalAlignment="Right"
Fill="{TemplateBinding Foreground}"
Margin="10,0,0,0" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="contentPresenter" Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="contentPresenter" Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD" />
</Trigger>
<DataTrigger Binding="{Binding ShowTitleBar, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
Value="True">
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</ControlTemplate.Resources>

Expand Down
1 change: 1 addition & 0 deletions samples/MetroDemo/CleanWindowDemo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Controls:WindowCommands>
<Button Content="Test"/>
<Button Content="Another Test"/>
<ToggleButton Content="ToggleButton Test"/>
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>
<Controls:MetroWindow.Flyouts>
Expand Down
1 change: 1 addition & 0 deletions samples/MetroDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<!--<Button Click="LaunchRibbonDemo" Content="Ribbon Demo (.NET 4.5)" />-->
<Button Click="InteropDemo" Content="Interop Demo" />
<Button Click="LaunchNavigationDemo" Content="Navigation Demo"/>
<ToggleButton Content="ToggleButton"/>
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>

Expand Down

0 comments on commit 4ba6b5e

Please sign in to comment.