remove red rectangle around combobox
19,679
Solution 1
Use this to modify the Validation.ErrorTemplate
<ControlTemplate x:Key="ComboBoxValidationErrorTemplate">
<DockPanel>
<Border BorderBrush="Blue" BorderThickness="4">
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
And then use it in your ComboBox like
<ComboBox Validation.ErrorTemplate="{StaticResource ComboBoxValidationErrorTemplate}"
...>
To have no indication of a Validation Error, remove the DockPanel, set Visibility to Collapsed or any other way you like.
Almost forgot, probably the easiest way to remove the "Red Border"
<ComboBox Validation.ErrorTemplate="{x:Null}"
...>
Solution 2
Add your Combobox, Validation.ErrorTemplate="{x:Null}" ; this code is ignore errors.
Author by
vikox
Updated on June 15, 2022Comments
-
vikox almost 2 years
i need to remove red rectangle around combobox. I have setup combobox in xaml like (below) this and i`m trying to override of the Validation.ErrorTemplate.
<ComboBox x:Name="comboPodkategoria" Margin="0,3,0,0" IsSynchronizedWithCurrentItem="False" IsEditable="False" ItemsSource="{Binding Source={StaticResource PodKategoriaLookup}, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" SelectedValue="{Binding IDPodKategoria}" DisplayMemberPath="kat_popis" SelectedValuePath="IDPodkat" TabIndex="5" Style="{StaticResource combostyle}"> <Validation.ErrorTemplate> <ControlTemplate> </ControlTemplate> </Validation.ErrorTemplate> </ComboBox>
And style for removing red rectangle, but a have some error in xaml saying that Visibility property is not recognized or is not accessible. Style definition is below.
<Style x:Key="combostyle"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Property="Visibility" TargetName="NotValid" Value="Visible"/> </Trigger> </Style.Triggers>
Any idea? :(
-
vikox over 13 yearsPerfect, thank you. The last option is perfect for me, i didn`t know that.
-
BSalita about 12 years+1 for Validation.ErrorTemplate="{x:Null}". I'm experiencing the joy of a "exactly right" UI element.
-
Mark over 10 years+1 for Validation.ErrorTemplate="{x:Null}", awesome one, Thanks.
-
mkb over 8 yearsBut is it ok to remove red validation rectangle in such case, doesn't it mean that binding is failing? also shouldn't it be done by OneWay binding since the ItemsSource is bound to a StaticResource? as in :
ItemsSource="{Binding Source={StaticResource PodKategoriaLookup, Mode=OneWay},
-
Fredrik Hedblad over 8 years@mkb: It is a visual indication of a validation error on a binding. If you want to modify or remove that visual indication, for whatever reason, then it can be done like in the examples above.
-
Wish almost 8 yearsI dont have much experience in WPF, but are there such nonsenses with textboxes?