设置菜单项的图标属性值,使用XAML中的样式为shape . path



我使用Silverlight 4和Expression Blend 4。

我正在样式化一个菜单项,路径为图标。

<Style x:Key="1234" TargetType="Controls:MenuItem">
        <Setter Property="Header" Value="Cancel" />
        <Setter Property="Icon">
            <Setter.Value>
                <Path Fill="#FF2B2B2B"
                      Width="14.3775"
                      Height="14"
                      Canvas.Left="0.311264"
                      Canvas.Top="0.500005"
                      Stretch="Fill"
                      Data="F1 M 111.2,-85.6L 124.2,-85.6L 124.2,-72.6L 111.2,-72.6L 111.2,-85.6 Z M 117.791,-82.3439L 117.791,-80.4506L 112.685,-80.4506L 112.685,-77.8084L 117.791,-77.8084L 117.791,-75.8748L 121.025,-79.1094L 117.791,-82.3439 Z M 121.657,-84.0222L 121.657,-74.0222L 122.657,-74.0222L 122.657,-84.0222L 121.657,-84.0222 Z " />
            </Setter.Value>
        </Setter>
    </Style>

但是当我试图打开这个时,这给出了一个异常表达式blend。

异常消息:从调用COM组件返回Error HRESULT E_FAIL在MS.Internal.XcpImports。MethodEx(IntPtr ptr, String name, CValue[] cdData)

这也给出了异常在运行时,当我添加这个样式到一个ContextMenu的项目。

将样式放入控件模板:

<ControlTemplate x:Key="CancelIcon">
      <Canvas>
        <Path Fill="#FF2B2B2B"
                          Width="14.3775"
                          Height="14"
                          Canvas.Left="0.311264"
                          Canvas.Top="0.500005"
                          Stretch="Fill"
                          Data="F1 M 111.2,-85.6L 124.2,-85.6L 124.2,-72.6L 111.2,-72.6L 111.2,-85.6 Z M 117.791,-82.3439L 117.791,-80.4506L 112.685,-80.4506L 112.685,-77.8084L 117.791,-77.8084L 117.791,-75.8748L 121.025,-79.1094L 117.791,-82.3439 Z M 121.657,-84.0222L 121.657,-74.0222L 122.657,-74.0222L 122.657,-84.0222L 121.657,-84.0222 Z " />
      </Canvas>
    </ControlTemplate>

对于菜单,尝试下面的

<MenuItem Header="Cancel" >
  <MenuItem.Icon>
    <ContentControl Template="{StaticResource CancelIcon}" />
  </MenuItem.Icon>
</MenuItem>

希望这能解决:-)

相关内容

  • 没有找到相关文章

最新更新