0

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!

Marta
  • 2,857
  • 13
  • 46
  • 67

2 Answers2

1

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.

Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400
0

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

Community
  • 1
  • 1
Haris Hasan
  • 29,856
  • 10
  • 92
  • 122