I'm trying to make it so that only one menu item can be checked at any one time. Sort of like radio buttons. But when I uncheck menu items programmatically the change doesn't show until I mouse over the items. Below is some sample code that demonstrates the bug. To recreate:
- Click the button to open the menu
- Check the first item, then check the second
- Mouse over the first item to see check mark disappear
<UserControl x:Class="SilverlightApplication17.Page" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:teleriknav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerikbase="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:telerikinput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
Width="400" |
Height="300"> |
<Grid x:Name="LayoutRoot" |
Background="White"> |
<Button Content="Open menu" |
Width="100" |
Height="30"> |
<teleriknav:RadContextMenu.ContextMenu> |
<teleriknav:RadContextMenu StaysOpen="True" |
ClickToOpen="True" |
EventName="Click" |
Placement="Bottom"> |
<teleriknav:RadContextMenu.Items> |
<teleriknav:RadMenuItem Header="Item 1" |
IsCheckable="True"> |
</teleriknav:RadMenuItem> |
<teleriknav:RadMenuItem Header="Item 2" |
IsCheckable="True"> |
</teleriknav:RadMenuItem> |
<teleriknav:RadMenuItem Header="Item 3" |
IsCheckable="True"> |
</teleriknav:RadMenuItem> |
</teleriknav:RadContextMenu.Items> |
</teleriknav:RadContextMenu> |
</teleriknav:RadContextMenu.ContextMenu> |
</Button> |
</Grid> |
</UserControl> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using Telerik.Windows; |
using Telerik.Windows.Controls; |
namespace SilverlightApplication17 |
{ |
public partial class Page : UserControl |
{ |
public Page() |
{ |
InitializeComponent(); |
this.AddHandler(RadMenuItem.CheckedEvent, new RoutedEventHandler(RadMenuItem_CheckedChanged)); |
this.AddHandler(RadMenuItem.UncheckedEvent, new RoutedEventHandler(RadMenuItem_CheckedChanged)); |
} |
private void RadMenuItem_CheckedChanged(object sender, RoutedEventArgs e) |
{ |
var radE = e as RadRoutedEventArgs; |
if (radE == null || radE.OriginalSource == null) |
return; |
var item = radE.OriginalSource as RadMenuItem; |
if (item.IsChecked) |
{ |
//Uncheck all the other items |
var menu = item.ParentOfType<RadContextMenu>(); |
menu.Items.ToList().ForEach(obj => |
{ |
var item2 = menu.ItemContainerGenerator.ContainerFromItem(obj) as RadMenuItem; |
if (item2.IsChecked && item2 != item) |
{ |
item2.IsChecked = false; |
} |
}); |
} |
} |
} |
} |