WPF:如何让 Radiobuttons 显示为 ToggleButtons 的水平行 [英] WPF: How to get Radiobuttons to display as a horizontal row of ToggleButtons

查看:21
本文介绍了WPF:如何让 Radiobuttons 显示为 ToggleButtons 的水平行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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}}">

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

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

非常感谢!

推荐答案

想通了:解决方案中不涉及 RadioButtons - 我不得不修改托管它们的 ItemsControl:

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>

这篇关于WPF:如何让 Radiobuttons 显示为 ToggleButtons 的水平行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆