【问题标题】:How to reference an app resource in a xaml Window?如何在 xaml 窗口中引用应用程序资源?
【发布时间】:2015-11-17 18:47:39
【问题描述】:

我在我的视图窗口中添加了对应用资源的引用。但是当我声明资源时,我得到了错误:

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>

【问题讨论】:

  • 那个验证器呢? (validators:RegexValidationRule) 听起来有点奇怪。你用混合吗? (因为我用 Google 搜索发现:dotnetgui.blogspot.hu/2012/02/…

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


【解决方案1】:

您是否在视图文件中添加了适当的 using 语句?它应该与您的 App.xaml 文件具有相同的语句:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    相关资源
    最近更新 更多