XAML变体:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="needed line" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>如何使用代码添加此代码?(我试着根本不使用xaml )
发布于 2019-04-08 02:59:15
在App.xaml.cs的某个地方(例如构造函数)
var src1 = new ResourceDictionary { Source = new Uri("Dictionary1.xaml", UriKind.Relative) };
this.Resources.MergedDictionaries.Add(src1);编辑:或者你的意思是你想要在没有XAML的情况下构建合并资源?
如果是的话,就这样做
//build some resources
var btnStyle = new Style(typeof(Button));
btnStyle.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.Red));
var src1 = new ResourceDictionary();
src1.Add("btnStyleKey", btnStyle);
this.Resources.MergedDictionaries.Add(src1);https://stackoverflow.com/questions/55564463
复制相似问题