如何将自定义图像添加到功能区设计 [英] How do add custom images to ribbon design

查看:97
本文介绍了如何将自定义图像添加到功能区设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以告诉我如何在功能区设计中添加自定义图像作为切换按钮吗?

Hello, can anyone tell me how can I add a custom image as a toggle button in ribbon design?

我已经尝试过了:

< toggleButton id =" toggleButton1"   size =大" onAction =" toggleButton1_Click" label ="Abrir ExcelAmpla"; image ="ampla-vertical16x16.PNG"/>

<toggleButton id="toggleButton1"  size="large" onAction="toggleButton1_Click" label="Abrir ExcelAmpla" image="ampla-vertical16x16.PNG"/>

但是插件不会加载图像.

But the add in doesn't load the image.

 

 

 


推荐答案

像这样将background属性设置为图像画笔.

Set the background property to an image brush like so.

 


    public void SetBackground(Image image)
    {
      var brush = new ImageBrush(ConvertToControlImage(image));
      brush.Stretch = Stretch.Uniform;
      Background = brush;
    }
private ImageSource ConvertToControlImage(Image image)
    {
      var ms = new MemoryStream(); // no using here! BitmapImage will dispose the stream after loading
      image.Save(ms, ImageFormat.Bmp);
      ms.Position = 0;
      var imageSource = new BitmapImage();
      imageSource.BeginInit();
      imageSource.CacheOption = BitmapCacheOption.OnLoad;
      imageSource.StreamSource = ms;
      imageSource.EndInit();
      return imageSource;
    }


 public Image GetNextImage()
    {
      if (_imageInformations.Count == 0) return null;
      if (++_imageCounter >= _imageInformations.Count) _imageCounter = 0;
      return Bitmap.FromFile(_imageInformations[_imageCounter].FullName);
    }


这篇关于如何将自定义图像添加到功能区设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆