在WPF中触发切换按钮 [英] Trigger a toggle button in WPF

查看:185
本文介绍了在WPF中触发切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有一个在其中放置3个切换按钮的组,单击一个切换按钮后,应禁用该组中的其他切换按钮

Hello All.

I have a group in which I have placed 3 togglebutton,After I click one toggle button the other toggle buttons in the group should be disabled

<RibbonTab x:Name="tb" Header="T">
                <ribbon:RibbonGroup Name="Co" >
                    <ribbon:RibbonToggleButton Name="line" Label="Line" ></ribbon:RibbonToggleButton>
                    <ribbon:RibbonToggleButton Name="Polyline" Label="PolyLine" ></ribbon:RibbonToggleButton>

                </ribbon:RibbonGroup>

            </ribbon:RibbonTab>



我知道我们可以使用click事件来做到这一点并禁用它们,但是想知道我们是否可以使用xaml和wpf中的触发器来做到这一点
当我单击Ribbontogglebutton名称时,应该禁用线"按钮折线"



I know we can do this with click event and disable them,but was wondering if we can do this using triggers in xaml and wpf
When I click Ribbontogglebutton name "line" button "polyline" should be disabled

推荐答案

您可以为此使用触发器,尽管这样做会浪费很多时间代码空间.

相反,为什么不尝试查找一个被称为很多的方法,并在其中进行检查,就像这样:

公共无效OftenCalledMethod(int bla1,int bla2)
{
if(toggleButton1.IsChecked)
{
toggleButton2.IsChecked = false;
}

...
}

依此类推.我知道示例是伪代码,但是应该很容易转换.
You can use triggers for this, although if you do that, you will waste a lot of code space.

Instead, why don''t you try finding a method that is called a lot, and check inside there, similar to this:

public void OftenCalledMethod(int bla1, int bla2)
{
if(toggleButton1.IsChecked)
{
toggleButton2.IsChecked = false;
}

...
}

And so forth. I know the example is in pseudo code, but it should be easy to convert.


这篇关于在WPF中触发切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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