开发者

In XAML, specify an Icon from another assembly

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 sp开发者_Go百科ecify 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.


It seems that you're in a Window control.

<Window Icon="{DynamicReosurce FlowDecisionIcon}"
     .....
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ReosurceDictionary Source="pack://application:,,,/System.Activities.Presentation;V4.0.0.0;31bf3856ad364e35;component/themes/icons.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
</Window>

But, it's advised to move the merging of the resources to the App.xaml file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜