在第一次尝试创建DataTemplate时,我将MainWindow的类添加到其中以访问事件处理程序。现在,这可能有许多原因是不正确的(并且会产生一些有趣的错误消息),但我想了解为什么ResourceDictionary无法引用像MainWindow这样的部分类?
xaml如下(请注意,如果没有实现任何事件,则会失败)
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary>
</Window.Resources>
</Window>
资源字典。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
>
</ResourceDictionary>
非常感谢您的帮助和建议。