WPF Bug清单之(4)——点击RadioButton的空白没有反应2011-01-25 博客园 南柯之石在WPF BUG清单之二,介绍过RadioButton在绑定上的一个Bug。现在再来介绍它的另一个造成RadioButton的点击事件处理不正确的BUG。现象是:点在RadioButton的范围内,可这个RadioButton就是选不中。先来看一个例子。Windows里一个常见的对话框,用了多个RadioButton。如下图所示。

图1.RadioButton使用范例把RadioButton放在GroupBox的Header上,是很常见的一个用例,而且被微软的UX Guide所认可。大家可以在自己的电脑上点点这些RadioButton,只要点在圆圈或文字范围内,就会被选中。我们现在用WPF来实现这个效果。实现的方式有很多。1.直接在Header里放一个RadioButton。简单,不可复用。2.使用HeaderTemplate,里面放个RadioButton。比上面的复杂些,结果一样。3.使用ControlTemplate,还是里面放个RadioButton。复用性好些。简单起见,我们用第一种方式来演示这个Bug。Sample code
<StackPanel Margin="12">
<TextBlock Margin="0,0,0,5" TextWrapping="Wrap">
<Run FontWeight="Bold">Bug Description:</Run>
<Run>略</Run>
</TextBlock>
<GroupBox Padding="9" >
<GroupBox.Header>
<RadioButton Content="Header RadioButton" GroupName="header"/>
</GroupBox.Header>
<GroupBox.Content>
<StackPanel>
<RadioButton Content="Common RadioButton"/>
<RadioButton Content="Common RadioButton"/>
</StackPanel>
</GroupBox.Content>
</GroupBox>
<GroupBox Padding="9" >
<GroupBox.Header>
<RadioButton Content="Header RadioButton" GroupName="header"/>
</GroupBox.Header>
<GroupBox.Content>
<StackPanel>
<RadioButton Content="Common RadioButton"/>
<RadioButton Content="Common RadioButton"/>
</StackPanel>
</GroupBox.Content>
</GroupBox>
</StackPanel>
运行的效果如下图。

图2.RadioButton点击Bug示例PS:本来想做个XBAP程序放上来让大家直接点点。结果没找着上传.exe的地方。这个BUG的根源应该是由于颜色造成的。可以发现鼠标在Header RadioButton上移动时,只有鼠标处在有颜色区域的上方时,RadioButton才认为自己是MouseOver。但是特意给RadioButton的Header设置了Background之后,问题依旧。这个问题让我们的QA和Developer同时抓狂不已。作为高品质的软件,这种看上去的小问题也是不可容忍的。解决方式是有的,但是丑恶得不敢拿出来给大家看。还是等神人出场或是.NET Framework 4.0吧。-----------------------------------------总结的分割线---------------------------------------RadioButton目前已有两个BUG入帐,荣登WPF BUG榜第一。但是RadioButton同学也不要高兴得太早,我们的BUG主力ListBox以其义兄ListView还没发威呢。Button同学就放弃吧,作为最简单的控件之一,也得给我们点儿信心啊。