我搜索过,但没有看到解决方案。
如果我没有在组合框tooltip属性中设置工具提示,我只能获得验证以显示工具提示。我希望看到验证错误工具提示,否则显示组合框属性中的工具提示。当我从工具提示属性中删除文本时(即从组合框的属性面板中删除),验证工具提示显示正常。
Application.Resources(App.XAML)中的XAML用于显示验证错误的工具提示
<Style x:Key="StandardComboBoxStyle" TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
我还使用Combobox的验证模板,如下所示。这是在用户控件cs文件中的UserControl.Resources部分。
<ControlTemplate x:Key="comboBoxValidationTemplate">
<DockPanel Name="myDockPanel">
<Border BorderBrush="Red" BorderThickness="3">
<AdornedElementPlaceholder Name="MyAdorner" />
</Border>
<TextBlock Text="*" FontWeight="Bold" FontSize="18" Foreground="Red" DockPanel.Dock="Left" />
</DockPanel>
</ControlTemplate>
控件本身定义如下。请注意,这里没有定义其他引用(但希望不相关 - 如果有问题,请随时告诉我。)
<ComboBox x:Name="ExposureTime" SelectedValuePath="Content"
Text="{Binding ExposureTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" IsEditable="True" Validation.ErrorTemplate="{StaticResource comboBoxValidationTemplate}"
HorizontalContentAlignment="Right" FontSize="18" Margin="136,47,462,0" Height="27" VerticalAlignment="Top" GotFocus="ComboBox_GotFocus_1" LostFocus="ComboBox_LostFocus_1" PreviewTextInput="ExposureTime_PreviewTextInput" Opacity="{Binding BackgroundOpacity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontWeight="Thin" Style="{DynamicResource StandardComboBoxStyle}" SelectedValue="{Binding Mode=OneWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" IsTextSearchEnabled="False" ToolTip="My tooltip test.">
<ComboBoxItem Content="0.05"/>
<ComboBoxItem Content="0.1"/>
<ComboBoxItem Content="0.2" />
<ComboBoxItem Content="1" />
<ComboBoxItem Content="2" />
<ComboBoxItem Content="5" />
<ComboBoxItem Content="10" />
<ComboBoxItem Content="20" />
<ComboBoxItem Content="60" />
<ComboBox.IsEnabled >
<MultiBinding Converter="{StaticResource multiBooleanConverter}">
<Binding Path="NotPerformingExposure" UpdateSourceTrigger="PropertyChanged"/>Th
<Binding Path="NotPerformingFocusTest" UpdateSourceTrigger="PropertyChanged"/>
</MultiBinding>
</ComboBox.IsEnabled>
</ComboBox>
谢谢! 降压
答案 0 :(得分:8)
在您的样式触发器中,您在出现错误时将工具提示设置为验证错误。通过操纵Value
Trigger
属性,如果没有错误,也可以这样做
<Style x:Key="StandardComboBoxStyle" TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
<Trigger Property="Validation.HasError" Value="False">
<Setter Property="ToolTip" Value="My tooltip test." />
</Trigger>
</Style.Triggers>
</Style>
另一方面,我建议将Path=(Validation.Errors)[0].ErrorContent
更改为Path=(Validation.Errors).CurrentItem.ErrorContent