![](/img/trans.png)
[英]xaml How reference a dynamic resource not as a attribute but as an element
[英]How to reference an app resource in a xaml Window?
我在“視圖”窗口中添加了對應用程序資源的引用。 但是當我聲明資源時,我得到了錯誤:
Error 10 RegexValidationRule is not supported in a Windows Presentation Foundation (WPF) project.
這是我將資源添加到視圖的方式:
<Window.Resources>
<validators:RegexValidationRule x:Key="localRegexValidationRule"/>
</Window.Resources>
有誰知道如何在WPF中正確引用資源?
我已遵循此解決方案,但在資源上仍然遇到相同的錯誤。 這是我在資源字典中的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>
您是否在View文件中添加了適當的using語句? 它應該與您的App.xaml文件具有相同的語句:
xmlns:validators="clr-namespace:MongoDBApp.Validators"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.