Skip to content

Radiobuttons crash fix - #1795

Merged
Niels Laute (niels9001) merged 4 commits into
microsoft:mainfrom
AndrewKeepCoding:radiobuttons-crash-fix
Mar 8, 2025
Merged

Niels Laute (niels9001) merged 4 commits into
microsoft:mainfrom
AndrewKeepCoding:radiobuttons-crash-fix

Conversation

@AndrewKeepCoding

Copy link
Copy Markdown
Contributor

Description

This PR addresses issues with RadioButtons (microsoft/microsoft-ui-xaml#10347) on the control sample pages.

Motivation and Context

How Has This Been Tested?

Ran the app and verified the changes. Also navigated through all the pages to check if other pages have the same issue.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes a crash with RadioButtons on control sample pages by refactoring the event handling logic used to update control orientations and viewbox properties.

  • Renamed event handlers from RadioButton_Checked to OrientationGroup_SelectionChanged for clarity.
  • Updated the selection change logic to use pattern matching and Enum.TryParse for converting radio button tags.
  • Added new event handlers for Stretch and StretchDirection control updates in the Viewbox sample.

Reviewed Changes

File Description
WinUIGallery/Samples/ControlPages/VariableSizedWrapGridPage.xaml.cs Refactored the orientation update event handler using Enum.TryParse for Orientation.
WinUIGallery/Samples/ControlPages/StackPanelPage.xaml.cs Refactored the orientation update event handler using Enum.TryParse for Orientation.
WinUIGallery/Samples/ControlPages/ViewboxPage.xaml.cs Added event handlers for updating Stretch and StretchDirection using radio selections.

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (4)

WinUIGallery/Samples/ControlPages/VariableSizedWrapGridPage.xaml.cs:24

  • Consider using Enum.TryParse with the ignoreCase parameter (e.g. Enum.TryParse(selectedItem.Tag?.ToString(), true, out var orientation)) to ensure tag matching is case-insensitive.
if ((sender as RadioButtons)?.SelectedItem is not RadioButton selectedItem ||

WinUIGallery/Samples/ControlPages/StackPanelPage.xaml.cs:24

  • Consider using Enum.TryParse with the ignoreCase parameter (e.g. Enum.TryParse(selectedItem.Tag?.ToString(), true, out var orientation)) to ensure tag matching is case-insensitive.
if ((sender as RadioButtons)?.SelectedItem is not RadioButton selectedItem ||

WinUIGallery/Samples/ControlPages/ViewboxPage.xaml.cs:74

  • Consider using Enum.TryParse with ignoreCase set to true (e.g. Enum.TryParse(selectedItem.Tag?.ToString(), true, out var stretch)) to allow for case-insensitive tag matching.
if ((sender as RadioButtons)?.SelectedItem is not RadioButton selectedItem ||

WinUIGallery/Samples/ControlPages/ViewboxPage.xaml.cs:86

  • Consider using Enum.TryParse with ignoreCase set to true (e.g. Enum.TryParse(selectedItem.Tag?.ToString(), true, out var stretchDirection)) to allow for case-insensitive tag matching.
if ((sender as RadioButtons)?.SelectedItem is not RadioButton selectedItem ||
@niels9001
Niels Laute (niels9001) enabled auto-merge (squash) March 8, 2025 18:28
@niels9001

Copy link
Copy Markdown
Collaborator

/azp run

@niels9001
Niels Laute (niels9001) merged commit 7b1f6e6 into microsoft:main Mar 8, 2025
@AndrewKeepCoding
Andrew KeepCoding (AndrewKeepCoding) deleted the radiobuttons-crash-fix branch March 8, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants