How to change ToggleButton property IsEnabled from codebehind?

0 votes
asked Aug 30, 2011 by marta

I want to set property IsEnabled to False for some ToggleButton after user click on ConfirmButton. I would like to do it from codebehind in OnMarkTakenSeatsClick action.

Some of my ToggleButtons look like that:

<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. My Click action from ConfirmButton looks like that:

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

Any help here much appreciated!

2 Answers

+1 vote
answered Aug 30, 2011 by haris-hasan

I am using you have name in a String inside some property of Seat object. 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

+1 vote
answered Nov 8 by h-b

This is why i said that it would be good to have respective properties on your seats in your other question, then you can just bind the IsEnabled of the button to that and in your handler logic you do not need any reference to the ui at all, just set the property to false and that is it.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...