我正在开发WPF应用程序。我的应用程序中有3个切换按钮。我使用切换按钮中的图像。我使用这个切换按钮来选择屏幕模式(1屏、3屏或4屏)。
<GroupBox >
<StackPanel Orientation="Horizontal">
<ToggleButton Height="50" Padding="10 5 10 5" Margin="5">
<Image Source="content/1screen.png"/>
</ToggleButton>
<ToggleButton Height="50" Padding="10 5 10 5" Margin="5">
<Image Source="content/3screen.png"/>
</ToggleButton>
<ToggleButton Height="50" Padding="10 5 10 5" Margin="5">
<Image Source="content/4screen.png"/>
</ToggleButton>
</StackPanel>
</GroupBox>所以我只能选择其中的一个。例如:如果我选择三屏切换按钮,然后选择四屏切换按钮,则必须取消选中三屏切换按钮。有谁能帮我吗?
发布于 2019-03-29 22:53:27
最简单的解决方案是只使用RadioButtons,但将它们设置为类似ToggleButtons的样式:
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" />这将创建一个RadioButton,但应用来自ToggleButton的样式,因此您可以使用RadioButtons执行任何操作,但它看起来将像ToggleButton。要想只选择一个,您可以使用here中解释的GroupName属性
https://stackoverflow.com/questions/55418338
复制相似问题