1

我正在尝试将图像加载到功能区按钮上。这是 System.Windows.Controls.RibbonBar 类型。

这是我正在使用的代码

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

我不知道如何添加图标。我可以毫无问题地添加没有图像的按钮

类文件创建按钮的路径是MyProject\Functions\Ribbonbar.cs
图标文件的路径是MyProject\Images\Test\smallicon.ico

我试图弄清楚 LargeImageSource 并且无法理解我需要做什么。

4

1 回答 1

3

您需要指定两个图像:LargeImageSource并且SmallImageSource,它们实际上需要不同(一个更大,一个更小),但为了测试,试试这个:

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;
}
于 2013-12-22T02:39:04.227 回答