remove red rectangle around combobox

时光总嘲笑我的痴心妄想 提交于 2019-12-03 18:38:37

问题


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? :(


回答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}"
          ...>



回答2:


Add your Combobox, Validation.ErrorTemplate="{x:Null}" ; this code is ignore errors.




回答3:


The setter in your trigger is setting the Visibility property of an element named "NotValid". That is not defined in the XAML you posted. If there is no element named "NotValid", that is your problem.



来源:https://stackoverflow.com/questions/4135955/remove-red-rectangle-around-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!