//file RadioButton.cs [ThreadStatic] privatestatic Hashtable _groupNameToElements; protectedoverridevoidOnChecked(RoutedEventArgs e) { // If RadioButton is checked we should uncheck the others in the same group UpdateRadioButtonGroup(); base.OnChecked(e); } privatevoidUpdateRadioButtonGroup() { string groupName = GroupName; if (!string.IsNullOrEmpty(groupName)) { Visual rootScope = KeyboardNavigation.GetVisualRoot(this); if (_groupNameToElements == null) _groupNameToElements = new Hashtable(1); lock (_groupNameToElements) { // Get all elements bound to this key and remove this element ArrayList elements = (ArrayList)_groupNameToElements[groupName]; for (int i = 0; i < elements.Count; ) { WeakReference weakReference = (WeakReference)elements[i]; RadioButton rb = weakReference.Target as RadioButton; if (rb == null) { // Remove dead instances elements.RemoveAt(i); } else { // Uncheck all checked RadioButtons different from the current one if (rb != this && (rb.IsChecked == true) && rootScope == KeyboardNavigation.GetVisualRoot(rb)) rb.UncheckRadioButton(); i++; } } } } else// Logical parent should be the group { DependencyObject parent = this.Parent; if (parent != null) { // Traverse logical children IEnumerable children = LogicalTreeHelper.GetChildren(parent); IEnumerator itor = children.GetEnumerator(); while (itor.MoveNext()) { RadioButton rb = itor.Current as RadioButton; if (rb != null && rb != this && string.IsNullOrEmpty(rb.GroupName) && (rb.IsChecked == true)) rb.UncheckRadioButton(); } } } }