简体   繁体   English

功能区按钮图像编程

[英]Ribbon Button Image Programmatically

I'm trying to load a image onto a Ribbon Button. 我正在尝试将图像加载到功能区按钮上。 This is the System.Windows.Controls.RibbonBar type. 这是System.Windows.Controls.RibbonBar类型。

here is the code I'm using 这是我正在使用的代码

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 类文件创建按钮的路径是MyProject \\ Functions \\ Ribbonbar.cs
Path to the Icon File is MyProject\\Images\\Test\\smallicon.ico 图标文件的路径是MyProject \\ Images \\ Test \\ smallicon.ico

I have tried to figure out the LargeImageSource and just cant understand what I need to do. 我试图找出LargeImageSource并且无法理解我需要做什么。

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: 您需要指定两个图像: LargeImageSourceSmallImageSource ,它们实际上需要不同(一个 - 更大,一个 - 更小),但是对于测试尝试这个:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM