Skip to content

Commit a84360c

Browse files
committed
(GH-3477) Fix for: Removing black border from button
1 parent 9c98005 commit a84360c

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

src/MahApps.Metro/Controls/Helper/ControlsHelper.cs

+61-9
Original file line numberDiff line numberDiff line change
@@ -150,39 +150,76 @@ public static void SetHeaderMargin(UIElement element, Thickness value)
150150
element.SetValue(HeaderMarginProperty, value);
151151
}
152152

153-
public static readonly DependencyProperty FocusBorderBrushProperty = DependencyProperty.RegisterAttached("FocusBorderBrush", typeof(Brush), typeof(ControlsHelper), new FrameworkPropertyMetadata(Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
154-
public static readonly DependencyProperty MouseOverBorderBrushProperty = DependencyProperty.RegisterAttached("MouseOverBorderBrush", typeof(Brush), typeof(ControlsHelper), new FrameworkPropertyMetadata(Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
153+
public static readonly DependencyProperty FocusBorderBrushProperty
154+
= DependencyProperty.RegisterAttached("FocusBorderBrush",
155+
typeof(Brush),
156+
typeof(ControlsHelper),
157+
new FrameworkPropertyMetadata(Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
158+
159+
/// <summary>
160+
/// Gets the brush used to draw the focus border.
161+
/// </summary>
162+
[Category(AppName.MahApps)]
163+
[AttachedPropertyBrowsableForType(typeof(TextBox))]
164+
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
165+
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
166+
[AttachedPropertyBrowsableForType(typeof(ButtonBase))]
167+
public static Brush GetFocusBorderBrush(DependencyObject obj)
168+
{
169+
return (Brush)obj.GetValue(FocusBorderBrushProperty);
170+
}
155171

156172
/// <summary>
157173
/// Sets the brush used to draw the focus border.
158174
/// </summary>
175+
[Category(AppName.MahApps)]
176+
[AttachedPropertyBrowsableForType(typeof(TextBox))]
177+
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
178+
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
179+
[AttachedPropertyBrowsableForType(typeof(ButtonBase))]
159180
public static void SetFocusBorderBrush(DependencyObject obj, Brush value)
160181
{
161182
obj.SetValue(FocusBorderBrushProperty, value);
162183
}
163184

185+
public static readonly DependencyProperty FocusBorderThicknessProperty
186+
= DependencyProperty.RegisterAttached("FocusBorderThickness",
187+
typeof(Thickness),
188+
typeof(ControlsHelper),
189+
new FrameworkPropertyMetadata(default(Thickness), FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
190+
164191
/// <summary>
165192
/// Gets the brush used to draw the focus border.
166193
/// </summary>
167194
[Category(AppName.MahApps)]
168195
[AttachedPropertyBrowsableForType(typeof(TextBox))]
169-
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
170-
[AttachedPropertyBrowsableForType(typeof(RadioButton))]
171196
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
172197
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
173-
public static Brush GetFocusBorderBrush(DependencyObject obj)
198+
[AttachedPropertyBrowsableForType(typeof(ButtonBase))]
199+
public static Thickness GetFocusBorderThickness(DependencyObject obj)
174200
{
175-
return (Brush)obj.GetValue(FocusBorderBrushProperty);
201+
return (Thickness)obj.GetValue(FocusBorderThicknessProperty);
176202
}
177203

178204
/// <summary>
179-
/// Sets the brush used to draw the mouse over brush.
205+
/// Sets the brush used to draw the focus border.
180206
/// </summary>
181-
public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value)
207+
[Category(AppName.MahApps)]
208+
[AttachedPropertyBrowsableForType(typeof(TextBox))]
209+
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
210+
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
211+
[AttachedPropertyBrowsableForType(typeof(ButtonBase))]
212+
public static void SetFocusBorderThickness(DependencyObject obj, Thickness value)
182213
{
183-
obj.SetValue(MouseOverBorderBrushProperty, value);
214+
obj.SetValue(FocusBorderThicknessProperty, value);
184215
}
185216

217+
public static readonly DependencyProperty MouseOverBorderBrushProperty
218+
= DependencyProperty.RegisterAttached("MouseOverBorderBrush",
219+
typeof(Brush),
220+
typeof(ControlsHelper),
221+
new FrameworkPropertyMetadata(Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
222+
186223
/// <summary>
187224
/// Gets the brush used to draw the mouse over brush.
188225
/// </summary>
@@ -198,6 +235,21 @@ public static Brush GetMouseOverBorderBrush(DependencyObject obj)
198235
return (Brush)obj.GetValue(MouseOverBorderBrushProperty);
199236
}
200237

238+
/// <summary>
239+
/// Sets the brush used to draw the mouse over brush.
240+
/// </summary>
241+
[Category(AppName.MahApps)]
242+
[AttachedPropertyBrowsableForType(typeof(TextBox))]
243+
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
244+
[AttachedPropertyBrowsableForType(typeof(RadioButton))]
245+
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
246+
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
247+
[AttachedPropertyBrowsableForType(typeof(Tile))]
248+
public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value)
249+
{
250+
obj.SetValue(MouseOverBorderBrushProperty, value);
251+
}
252+
201253
/// <summary>
202254
/// DependencyProperty for <see cref="CornerRadius" /> property.
203255
/// </summary>

src/MahApps.Metro/Styles/Controls.Buttons.xaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@
390390
<Setter Property="BorderThickness" Value="1" />
391391
<Setter Property="Controls:ControlsHelper.ContentCharacterCasing" Value="Upper" />
392392
<Setter Property="Controls:ControlsHelper.CornerRadius" Value="3" />
393+
<Setter Property="Controls:ControlsHelper.FocusBorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" />
394+
<Setter Property="Controls:ControlsHelper.FocusBorderThickness" Value="2" />
393395
<Setter Property="FontFamily" Value="{DynamicResource DefaultFont}" />
394396
<Setter Property="FontSize" Value="{DynamicResource UpperCaseContentFontSize}" />
395397
<Setter Property="FontWeight" Value="Bold" />
@@ -434,8 +436,8 @@
434436
<Setter TargetName="Border" Property="Background" Value="{DynamicResource GrayBrush7}" />
435437
</Trigger>
436438
<Trigger Property="IsKeyboardFocusWithin" Value="True">
437-
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" />
438-
<Setter TargetName="Border" Property="BorderThickness" Value="2" />
439+
<Setter TargetName="Border" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush), Mode=OneWay}" />
440+
<Setter TargetName="Border" Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderThickness), Mode=OneWay}" />
439441
</Trigger>
440442
<Trigger Property="IsEnabled" Value="False">
441443
<Setter TargetName="DisabledVisualElement" Property="Opacity" Value="0.7" />
@@ -676,6 +678,7 @@
676678
<Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
677679
<Setter Property="BorderThickness" Value="1" />
678680
<Setter Property="Controls:ControlsHelper.CornerRadius" Value="3" />
681+
<Setter Property="Controls:ControlsHelper.FocusBorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" />
679682
<Setter Property="FontFamily" Value="{DynamicResource DefaultFont}" />
680683
<Setter Property="FontSize" Value="{DynamicResource UpperCaseContentFontSize}" />
681684
<Setter Property="FontWeight" Value="Bold" />
@@ -750,7 +753,7 @@
750753
<Setter Property="Background" Value="{DynamicResource GrayBrush7}" />
751754
</Trigger>
752755
<Trigger Property="IsKeyboardFocusWithin" Value="True">
753-
<Setter Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" />
756+
<Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush), Mode=OneWay}" />
754757
</Trigger>
755758
</Style.Triggers>
756759
</Style>

0 commit comments

Comments
 (0)