c# - 从 C# 代码添加 MergedDictionaries 字段
问题描述
XAML 变体:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="needed line" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
如何使用代码添加它?(我试图根本不使用 xaml)
解决方案
在 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);
推荐阅读
- go - 转到 AWS SES 无法找到凭证
- reactjs - NextJs 应用在 SWR 中使用 JavaScript toISOString() 导致无限 API 调用
- azure-devops - Azure devops 错误 0000000d-0000-8888-8000-000000000000 需要读取组织资源权限
- twilio - 有什么方法可以通过排除一组错误而不是专门包含每个错误来为 Twilio SMS 消息设置警报?
- mysql - AWS RDS下MySQL ADD COLUMN慢
- android - 如何重置 CardView 背景?
- c# - Razor 模板中的 Nullable DateTime 错误
- matplotlib - Matplotlib:在绘图中插入图像并能够用鼠标拖动它
- javascript - Vue,单击带有数据的表格单元格并以模式显示该数据
- android - 执行 org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction 时发生故障