Vector icons in WPF menu items?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Veeneman

    #1

    Vector icons in WPF menu items?

    I'm just getting started with WPF and XAML, and I am trying to create a
    traditional menu bar. Everything works until I get to the menu icons. I can
    add a bitmap icon to a menu item using this XAML markup:

    <MenuItem Header = "Log In">
    <MenuItem.Ico n>
    <Image Source="Resourc es\LogIn.png" />
    </MenuItem.Icon>
    </MenuItem>

    However, I want to use vector graphics, rather than bitmaps, for menu icons.
    So, I try this markup:

    <MenuItem Header = "Log In">
    <MenuItem.Ico n>
    <Image Source="Resourc es\LogIn.xaml" />
    </MenuItem.Icon>
    </MenuItem>

    I'm getting a design-time error saying that "No imaging component suitable
    to complete this operation was found".

    What's going on, and what do I need to do to be able to use a XAML
    vector-graphic file as a menu item icon? Thanks for your help!

    David Veeneman
    Foresight Systems


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Vector icons in WPF menu items?

    David,

    I don't believe you can use an Image tag here, because the Image will
    expect something in an image format.

    Rather, you could place the markup for the vector right in the Icon
    property. Either that, or set it as a static resource somewhere in your
    project, and then set the Icon to that static resource.

    You might be able to use a Frame as well, like so:

    <MenuItem Header = "Log In">
    <MenuItem.Ico n>
    <Frame Source="Resourc es\LogIn.xaml">
    </MenuItem.Icon>
    </MenuItem>


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "David Veeneman" <davidv@nospam. comwrote in message
    news:OYWvGG2QIH A.5400@TK2MSFTN GP04.phx.gbl...
    I'm just getting started with WPF and XAML, and I am trying to create a
    traditional menu bar. Everything works until I get to the menu icons. I
    can add a bitmap icon to a menu item using this XAML markup:
    >
    <MenuItem Header = "Log In">
    <MenuItem.Ico n>
    <Image Source="Resourc es\LogIn.png" />
    </MenuItem.Icon>
    </MenuItem>
    >
    However, I want to use vector graphics, rather than bitmaps, for menu
    icons. So, I try this markup:
    >
    <MenuItem Header = "Log In">
    <MenuItem.Ico n>
    <Image Source="Resourc es\LogIn.xaml" />
    </MenuItem.Icon>
    </MenuItem>
    >
    I'm getting a design-time error saying that "No imaging component suitable
    to complete this operation was found".
    >
    What's going on, and what do I need to do to be able to use a XAML
    vector-graphic file as a menu item icon? Thanks for your help!
    >
    David Veeneman
    Foresight Systems
    >

    Comment

    • David Veeneman

      #3
      Re: Vector icons in WPF menu items?

      Thank you, Nicholas! That is exactly what I needed.


      Comment

      Working...