5
我搜索了但没有看到解决方案。没有验证错误时不显示工具提示WPF
如果我没有在组合框工具提示属性中设置工具提示,我只能得到验证以显示工具提示。我希望在出现验证错误时提示工具提示,否则显示combobox属性的工具提示。当我从工具提示属性(即从组合框的属性面板)中删除文本时,验证工具提示显示正常。
工具提示,以显示验证错误的XAML中Application.Resources(App.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>
我也使用验证模板的组合框,如下所示。这是用户控件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>
谢谢! 降压
很大的反响有一个错误。它完美的工作 - 谢谢你! – Buck
伟大的解决方案,但如果我想将其应用于不同的组合框,我会怎么做,每个组合框都有不同的工具提示。即Combobox1有工具提示“我是一个”,而ComboBox2有工具提示“我是#2”。我在猜测像 但无法使其工作! –
Dave