How to change ToggleButton property IsEnabled from codebehind?
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开发者_如何学C 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!
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.
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
精彩评论