ComboBox验证错误 - 为什么会失败?

时间:2013-06-12 06:47:29

标签: wpf validation ribbon

这个想法很简单:从RibbonComboBox中选择一个以秒为单位的句点并将其保存到app实例属性。基础数据以毫秒为单位,但组合以秒为单位显示它们。

我的应用中的属性以毫秒为单位存储时间:

private int _updatePeriod;
public int UpdatePeriod
{
    get { return _updatePeriod; }
    set
    {
        _updatePeriod = value;
        InvokePropertyChanged(new PropertyChangedEventArgs("UpdatePeriod"));
    }
}

在XAML中我定义了一个可能的选择列表,以毫克为单位:

<x:Array x:Key="UpdateFrequenciesCollection" Type="{x:Type System:Int32}" >
    <System:Int32 >100</System:Int32>
    <System:Int32 >200</System:Int32>
    <System:Int32 >500</System:Int32>
    <System:Int32 >1000</System:Int32>
    <System:Int32 >2000</System:Int32>
</x:Array >

然后我有一个像这样设置的功能区工具栏组合框:

<ribbon:RibbonComboBox IsEditable="False" AllowDrop="False" Grid.Column="1" Grid.Row="1" IsDropDownOpen="False">
    <ribbon:RibbonGallery x:Name="RibbonGalleryUpdatePeriod" SelectedValue="{Binding Path=UpdatePeriod, Mode=TwoWay, Source={x:Static Application.Current}}">
        <ribbon:RibbonGalleryCategory x:Name="RibbonGalleryCategoryUpdatePeriod" ItemTemplate="{StaticResource UpdatePeriodTemplate}" ItemsSource="{Binding Source={StaticResource UpdateFrequenciesCollection}}">
        </ribbon:RibbonGalleryCategory>
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

这是组合框项目的简单模板:

<DataTemplate x:Key="UpdatePeriodTemplate">
    <StackPanel Orientation="Horizontal" >
        <TextBlock Text="{Binding Converter={StaticResource DivideConverter}, ConverterParameter=1000, StringFormat={}{0:0.0 s}}"/>
    </StackPanel>
</DataTemplate>

从功能上来说,它可以设置并在组合框&lt; - &gt; UpdatePeriod中获得正确的值。但是下拉列表总是有一个红色边框,我认为这表示验证错误。知道是什么导致这个,或者我怎么能以某种方式调试错误?非常感谢!

1 个答案:

答案 0 :(得分:0)

If your Binding has associated validation rules but you do not specify an ErrorTemplate on the bound control, a default ErrorTemplate will be used to notify users when there is a validation error. The default ErrorTemplate is a control template that defines a red border in the adorner layer.

我猜RibbonComboBox确实定义了验证规则。

您可以设置附加属性PresentationTraceSources.TraceLevel并查看绑定错误,但我会从Snoop开始