WPF: How to get Radiobuttons to display as a horizontal row of ToggleButtons

时光怂恿深爱的人放手 提交于 2019-12-08 19:25:20

问题


I'm currently building a UI that is going to be used in a touch panel. Therefore, I would like to display any RadioButton groups as horizontal rows of ToggleButtons. I already figured out how to display ToggleButtons instead of the standard bullet items:

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

However, this will show a column of ToggleButtons, not a row. Do you know an easy way to do this?

Thanks a lot!


回答1:


Put radio buttons in a StackPanel with Orientation set to Horizontal.

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



回答2:


Figured it out: the RadioButtons are not involved in the solution - I had to modify the ItemsControl that hosted them:

<Style x:Key="myKey" TargetType="{x:Type ItemsControl}">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"
                            IsItemsHost="True"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>


来源:https://stackoverflow.com/questions/3371357/wpf-how-to-get-radiobuttons-to-display-as-a-horizontal-row-of-togglebuttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!