Reputation: 823
I dynamically create a collection of radiobuton
s.
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="CurrentParameter"
IsChecked="{Binding IsSelected, Mode=TwoWay}"
Content="{Binding Name, Mode=OneWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
How can I set first of them to IsChecked=true
by default? Ideally will be to do it in xaml
.
Upvotes: 0
Views: 1028
Reputation: 169150
You should set the corresponding IsSelected
source property to true
in your view model.
View:
<ItemsControl ItemsSource="{Binding YourItemsSourceCollection}" ... />
View Model:
YourItemsSourceCollection[0].IsSelected = true;
That's how MVVM and data binding works. You set the initial value of the property that the CheckBox
in the view binds to. The XAML markup shouldn't contain any logic that decides which value is selected initially. This logic belongs to the view model.
Upvotes: 3