WPF:如何让Radiobuttons显示为ToggleButtons的水平行

Jan*_*Jan 7 c# wpf xaml wpf-controls

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

    <Style x:Key="{x:Type RadioButton}" 
           TargetType="{x:Type RadioButton}" 
           BasedOn="{StaticResource {x:Type ToggleButton}}">
Run Code Online (Sandbox Code Playgroud)

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

非常感谢!

Eug*_*rda 12

将单选按钮放在StackPanel中,并将Orientation设置为Horizo​​ntal.

<StackPanel Orientation="Horizontal">
   <RadioButton Content="1"/>
   <RadioButton Content="2"/>
   <RadioButton Content="3"/>
</StackPanel >
Run Code Online (Sandbox Code Playgroud)


Jan*_*Jan 3

弄清楚了: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>
Run Code Online (Sandbox Code Playgroud)