checkbox like radiobutton wpf c#
Posted
by
rockenpeace
on Stack Overflow
See other posts from Stack Overflow
or by rockenpeace
Published on 2013-06-26T12:46:53Z
Indexed on
2013/06/26
22:21 UTC
Read the original article
Hit count: 387
i have investigated this problem but this is solved in design view and code-behind. but my problem is little difference: i try to do this as only code-behind because my checkboxes are dynamically created according to database data.In other words, number of my checkboxes is not stable. i want to check only one checkbox in group of checkboxes. when i clicked one checkbox,i want that ischecked property of other checkboxes become false.this is same property in radiobuttons. i take my checkboxes from a stackpanel in xaml side:
<StackPanel Margin="4" Orientation="Vertical" Grid.Row="1" Grid.Column="1" Name="companiesContainer">
</StackPanel>
my xaml.cs:
using (var c = new RSPDbContext())
{
var q = (from v in c.Companies select v).ToList();
foreach (var na in q)
{
CheckBox ch = new CheckBox();
ch.Content = na.Name;
ch.Tag = na;
companiesContainer.Children.Add(ch);
}
}
foreach (object i in companiesContainer.Children)
{
CheckBox chk = (CheckBox)i;
chk.SetBinding(ToggleButton.IsCheckedProperty, "DataItem.IsChecked");
}
how can i provide this property in checkboxes in xaml.cs ? thanks in advance..
© Stack Overflow or respective owner