2019独角兽企业重金招聘Python工程师标准>>>
http://stackoverflow.com/a/35692688/5972372
这个问题下还有其他解决方案,可以看看,不过还是喜欢这种实现方式,简单干净。
public class RadioMenuItem : MenuItem
{
public string GroupName { get; set; }
protected override void OnClick()
{
var c = Parent as ItemsControl;
if (null != c)
{
var rmi = c.Items.OfType().FirstOrDefault(i => i.GroupName == GroupName && i.IsChecked);
if (null != rmi) rmi.IsChecked = false;
IsChecked = true;
}
base.OnClick();
}
private static readonly Geometry RadioDot = Geometry.Parse(
"M9,5.5L8.7,7.1 7.8,8.3 6.6,9.2L5,9.5L3.4,9.2 2.2,8.3 1.3,7.1L1,5.5L1.3,3.9 2.2,2.7 3.4,1.8L5,1.5L6.6,1.8 7.8,2.7 8.7,3.9L9,5.5z");
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var p = GetTemplateChild("Glyph") as Path;
if (null == p) return;
//var x = p.Width/2;
//var y = p.Height/2;
//var r = Math.Min(x, y) - 1;
//var e = new EllipseGeometry(new Point(x,y), r, r);
//p.Data = e.GetFlattenedPathGeometry();
p.Data = RadioDot;
}
private new bool IsCheckable { get; } = false;
}