在 XAML 中,指定来自另一个程序集的图标
我是 WPF 和 XAML 新手。我有以下可以使用代码隐藏的解决方案。但在我看来,在 XAML 中指定应该更容易。
我想将图标设置为另一个程序集中的资源(具体来说,即 System.Activities.Presentation 中的“FlowDecisionIcon”)。当添加到代码隐藏中的构造函数时,以下代码可以工作:
InitializeComponent(); // This was already there
ResourceDictionary dict = new ResourceDictionary { Source = new Uri("pack://application:,,,/System.Activities.Presentation;V4.0.0.0;31bf3856ad364e35;component/themes/icons.xaml") };
this.Resources.MergedDictionaries.Add(dict);
Icon = this.Resources["FlowDecisionIcon"] as DrawingBrush;
我希望有一种很好的方法可以在 XAML 中指定它,如下所示:
<Window xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
Icon="sap:FlowDecisionIcon"> ...
或者,只需在 Visual Studio 的“属性”面板中指定它图标属性。但我一直没能成功地找出执行这两者的语法。
I'm new to WPF and XAML. I have the following solution which WORKS using codebehind. But it seems to me to be something that should be easier to specify in XAML.
I want to set the Icon to a resource in another assembly (specifically, so the "FlowDecisionIcon" in System.Activities.Presentation). The following code works, when added to the constructor in the codebehind:
InitializeComponent(); // This was already there
ResourceDictionary dict = new ResourceDictionary { Source = new Uri("pack://application:,,,/System.Activities.Presentation;V4.0.0.0;31bf3856ad364e35;component/themes/icons.xaml") };
this.Resources.MergedDictionaries.Add(dict);
Icon = this.Resources["FlowDecisionIcon"] as DrawingBrush;
I was hoping there would be a nice way for me to specify this either in the XAML as something like:
<Window xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
Icon="sap:FlowDecisionIcon"> ...
Or, just specify it in Visual Studio in the Properties panel for the Icon property. But I've been unsuccessful in figuring out the syntax to do either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您处于 Window 控件中。
但是,建议将资源合并移至 App.xaml 文件。
It seems that you're in a Window control.
But, it's advised to move the merging of the resources to the App.xaml file.