-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set a GroupName when creating new WinUI RadioButtons (#13611)
### Description of Change This change sets a unique GroupName on every WinUI RadioButton created so that different groups of MAUI RadioButtons are not assumed by WinUI to share the same group and thus prevent IsChecked values from being set properly. ### Issues Fixed Fixes #11418
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Maui.Handlers; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class RadioButtonTests | ||
{ | ||
UI.Xaml.Controls.RadioButton GetNativeRadioButton(RadioButtonHandler radioButtonHandler) => | ||
radioButtonHandler.PlatformView; | ||
|
||
bool GetNativeIsChecked(RadioButtonHandler radioButtonHandler) => | ||
GetNativeRadioButton(radioButtonHandler).IsChecked ?? false; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#if WINDOWS | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Handlers; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
[Category(TestCategory.RadioButton)] | ||
public partial class RadioButtonTests : ControlsHandlerTestBase | ||
{ | ||
[Theory(DisplayName = "IsChecked Initializes Correctly")] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public async Task IsCheckedInitializesCorrectly(bool isChecked) | ||
{ | ||
bool xplatIsChecked = isChecked; | ||
var radioButton = new RadioButton() { IsChecked = xplatIsChecked }; | ||
bool expectedValue = isChecked; | ||
var layoutFirst = new VerticalStackLayout(); | ||
var rdFirst = new RadioButton { GroupName = "FirstGroup", IsChecked = xplatIsChecked }; | ||
layoutFirst.Add(rdFirst); | ||
layoutFirst.Add(new RadioButton { GroupName = "FirstGroup" }); | ||
layoutFirst.Add(new RadioButton { GroupName = "FirstGroup" }); | ||
var layoutSecond = new VerticalStackLayout(); | ||
layoutSecond.Add(new RadioButton { GroupName = "SecondGroup" }); | ||
var rdSecond = new RadioButton { GroupName = "SecondGroup", IsChecked = xplatIsChecked }; | ||
layoutSecond.Add(rdSecond); | ||
layoutSecond.Add(new RadioButton { GroupName = "SecondGroup" }); | ||
var layout = new VerticalStackLayout | ||
{ | ||
layoutFirst, | ||
layoutSecond | ||
}; | ||
var valuesFirst = await GetValueAsync(rdFirst, (handler) => { return new { ViewValue = rdFirst.IsChecked, PlatformViewValue = GetNativeIsChecked(handler as RadioButtonHandler) }; }); | ||
var valuesSecond = await GetValueAsync(rdSecond, (handler) => { return new { ViewValue = rdSecond.IsChecked, PlatformViewValue = GetNativeIsChecked(handler as RadioButtonHandler) }; }); | ||
Assert.Equal(xplatIsChecked, valuesFirst.ViewValue); | ||
Assert.Equal(expectedValue, valuesFirst.PlatformViewValue); | ||
Assert.Equal(xplatIsChecked, valuesSecond.ViewValue); | ||
Assert.Equal(expectedValue, valuesSecond.PlatformViewValue); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters