I have a WPF application where I have 2 custom UserControl, both have the characteristic that are reusable. The first user control is an FormGroup where exposes a label and a reference to the other user control. The second UserControl is a custom PlaceholderTextbox where exposes an TextBox and TextBlock in simple terms.
- MainWindow.xaml
<FormGroupUserControl Text={Binding Text} />
- FormGroupUserControl
<Label />
<PlaceholderTextBoxUserControl Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
- PlaceholderTextBoxUserControl
<TextBlock />
<TextBox Text="{Binding Placeholder, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
So basically I’m propagating the Text binding into the TextBox, the issue I’m having is when trying to make validations with INotifyDataErrorInfo that is defined in my MainViewModel is that the red border is outlining my entire FormGroupUserControl, I know that this is how should work because I’m adding errors into the entire UserControl, but how can I propagate that Validation error into the TextBox inside PlaceHolderTextBoxUserControl.
I tried with ValidationAdornerSiteFor and the red border now is in the entire PlaceHolderTextBoxUserControl UserControl, but not in the TextBox. Anyways this can be a solution but how can I edit the style of the Validation red error border, otherwise how can I propagate the validation error into the TextBox
- FormGroupUserControl
<Label />
<PlaceholderTextBoxUserControl Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Validation.ValidationAdornerSiteFor="{Binding RelativeSource={RelativeSource AncestorType=UserControl}}"/>