Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7729643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:01:03+00:00 2026-06-01T06:01:03+00:00

I need to convert my WPF application, which has a Ribbon , to use

  • 0

I need to convert my WPF application, which has a Ribbon, to use vector graphics for the images on buttons, etc., instead of bitmaps. I’ve got this working so far, except for the RibbonApplicationMenu items, which use their RibbonApplicationMenu.ImageSource property, with type ImageSource to set the graphic that shows up at the left side of the ribbon menu item.

My vector graphics are defined like this in XAML:

<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ViewBox Width="148.854" Height="150.500">
        <Canvas Width="148.854" Height="150.500">
            <Path>
            <!-- . . . yadda yadda yadda . . . -->
            </Path>
        </Canvas>
    <Viewbox>
</ControlTemplate>

These render properly when I set them to be the .Template of a Button, etc.

I can’t figure out, however, how to use them for the images that show up in the RibbonApplicationMenu controls. Just setting the .Template property of the RibbonApplicationMenu does not work (it fills the entire control seems to break its functionality).

I attempted to use a VisualBrush and then render it to a RenderTargetBitmap to use as the .ImageSource (I also have to work mostly in code behind for reasons I won’t get into):

ContentControl cc = new ContentControl(); // just picked ContentControl as a test
cc.Template = myTemplate; // assume myTemplate has the proper ControlTemplate
VisualBrush visBrush = new VisualBrush();
visBrush.Visual = cc;
// not really sure about the parameters to this next line 
RenderTargetBitmap rend = 
    new RenderTargetBitmap(148.854, 150.5, 120, 96, PixelFormats.Pbgra32);
rend.Render(cc);
RibbonApplicationMenuItem menu = new RibbonApplicationMenuItem();
menu.ImageSource = render;

This compiles, but just shows a blank where the image would go. If I instead use a BitmapImage loaded from an image file as the .ImageSource, it displays correctly.

Any ideas how I can get this to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:01:04+00:00Added an answer on June 1, 2026 at 6:01 am

    Two things that might need to be done:
    Firstly there is no explicit size set for the Canvas in the ControlTemplate, you’ll need to assign it a width and height (see the upvoted answer here for details).
    The other thing is that you need to Arrange and Measure the Viewbox so that it assumes the required dimensions.

    So altering the xaml for the vector graphics to something like:

    <ControlTemplate x:Key="Template">
        <Viewbox>
            <Canvas Height="100" Width="130">
                <Path>
                    <!-- data -->
                </Path>
            </Canvas>
        </Viewbox>
    </ControlTemplate>
    

    And the code to:

    ControlTemplate controlTemplate = 
        FindResource("Template") as ControlTemplate; 
    
    ContentControl content = new ContentControl();
    content.Template = controlTemplate;
    
    // ensure control has dimensions
    content.Measure(new Size(200, 200));
    content.Arrange(new Rect(0, 0, 200, 200));
    
    RenderTargetBitmap render =
        new RenderTargetBitmap((int)content.ActualWidth, (int)content.ActualHeight, 120, 96, PixelFormats.Pbgra32);
    
    render.Render(content);
    
    RibbonApplicationMenuItem menu = new RibbonApplicationMenuItem();
    menu.ImageSource = render;
    

    Will hopefully get it working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a WPF application in which I need to display document previews such
I need to convert a value which is in a DateTime variable into a
I have a WPF application and I use external library for generating documents. This
I'm looking for some simple clip art to use in a WPF application. I'd
I have a Silverlight control i need to convert to WPF (Yes, i know
I need to convert a Silverlight App to WPF (to finally run it on
I need to convert a GDI Font in a WPF Font. myGdiFont As System.Drawing.Font
I will need to convert the following VB Form code to WPF C# :
I have a complex Dot in WPF which I need to customize the diameter.
To implement a tab-based environment in WPF we need to convert our forms to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.