Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom mode to ColorZone #1611

Merged
merged 8 commits into from
Jan 31, 2020
Prev Previous commit
Next Next commit
Move the Custom Background and Foreground from the ColorZone to the C…
…olorZone assist class and remvoe Custom from their names

Add Custom GroupBox to the demo app and edit the Custom ColorZone Demo to reflect the new changes
  • Loading branch information
ahmed-abdelrazek committed Jan 24, 2020
commit 509f0436deec29bf4f20d347aaae97ce5c91de28
2 changes: 1 addition & 1 deletion MainDemo.Wpf/ColorZones.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use custom back and fore colours.</TextBlock>
<smtx:XamlDisplay Key="color_zones_custom">
<materialDesign:ColorZone Mode="Custom" CustomBackground="Black" CustomForeground="White" Padding="16">
<materialDesign:ColorZone Mode="Custom" Background="Black" Foreground="White" Padding="16">
<StackPanel Orientation="Horizontal">
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
<TextBlock VerticalAlignment="Center" Margin="16 0 0 0">Material Design In XAML Toolkit</TextBlock>
Expand Down
6 changes: 6 additions & 0 deletions MainDemo.Wpf/GroupBoxes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<Image Source="Resources/Contact.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</GroupBox>
</smtx:XamlDisplay>

<smtx:XamlDisplay Key="groupbox_6" Grid.Column="2" Grid.Row="1">
<GroupBox Header="Custom Header" Style="{DynamicResource MaterialDesignGroupBox}" Margin="16" materialDesign:ColorZoneAssist.Mode="Custom" materialDesign:ColorZoneAssist.Background="Black" materialDesign:ColorZoneAssist.Foreground="White">
<TextBlock>My Content</TextBlock>
</GroupBox>
</smtx:XamlDisplay>
</Grid>
</UserControl>

Expand Down
19 changes: 0 additions & 19 deletions MaterialDesignThemes.Wpf/ColorZone.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf
{
Expand Down Expand Up @@ -44,23 +43,5 @@ public CornerRadius CornerRadius
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}

public static readonly DependencyProperty CustomBackgroundProperty = DependencyProperty.Register(
nameof(CustomBackground), typeof(Brush), typeof(ColorZone), new PropertyMetadata(default(Brush)));

public Brush CustomBackground
{
get { return (Brush)GetValue(CustomBackgroundProperty); }
set { SetValue(CustomBackgroundProperty, value); }
}

public static readonly DependencyProperty CustomForegroundProperty = DependencyProperty.Register(
nameof(CustomForeground), typeof(Brush), typeof(ColorZone), new PropertyMetadata(default(Brush)));

public Brush CustomForeground
{
get { return (Brush)GetValue(CustomForegroundProperty); }
set { SetValue(CustomForegroundProperty, value); }
}
}
}
27 changes: 27 additions & 0 deletions MaterialDesignThemes.Wpf/ColorZoneAssist.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf
{
Expand All @@ -16,5 +17,31 @@ public static ColorZoneMode GetMode(DependencyObject element)
{
return (ColorZoneMode)element.GetValue(ModeProperty);
}

public static readonly DependencyProperty BackgroundProperty = DependencyProperty.RegisterAttached(
"Background", typeof(Brush), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.Inherits));

public static void SetBackground(DependencyObject element, Brush value)
{
element.SetValue(BackgroundProperty, value);
}

public static Brush GetBackground(DependencyObject element)
{
return (Brush)element.GetValue(BackgroundProperty);
}

public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached(
"Foreground", typeof(Brush), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.Inherits));

public static void SetForeground(DependencyObject element, Brush value)
{
element.SetValue(ForegroundProperty, value);
}

public static Brush GetForeground(DependencyObject element)
{
return (Brush)element.GetValue(ForegroundProperty);
}
}
}
4 changes: 2 additions & 2 deletions MaterialDesignThemes.Wpf/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignDarkForeground}" />
</Trigger>
<Trigger Property="Mode" Value="Custom">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=CustomBackground}" />
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=CustomForeground}" />
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:ColorZoneAssist.Background)}" />
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:ColorZoneAssist.Foreground)}" />
</Trigger>
</Style.Triggers>
</Style>
Expand Down