ResourceDictionary 添加 x:Class
在第一次尝试创建 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>
资源 dic。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
>
</ResourceDictionary>
任何想法非常感谢
In a first attempt to create a DataTemplate I added the class from MainWindow to access eventhandlers. Now this may be incorrect for a number of reasons (and produces some interesting error messages) however I'd like to understand why a ResourceDictionary is unable to reference a partial class such as MainWindow ?
xaml as follows (note that this fails without any events implemented)
<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>
Resource dic.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
>
</ResourceDictionary>
Any thoughts much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
MainWindow
之类的东西来备份资源字典,因为MainWindow
不是从ResourceDictionary
类继承的。请参阅此 文章可以更好地理解资源字典背后的代码的使用......
我希望这能回答您的问题。
You cannot have a resource dictionary backed up by something like a
MainWindow
becauseMainWindow
does not inherit fromResourceDictionary
class.See this article for better understanding of the use of code behind resource dictionaries ...
I hope this answers your question.