I have a WPF ListView control containing a number of RadioButton controls using data binding. I'd like the first RadioButton in the group to be checked by default, preferably set in the XAML rather than programmatically, but haven't managed to achieve this.
My XAML for the control is:
<ListView ItemsSource="{Binding OptionsSortedByKey}" >
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type Logging:FilterOptionsRadioListViewModel}">
<RadioButton Content="{Binding Value}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The OptionsSortedByKey property is a SortedList.
I have done this clumsily by setting the IsChecked property of the RadioButton control in the Loaded event:
var button = sender as RadioButton;
if (button != null)
{
if (button.Content.ToString().ToUpperInvariant() == "ALL")
{
button.IsChecked = true;
}
}
I'd far prefer to do it via data binding in the XAML. Is there a simple way?