WPF:如何使单选按钮显示为切换按钮的水平行

时间:2010-07-30 12:26:48

标签: c# wpf xaml wpf-controls

我目前正在构建一个将在触摸屏中使用的UI。因此,我想将任何RadioButton组显示为ToggleButtons的水平行。我已经想出了如何显示ToggleButtons而不是标准项目符号:

    <Style x:Key="{x:Type RadioButton}" 
           TargetType="{x:Type RadioButton}" 
           BasedOn="{StaticResource {x:Type ToggleButton}}">

但是,这将显示ToggleButtons的,而不是。 你知道一个简单的方法吗?

非常感谢!

2 个答案:

答案 0 :(得分:10)

将单选按钮放在StackPanel中,方向设置为水平。

<StackPanel Orientation="Horizontal">
   <RadioButton Content="1"/>
   <RadioButton Content="2"/>
   <RadioButton Content="3"/>
</StackPanel >

答案 1 :(得分:3)

想出来:解决方案中没有涉及单选按钮 - 我必须修改托管它们的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>
相关问题