[英]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.