0

I have a lot of ToggleButtons (about 260). Part of my code with ToggleButtons:

<ToggleButton Style="{DynamicResource Seat}" Content="10" Click="OnSeatButtonClick"/>
<ToggleButton Style="{DynamicResource Seat}" Content="18" Click="OnSeatButtonClick"/>
<ToggleButton Style="{DynamicResource Seat}" Content="10" Click="OnSeatButtonClick" IsEnabled="False"/>  

I want to add action that after clicking on button "Confirm changes", ToggleButtons that are at the moment checked will go into disabled state. And what is more I want those changes to be saved to database.

So I figured that I would need to add some unique id to those ToggleButtons. And then somehow bind them to a List with elements of type Saet.

Code of class Seat:

public class Seat
{
    string Column;
    string Number;
    bool IsTaken;
}

So my question is: how to bind those ToggleButtons with List, so that I will be able to operate on them?

Any help here much appreciated!

H.B.
  • 166,899
  • 29
  • 327
  • 400
Marta
  • 2,857
  • 13
  • 46
  • 67

1 Answers1

3

Create an ItemsControl and set its ItemTemplate to be your ToggleButton, bind the ItemsSource to your seat-collection. From there its just some custom logic in the handler.

It would probably be advantageous to provide properties for the button-state in your bound object as, then you can bind the IsEnabled and IsChecked to those.

H.B.
  • 166,899
  • 29
  • 327
  • 400