Skip to content

Commit

Permalink
Tweak ToggleSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Feb 17, 2020
1 parent 5759021 commit 6628f58
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
13 changes: 13 additions & 0 deletions ModernWpf.Controls/ToggleSwitch/ToggleSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ public bool IsPressed

#endregion

#region CornerRadius

public static readonly DependencyProperty CornerRadiusProperty =
ControlHelper.CornerRadiusProperty.AddOwner(typeof(ToggleSwitch));

public CornerRadius CornerRadius
{
get => (CornerRadius)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}

#endregion

private ContentPresenter HeaderContentPresenter { get; set; }

private FrameworkElement SwitchKnobBounds { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions ModernWpf.Controls/ToggleSwitch/ToggleSwitch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
<Setter.Value>
<ControlTemplate TargetType="local:ToggleSwitch">
<Border
SnapsToDevicePixels="True"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius}">
CornerRadius="{TemplateBinding CornerRadius}"
SnapsToDevicePixels="True">

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ToggleStates">
Expand Down Expand Up @@ -172,8 +173,7 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Grid Background="{TemplateBinding Background}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand Down
1 change: 1 addition & 0 deletions Settings.XamlStyler
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
RotateTransform,
TranslateTransform,
Trigger,
EventTrigger,
Condition,
Setter,
Style,
Expand Down
2 changes: 1 addition & 1 deletion test/ModernWpfTestApp/CommonStylesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void ToggleSwitchDensityTest_Click(object sender, RoutedEventArgs e)
simpleVerify.IsEqual(contentPresenter.Margin.ToString(), expectedHeaderMargin, "HeaderContentPresenter.Margin");
}

var grid = (Grid)root;
var grid = (Grid)VisualTreeHelper.GetChild(root, 0);
if (grid != null)
{
var rowDefinitions = grid.RowDefinitions;
Expand Down

0 comments on commit 6628f58

Please sign in to comment.