开发者

Using a DrawingImage as Icon for Multiple MenuItems

开发者 https://www.devze.com 2022-12-13 08:32 出处:网络
I have some icon resources as DrawingImages that is made up of many GeometryDrawings.I have File MenuItems and ToolBar buttons that use these images via resource bindings to MenuItem.Icon.Unfortunatel

I have some icon resources as DrawingImages that is made up of many GeometryDrawings. I have File MenuItems and ToolBar buttons that use these images via resource bindings to MenuItem.Icon. Unfortunately, only one of the MenuItems show the icon.

I am sure you can't assign a single DrawingImage resource to many MenuItem.Icon (or anything else for that matter), but I don't know of an alternative. I would prefer not to duplicate the DrawingImage resource, but if I have 开发者_StackOverflow中文版too I guess I will.


You assign an Image control to the Icon Property and set the DrawingImage into the Image.Source property.

In XAML:

<MenuItem>
    <MenuItem.Icon>
        <Image Source="{StaticResource myDrawingImage}"/>
    </MenuItem.Icon>
    <!-- everyhting else -->
</MenuItem>

In C#:

menuItem.Icon = new Image() {Source = (ImageSource)Resources["myDrawingImage"]};
0

精彩评论

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