Browse Source

Merge pull request #2950 from Gillibald/fixes/2903

Fixes RadioButton GroupName when reattached to visual tree
pull/2979/head
danwalmsley 7 years ago
committed by GitHub
parent
commit
6adf3174d1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      src/Avalonia.Controls/RadioButton.cs

25
src/Avalonia.Controls/RadioButton.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls
public static readonly RadioButtonGroupManager Default = new RadioButtonGroupManager();
static readonly ConditionalWeakTable<IRenderRoot, RadioButtonGroupManager> s_registeredVisualRoots
= new ConditionalWeakTable<IRenderRoot, RadioButtonGroupManager>();
readonly Dictionary<string, List<WeakReference<RadioButton>>> s_registeredGroups
= new Dictionary<string, List<WeakReference<RadioButton>>>();
@ -127,13 +127,11 @@ namespace Avalonia.Controls
{
if (!string.IsNullOrEmpty(GroupName))
{
var manager = RadioButtonGroupManager.GetOrCreateForRoot(e.Root);
if (manager != _groupManager)
{
_groupManager.Remove(this, _groupName);
_groupManager = manager;
manager.Add(this);
}
_groupManager?.Remove(this, _groupName);
_groupManager = RadioButtonGroupManager.GetOrCreateForRoot(e.Root);
_groupManager.Add(this);
}
base.OnAttachedToVisualTree(e);
}
@ -141,9 +139,10 @@ namespace Avalonia.Controls
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
if (!string.IsNullOrEmpty(GroupName) && _groupManager != null)
if (!string.IsNullOrEmpty(GroupName))
{
_groupManager.Remove(this, _groupName);
_groupManager?.Remove(this, _groupName);
}
}
@ -152,9 +151,9 @@ namespace Avalonia.Controls
string oldGroupName = GroupName;
if (newGroupName != oldGroupName)
{
if (!string.IsNullOrEmpty(oldGroupName) && _groupManager != null)
if (!string.IsNullOrEmpty(oldGroupName))
{
_groupManager.Remove(this, oldGroupName);
_groupManager?.Remove(this, oldGroupName);
}
_groupName = newGroupName;
if (!string.IsNullOrEmpty(newGroupName))
@ -181,7 +180,7 @@ namespace Avalonia.Controls
.GetVisualChildren()
.OfType<RadioButton>()
.Where(x => x != this);
foreach (var sibling in siblings)
{
if (sibling.IsChecked.GetValueOrDefault())

Loading…
Cancel
Save