有没有一种方法可以模板化 RadioButton,使其具有 TabItem 样式
我已经尝试过:
<UniformGrid DockPanel.Dock="Top" Columns="2" Rows="1">
<UniformGrid.Resources>
<Style TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<TabItem IsSelected="{TemplateBinding IsChecked}">
<TabItem.Header>
<ContentPresenter Margin="5" />
</TabItem.Header>
</TabItem>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UniformGrid.Resources>
<RadioButton Content="By company name" />
<RadioButton Content="By contact name" Grid.Column="1"/>
</UniformGrid>
它实际上有效,只是它没有选择/取消选择适当的选项卡。
我当然更喜欢单选按钮,但我的客户坚持认为它应该是选项卡。
I've tried:
<UniformGrid DockPanel.Dock="Top" Columns="2" Rows="1">
<UniformGrid.Resources>
<Style TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<TabItem IsSelected="{TemplateBinding IsChecked}">
<TabItem.Header>
<ContentPresenter Margin="5" />
</TabItem.Header>
</TabItem>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UniformGrid.Resources>
<RadioButton Content="By company name" />
<RadioButton Content="By contact name" Grid.Column="1"/>
</UniformGrid>
It actually works except it doesn't select/unselect the appropriate tab.
I would prefer RadioButtons of course, but my customer insist it should be Tabs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于 TabItem 正在“吃掉”鼠标单击,因此 RadioButton 永远不会被选中/取消选中。您可以将 TabItem 包裹在 Border 中并设置
IsHitTestVisible="False"
。这样做您将丢失 IsMouseOver 触发器等,因此您必须从默认模板中重新添加它们尝试像这样的
更新
更新2
您可以使用附加行为在单击 TabItem 时引发 RadioButton 上的 MouseDown 事件。或者,您可以只设置 IsChecked="True" 而不是引发点击事件
LinkWithRadioButtonBehavior
I think the problem is that the TabItem is "eating" the mouseclick so the RadioButton never gets checked/unchecked. You could wrap the TabItem in a Border and set
IsHitTestVisible="False"
. Doing this you'll lose the IsMouseOver trigger etc, so you'll have to re-add them from the Default templateTry something like this
Update
Update 2
You could use an Attached Behavior to raise the MouseDown event on the RadioButton when the TabItem gets clicked. Alternatively you could just set IsChecked="True" instead of raising the click-event
LinkWithRadioButtonBehavior
您可以将单选按钮设置为切换按钮,并创建分配给“单击”事件混合交互触发器的互斥状态。这很痛苦,但比您接受的答案要少得多。希望它可以帮助某人
You could just style the radiobuttons as ToggleButtons and create mutually exclusive states assigned to the "Click" event Blend Interaction Triggers. It's a pain, but much less so than the answer you accepted. Hope it helps someone