我有一个自定义控件,我想从另一个项目的资源字典中应用一些样式。出于某种原因,在UserControl.Resources
中添加资源会失败,但会将其置于Grid.Resources
成功;
<UserControl x:Class="My.Name.Space.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="300">
<UserControl.Resources>
<ResourceDictionary x:Key="UserControlResources">
<!--Putting it here fails-->
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.Resources>
<ResourceDictionary x:Key="GridResources">
<!--Putting it here succeeds-->
</ResourceDictionary>
</Grid.Resources>
<!--Control XAML-->
</Grid>
</UserControl>
我收到错误“当前上下文中不存在名称'IntializeComponent'”。但是,查看自动生成的MyUserControl.g.i.cs文件,嘿presto;它就是。我究竟做错了什么?这两个声明之间有什么区别?
谢谢,Sterren