简体   繁体   English

如何从代码隐藏更改ToggleButton属性IsEnabled?

[英]How to change ToggleButton property IsEnabled from codebehind?

I want to set property IsEnabled to False for some ToggleButton after user click on ConfirmButton. 我想在用户点击ConfirmButton后将某些ToggleButton属性IsEnabled设置为False I would like to do it from codebehind in OnMarkTakenSeatsClick action. 我想在OnMarkTakenSeatsClick操作中从代码隐藏中做到这一点。

Some of my ToggleButtons look like that: 我的一些ToggleButton看起来像这样:

<ToggleButton Style="{DynamicResource Seat}" x:Name="A10" Content="10" Click="OnSeatButtonClick" HorizontalAlignment="Left" Height="28.404" Margin="594.623,219.36,0,0" VerticalAlignment="Top" Width="29.145"/>

I have list of objects (seats) that have ToggleButtons names that should be disabled. 我有对象(席位)列表,其中包含应禁用的ToggleButtons名称。 My Click action from ConfirmButton looks like that: 来自ConfirmButton的我的点击操作如下所示:

void OnMarkTakenSeatsClick(object sender, RoutedEventArgs e)
        {
            foreach (Seat addedSeat in seats)
            {
                if (addedSeat.IsSelected)
                { 

                }
            }
        }

Any help here much appreciated! 任何帮助在这里非常感谢!

这就是为什么我说在你的另一个问题中在你的座位上拥有各自的属性会很好,然后你可以将按钮的IsEnabled绑定到那个并且在你的处理程序逻辑中你根本不需要任何对ui的引用。 ,只需将属性设置为false

I am using you have name in a String inside some property of Seat object. 我正在使用您在Seat对象的某些属性中的String名称。 You can use algorithm given here to find any control via name. 您可以使用此处给出的算法通过名称查找任何控件。 Once you have the control you can disable it easily by setting IsEnabled = false 一旦有了控件,就可以通过设置IsEnabled = false来轻松禁用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM