Skip to content

Commit

Permalink
Add work around for WinAppSdk 1.4.1 issue
Browse files Browse the repository at this point in the history
More of a bodge than a work around...
  • Loading branch information
DHancock committed Sep 20, 2023
1 parent c6e4c6f commit 37a3ec7
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions SudokuSolver/ViewModels/PuzzleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void UpdateCellForKeyDown(int index, int newValue)
UpdateView();
undoHelper.Push(model);
IsModified = true;
RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}
else
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Open(Stream stream)
{
UpdateView();
undoHelper.Push(model);
RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}
}

Expand All @@ -148,7 +148,7 @@ public void New()
UpdateView();
undoHelper.Push(model);
IsModified = false;
RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}

public bool ShowPossibles
Expand Down Expand Up @@ -224,7 +224,7 @@ public void ExecuteUndo(object? param)
model = undoHelper.PopUndo();
UpdateView();
IsModified = true;
RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}
}

Expand All @@ -238,7 +238,7 @@ public void ExecuteRedo(object? param)
model = undoHelper.PopRedo();
UpdateView();
IsModified = true;
RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}
}

Expand All @@ -249,18 +249,25 @@ public void Puzzle_SelectedIndexChanged(object sender, Views.Cell.SelectionChang
else if (selectedIndex == e.Index)
selectedIndex = -1;

RaiseCanExecuteChanged();
UpdateMenuItemsDisabledState();
}

private void RaiseCanExecuteChanged()
private void UpdateMenuItemsDisabledState()
{
UndoCommand.RaiseCanExecuteChanged();
RedoCommand.RaiseCanExecuteChanged();
CutCommand.RaiseCanExecuteChanged();
CopyCommand.RaiseCanExecuteChanged();
DeleteCommand.RaiseCanExecuteChanged();
PasteCommand.RaiseCanExecuteChanged();
MarkAsGivenCommand.RaiseCanExecuteChanged();
// an unfortunate work around for https://github.com/microsoft/microsoft-ui-xaml/issues/8894
// The menu flyout item will loose it's foreground color if disabled from within the ICommands execute
// method when the system theme is light and the app's theme is dark. Fire and forget, so always need to
// call the CanExecute method first when executing to check it's still valid to execute.
Task.Run(() =>
{
UndoCommand.RaiseCanExecuteChanged();
RedoCommand.RaiseCanExecuteChanged();
CutCommand.RaiseCanExecuteChanged();
CopyCommand.RaiseCanExecuteChanged();
DeleteCommand.RaiseCanExecuteChanged();
PasteCommand.RaiseCanExecuteChanged();
MarkAsGivenCommand.RaiseCanExecuteChanged();
});
}

private bool CanCutCopyDelete(object? param = null) => (selectedIndex >= 0) && Cells[selectedIndex].HasValue;
Expand Down

0 comments on commit 37a3ec7

Please sign in to comment.