【问题标题】:WPF: How to get Radiobuttons to display as a horizontal row of ToggleButtonsWPF:如何让 Radiobuttons 显示为 ToggleButtons 的水平行
【发布时间】:2010-07-30 20:48:08
【问题描述】:
我目前正在构建一个将在触摸面板中使用的 UI。因此,我想将任何 RadioButton 组显示为 ToggleButtons 的水平行。我已经想出了如何显示 ToggleButtons 而不是标准的项目符号:
<Style x:Key="{x:Type RadioButton}"
TargetType="{x:Type RadioButton}"
BasedOn="{StaticResource {x:Type ToggleButton}}">
但是,这将显示切换按钮的列,而不是行。
你知道一个简单的方法吗?
非常感谢!
【问题讨论】:
标签:
c#
wpf
xaml
wpf-controls
【解决方案1】:
将单选按钮放在 StackPanel 中,并将方向设置为水平。
<StackPanel Orientation="Horizontal">
<RadioButton Content="1"/>
<RadioButton Content="2"/>
<RadioButton Content="3"/>
</StackPanel >
【解决方案2】:
弄清楚了:解决方案中不涉及 RadioButtons - 我必须修改托管它们的 ItemsControl:
<Style x:Key="myKey" TargetType="{x:Type ItemsControl}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
IsItemsHost="True"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>