如何将绘图画笔显示为菜单项图标

时间:2017-02-01 06:02:10

标签: wpf xaml

我需要将绘图画笔显示为MenuItem图标。

以下是绘图画笔

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DrawingBrush x:Key="NewDocument" Stretch="Uniform">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <DrawingGroup.Children>
                    <GeometryDrawing Brush="#FF000000" Geometry="F1 M 41.3333,41.3333L 0,41.3333L 0,0L 41.3333,0L 41.3333,41.3333 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 15.8164,7.40293L 15.8164,1.85626L 13.9991,1.85626L 13.9991,7.40293C 14.2964,7.35093 14.5951,7.31093 14.9071,7.31093C 15.2191,7.31093 15.5177,7.35093 15.8164,7.40293 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 21.1491,3.7708L 19.5731,2.86147L 16.7997,7.6668C 17.3784,7.88413 17.9024,8.19614 18.3704,8.5828L 21.1491,3.7708 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 24.8099,8.09827L 23.9005,6.52493L 19.0885,9.30227C 19.4765,9.76893 19.7899,10.2929 20.0045,10.8756L 24.8099,8.09827 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 8.66667,21.7579L 10.2413,22.6672L 13.0147,17.8619C 12.436,17.6472 11.912,17.3352 11.444,16.9459L 8.66667,21.7579 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 5.00454,17.4343L 5.91387,19.0076L 10.7272,16.2289C 10.3392,15.7623 10.0259,15.2396 9.8112,14.6596L 5.00454,17.4343 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 9.54493,11.8561L 3.9996,11.8561L 3.9996,13.6735L 9.54493,13.6735C 9.49559,13.3788 9.45426,13.0748 9.45426,12.7655C 9.45426,12.4548 9.49559,12.1521 9.54493,11.8561 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 5.914,6.52533L 5.00467,8.09866L 9.81,10.8747C 10.0247,10.2933 10.338,9.76934 10.726,9.30266L 5.914,6.52533 Z "/>
                    <GeometryDrawing Brush="#FFEFAE5A" Geometry="F1 M 10.2409,2.86134L 8.66627,3.77067L 11.4449,8.584C 11.9116,8.196 12.4356,7.884 13.0156,7.66666L 10.2409,2.86134 Z "/>
                    <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 25.3333,25.3333L 25.3333,14.6667L 17.3333,14.6667L 17.3333,38.6667L 36,38.6667L 36,25.3333L 25.3333,25.3333 Z "/>
                    <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 28,14.6667L 28,22.6667L 36,22.6667L 28,14.6667 Z "/>
                </DrawingGroup.Children>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>
</ResourceDictionary>

我需要将其显示为菜单项图标。

我尝试了以下方式

 <MenuItem 
                      Header="New" Command="{Binding New}" >
                <MenuItem.Icon >
                    <Image Source="Resources/Icons/NewDocument.xaml"/>
                </MenuItem.Icon>
            </MenuItem>

寻找解决方案。请帮助。

1 个答案:

答案 0 :(得分:1)

            <MenuItem.Icon>
                <Rectangle Fill="{StaticResource NewDocument}" Stretch="Uniform" >
                </Rectangle>
            </MenuItem.Icon>

这将有效