如何在xaml窗口中引用app资源?

时间:2015-11-17 18:47:40

标签: wpf xaml resources app.xaml application-resource

我在View的窗口中添加了对app资源的引用。但是,当我声明资源时,我收到错误:

Error   10  RegexValidationRule is not supported in a Windows Presentation Foundation (WPF) project.

这是我将资源添加到视图的方式:

  <Window.Resources>
        <validators:RegexValidationRule x:Key="localRegexValidationRule"/>
    </Window.Resources>

有谁知道如何在WPF中正确引用资源?

我已关注this solution但仍然在资源上遇到相同的错误。这就是我在资源字典中在app.xaml中声明资源的方式:

<Application x:Class="MongoDBApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:converters="clr-namespace:MongoDBApp.Converters"
             xmlns:validators="clr-namespace:MongoDBApp.Validators"
             StartupUri="pack://application:,,,/Views/MainView.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <converters:BoolToNonVisibilityConverter x:Key="localBoolToNonVisibilityConverter" />
            <converters:BoolToVisibilityConverter x:Key="localBoolToVisibilityConverter" />
            <validators:RegexValidationRule x:Key="localRegexValidationRule" />
        </ResourceDictionary>
    </Application.Resources>
</Application>

1 个答案:

答案 0 :(得分:0)

您是否在View文件中添加了相应的using语句?它应该与您的App.xaml文件具有相同的声明:

         xmlns:validators="clr-namespace:MongoDBApp.Validators"