I have a RadioButton
inside ItemsControl
. By default Radio Buttons will be unchecked. I want the user to select either of the radio buttons if a particular value (string value) is configured in another screen. I need to apply a validation rule for the same. If the user does not select either of the radio buttons, then on click on a submit button, I should display validation error.
XAML
<StackPanel Grid.Row="1" Visibility="{Binding Path=IsUpdateSendDateConfigured}" Orientation="Horizontal" Margin="0,2,0,0">
<TextBlock Text="{Binding Path=UpdateSendDate, UpdateSourceTrigger=PropertyChanged}" FontWeight="Bold" FontSize="12" Width="400" TextWrapping="WrapWithOverflow" />
<ItemsControl Name="updateSendDateLevelItemsControl" ItemsSource="{Binding UpdateSendDateLevel}" Margin="10,5,0,10">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton Height="25" GroupName="updateSendDateLevel" IsChecked="{Binding Selected, ValidatesOnDataErrors=True}" Padding="10,0,10,0" > <!--Need to apply Validation rule here -->
<TextBlock Text="{Binding Description}"/>
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
UpdateSendDateLevel is a view model which I am updating in the controller.
if (!string.IsNullOrEmpty(configuredUpdateDueDateSelection))
{
UpdateSendDateViewModel updateSendDateLevelViewModel = null;
foreach (SendDate value in Enum.GetValues(typeof(SendDate)).Cast<SendDate>())
{
updateSendDateLevelViewModel = new UpdateSendDateViewModel();
updateSendDateLevelViewModel.UpdateSendDateLevel = value;
updateSendDateLevelViewModel.Description = EnumHelper.GetDescription(value);
m_sendDataContext.UpdateSendDateLevel.Add(updateSendDateLevelViewModel);
}
}
Can someone please help with with adding xaml side validation rule or point me in the right direction?
Let me know if you need any other details.