RadioButton Unchecked Event Missing #24086
Unanswered
usefulBeeing
asked this question in
Ideas
Replies: 1 comment 3 replies
-
You can solve this with a TwoWay binding to IsChecked, either:
// MyRadioButton.cs
public class MyRadioButton : RadioButton
{
public event EventHandler Checked;
public event EventHandler Unchecked;
public MyRadioButton()
{
PropertyChanged += (s,e) => {
if (e.PropertyName == nameof(IsChecked))
{
if (IsChecked)
Checked?.Invoke(this, EventArgs.Empty);
else
Unchecked?.Invoke(this, EventArgs.Empty);
}
};
}
} // MainViewModel.cs
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
bool _isChecked;
public MainViewModel()
{
PropertyChanged += (s,e) =>
{
if (e.PropertyName == nameof(IsChecked))
{
if (IsChecked)
Debug.WriteLine("Checked");
else
Debug.WriteLine("Unchecked");
}
};
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Unlike WPF RadioButton, MAUI's RadioButton lacks an Unchecked event. Instead, the CheckedChanged event appears to handle both underlaying events. This might be fine in Code Behind, but in MVVM? I'm not sure, maybe due to lack of samples or documentation.
I would like to see CheckedChanged split into Checked and Unchecked events.
First, this will align with the separation of concerns principle.
Second, clear any confusion about how this 2 in 1 CheckedChanged event is supposed to work,
especially in an MVVM scenario (Using Commands for example).
Beta Was this translation helpful? Give feedback.
All reactions