我正在尝试将图像加载到功能区按钮上。这是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并且无法理解我需要做什么。
答案 0 :(得分: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;
}