当前位置:   article > 正文

WPF中添加菜单里最前面的图标._wpf中menu可以追加图标

wpf中menu可以追加图标

 <MenuItem Header="_submenuitem1" IsCheckable="true">
            <MenuItem.Icon>
              <Image Source="c:/data/cat.png"/>
            </MenuItem.Icon>
        </MenuItem> 

另一种写法

<Window.Resources>
    <Style x:Key="ImageMenu" TargetType="{x:Type MenuItem}">
      <Setter Property = "Background" Value = "Red"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type MenuItem}">
            <MenuItem>
            <MenuItem.Icon>
              <Image Source="c:/data/cat.png"/>
            </MenuItem.Icon>
            </MenuItem>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Window.Resources>
 
  <Menu Width="40" Margin="10, 10, 5, 5" HorizontalAlignment="Left" Background="White">
    <MenuItem Header="_File">
      <MenuItem Header="_New"  Style="{StaticResource ImageMenu}">
       </MenuItem>
      <MenuItem Header="_Open" IsCheckable="true"/>
      <MenuItem Header="_Close" IsCheckable="true"/>
      <Separator/>
      <MenuItem Header="Menu with Submenu">
        <MenuItem Header="_submenuitem1" IsCheckable="true"/>
        <MenuItem Header="_submenuitem2" IsCheckable="true">
          <MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
        </MenuItem>
      </MenuItem>
      <Separator/>
      <MenuItem Header="_Menu item with ToolTip">
        <MenuItem.ToolTip>
          <ToolTip>
            ToolTip Information.
          </ToolTip>
        </MenuItem.ToolTip>
      </MenuItem>
    </MenuItem>
  </Menu>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/493473
推荐阅读
  

闽ICP备14008679号