【问题标题】:WPF - Custom Pie Menu - MenuItem ImageWPF - 自定义饼图菜单 - MenuItem Image
【发布时间】:2015-08-03 14:48:20
【问题描述】:

有人可以帮我,为本教程的每个 MenuItem 添加图像:

http://www.codeproject.com/Articles/522343/A-Pie-Menu-for-WPF

我不知道该怎么做。

【问题讨论】:

    标签: c# wpf menu


    【解决方案1】:

    试试这个:

    </MyNamespace:PieMenu.BitmapEffect>
      <Image Source="Items\1.png" Width="50" Height="50"/>
      <Image Source="Items\2.png" Width="50" Height="50"/>
      <Image Source="Items\3.png" Width="50" Height="50"/>
      <Image Source="Items\4.png" Width="50" Height="50"/>
      <Image Source="Items\5.png" Width="50" Height="50"/>
    </MyNamespace:PieMenu>
    

    【讨论】:

    • 不......不幸的是,这不起作用。编译器说,“BitmapEffect”属性不支持“Image”。
    【解决方案2】:

    我有类似的问题。我最终玩了 PieMenuItem 的 header 属性。这样的事情会奏效。

        if (menu_item.Header as FrameworkElement != null)
        {
            FrameworkElement header = (FrameworkElement)menu_item.Header;
    
            // Create the visual brush based on the UserControl
            VisualBrush headerVisualBrush = new VisualBrush(header);
            headerVisualBrush.Stretch = Stretch.Uniform;
    
            // Draw using the visual brush in the rect
            double contentSize = distance / 2;
            drawingContext.DrawRectangle(headerVisualBrush, null, new Rect(center.X - contentSize / 2.0, center.Y - contentSize / 2.0, contentSize, contentSize));
      }
      else if (menu_item.Header as String != null)
      {
    
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多