<ResourceDictionary x:Class="MyAssembly.MiscResources" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <SolidColorBrush x:Key="MyBrush" Color="Purple" /> </ResourceDictionary>
那么我有一些C#:
var dict = new MiscResources();
dict 被创建并似乎正常运行,但它有0个元素。并不是说这是一种必要的行为,但我完全不明白为什么它不起作用。我错过了什么?
dict
在ResourceDictionary的分部类中缺少对Initializecomponent()的调用
namespace YourNameSpace { public partial class someClassName: ResourceDictionary { public someClassName() { InitializeComponent(); // you need this for the LoadComponent call on the Baml.. } } }