开发者

How to bind ToggleButtons with a List?

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜