【发布时间】:2021-05-06 03:13:41
【问题描述】:
Net 5 WFP 应用程序问题 VS v.16.9
我的自定义控件,应该显示一个普通的在运行时没有显示。我想我知道发生了什么,但不知道如何解决。
合并我的 Generic.xaml 文件中的资源字典以引用我的自定义控件的源会导致蓝色波浪线和鼠标悬停工具提示 “找不到资源 'ControlsFolder/CustomControl.xaml'”
如果我删除我的合并字典,鼠标悬停工具提示会更改为 "Projectnamespace.ControlsFolder.CustomControl"
在我的 MainWindow.xaml 中调用带有工具提示的 CustomControl,如下所示。
<Control:CustomControl/>
我认为导致问题的字典合并是...
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ControlsFolder/CustomContol.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
我的 CustomControls.cs 有下面的构造函数
static CustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl)));
}
据我了解,此构造函数会搜索 Themes/Generic.xaml 文件以找出我的自定义控件的位置,以便将默认元数据添加到我的自定义控件。但我认为,当我添加合并的资源字典时,它会更改我的 CustomControl 调用的路径以在 /ControlFolder/CustomControl.xaml 中搜索我的样式,而不是默认路径应该是“Projectnamespace.ControlsFolder.CustomControl”。
或者我犯了一个对初学者来说根本不直观的简单错误。
也许我可以向 CustomControl 添加一个属性,将路径设置回另一个。有没有人知道问题是什么?
但我应该会在屏幕上看到我的风格显示
【问题讨论】: