简体   繁体   中英

How to reference an app resource in a xaml Window?

I've added a reference to an app resource in my View's window. But when I declare the resource I get the error:

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

This is how I added the resource to the View:

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

Does anyone know how to reference the resource correctly in WPF?

I've followed this solution but still get the same error on the resource. This is how I've declared the resource in app.xaml within a resource dictionary:

<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>

Have you added the appropriate using statement in your View file? It should have the same statement as your App.xaml file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM