Skip to content

Commit

Permalink
Fix #237: AppBarToggleButton is not greyed out when set to disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Jan 5, 2021
1 parent 47b84d5 commit eebdb5c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
47 changes: 25 additions & 22 deletions ModernWpf.Controls/CommandBar/AppBarButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ModernWpf.Controls.Primitives;
Expand Down Expand Up @@ -361,36 +359,41 @@ private void UpdateVisualState(bool useTransitions = true)

private void UpdateCommonState(bool useTransitions = true)
{
if (_vsm is null)
{
return;
}

string stateName;

if (!IsEnabled)
{
stateName = "Disabled";
}
else if (IsPressed)
{
stateName = "Pressed";
}
else if (IsMouseOver)
{
stateName = "PointerOver";
}
else
{
stateName = "Normal";
}
if (IsPressed)
{
stateName = "Pressed";
}
else if (IsMouseOver)
{
stateName = "PointerOver";
}
else
{
stateName = "Normal";
}

if (IsInOverflow)
{
stateName = "Overflow" + stateName;
if (IsInOverflow)
{
stateName = "Overflow" + stateName;
}
}

if (_vsm != null)
{
_vsm.CanChangeCommonState = true;
VisualStateManager.GoToState(this, stateName, useTransitions);
_vsm.CanChangeCommonState = false;
}
_vsm.CanChangeCommonState = true;
VisualStateManager.GoToState(this, stateName, useTransitions);
_vsm.CanChangeCommonState = false;
}

private void UpdateKeyboardAcceleratorTextVisibility(bool useTransitions = true)
Expand Down
23 changes: 12 additions & 11 deletions ModernWpf.Controls/CommandBar/AppBarToggleButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ModernWpf.Controls.Primitives;
Expand Down Expand Up @@ -329,10 +327,16 @@ private void UpdateVisualState(bool useTransitions = true)

private void UpdateCommonState(bool useTransitions = true)
{
if (_vsm is null)
{
return;
}

string stateName;
bool isEnabled = IsEnabled;
bool isChecked = IsChecked != false;

if (!IsEnabled)
if (!isEnabled)
{
stateName = "Disabled";
}
Expand All @@ -358,17 +362,14 @@ private void UpdateCommonState(bool useTransitions = true)
stateName = "Checked" + stateName;
}

if (IsInOverflow)
if (isEnabled && IsInOverflow)
{
stateName = "Overflow" + stateName;
}

if (_vsm != null)
{
_vsm.CanChangeCommonState = true;
VisualStateManager.GoToState(this, stateName, useTransitions);
_vsm.CanChangeCommonState = false;
}
_vsm.CanChangeCommonState = true;
VisualStateManager.GoToState(this, stateName, useTransitions);
_vsm.CanChangeCommonState = false;
}

private void UpdateKeyboardAcceleratorTextVisibility(bool useTransitions = true)
Expand Down

0 comments on commit eebdb5c

Please sign in to comment.