Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 组合框验证错误-为什么失败?_Wpf_Validation_Ribbon - Fatal编程技术网

Wpf 组合框验证错误-为什么失败?

Wpf 组合框验证错误-为什么失败?,wpf,validation,ribbon,Wpf,Validation,Ribbon,想法很简单:从RibbonComboBox中选择一个以秒为单位的周期,并将其保存到应用程序实例属性中。基础数据以毫秒为单位,但组合以秒为单位显示 我的应用程序中的属性以毫秒为单位存储时间: private int _updatePeriod; public int UpdatePeriod { get { return _updatePeriod; } set { _updatePeriod = value; InvokePropertyC

想法很简单:从RibbonComboBox中选择一个以秒为单位的周期,并将其保存到应用程序实例属性中。基础数据以毫秒为单位,但组合以秒为单位显示

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

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>
然后,我有一个功能区工具栏组合框设置,如下所示:

<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>
从功能上来说,这是可以的,因为它在comboboxUpdatePeriod中设置并获取正确的值。但是,下拉列表总是有一个红色边框,我认为这表示验证错误。你知道这是什么原因吗,或者我如何以某种方式调试错误??非常感谢

如果绑定具有关联的验证规则,但未在绑定控件上指定ErrorTemplate,则当出现验证错误时,将使用默认ErrorTemplate通知用户。默认的ErrorTemplate是一个控件模板,它在装饰器层中定义了一个红色边框

我想RibbonComboBox确实定义了一个验证规则

您可以设置attached属性并查看绑定错误,但我将从