【问题标题】: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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 2021-05-13
      • 2010-12-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      相关资源
      最近更新 更多