Home > DeveloperSection > Forums > Ribbon Button Image Programtically
Ashish Pandey

Total Post:128

Points:898
Posted on    December-23-2013 2:26 AM

 C# C# 
Ratings:


 1 Reply(s)
 694  View(s)
Rate this:

I'm trying to load a image onto a Ribbon Button. This is the System.Windows.Controls.RibbonBar type.

here is the code:

public RibbonGroup CreateButtons()

{

    RibbonGroup GroupControlComputers = new RibbonGroup();

    GroupControlComputers.Header = "Computer Control";

    GroupControlComputers.Items.Add(DropdownButton("DropDown Stuffs"));

    return GroupControlComputers;    

}

public RibbonButton DropdownButton(String Caption)

{

    RibbonButton NewRibbonButton = new RibbonButton();

    NewRibbonButton.Label = Caption;

    NewRibbonButton.AllowDrop = true;

    return NewRibbonButton;

}

I cant figure out how to add a icon. i can add the button without an image with no problems

Path to class file creating button is MyProject\Functions\Ribbonbar.cs

Path to the Icon File is MyProject\Images\Test\smallicon.ico


I have tried to figure out the LargeImageSource and just cant understand what I need to do.

Any help would be appreciated



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-23-2013 5:00 AM

Hi Ashish,

There are two images which you need to specify: 

LargeImageSource and SmallImageSource, they actually need to be different (one - larger and one - smaller), but for test try this:

public RibbonButton DropdownButton(String Caption)

{

    RibbonButton NewRibbonButton = new RibbonButton();

    NewRibbonButton.Label = Caption;

    BitmapImage image = new BitmapImage();

    image.BeginInit();

    // your path to image might be different

    image.UriSource = new Uri("pack://application:,,,/Images/Test/smallicon.ico");

    image.EndInit();

    NewRibbonButton.SmallImageSource = image;

    NewRibbonButton.LargeImageSource = image;

    NewRibbonButton.AllowDrop = true;

    return NewRibbonButton;

}


Don't want to miss updates? Please click the below button!

Follow MindStick