XAML功能区和更改多个图像

时间:2019-05-20 17:16:06

标签: c# ribbon-control

我有一个带有自定义功能区的VSTO插件,我正在创建一个下拉菜单,我想在其中使用图形表示下拉菜单中3个菜单项的复选框。自然,我有两个图形,一个是选中的,另一个是未选中的。

我使用名为QueryPreference的变量来管理代码中已检查内容的状态。

我正在努力的是,当选择了一个选项时,如何将其他两个菜单选项设置为“关闭”图形?

我正在使用GetAction设置状态,并使用GetImage设置图像。 GetImage并没有真正做很多事情,因为它是我尝试解决这一问题的起点。我一直撞墙。

如何用GetImage或其他方式设置其他控件的图形?

这里是我的XAML,

<menu id="queryPreference" label ="Query Preference"  getImage="GetImage" getEnabled="GetEnabled" supertip="Determines how much Shape data is queried.">
            <button id="Low" label ="Low" onAction="OnQueryPreferenceAction" getImage="GetQueryPreferenceImage" supertip="Only component name and description are queried and available in shape data. Select this option for fastest drawing time."/>
            <button id="Medium" label ="Medium" onAction="OnQueryPreferenceAction" getImage="GetQueryPreferenceImage" supertip="Only native component properties are queried. Calculated properties are not initially available in shape data."/>
            <button id="High" label ="High" onAction="OnQueryPreferenceAction" getImage="GetQueryPreferenceImage" supertip="All component properties are queried and available in shape data, including calculated properties."/>
          </menu>

这是我的GetAction和GetImage,

public Bitmap GetQueryPreferenceImage(Office.IRibbonControl control)
        {
            var image = Properties.Resources.checkbox_off;
            if (QueryPreference.Equals(VisioQueryPreferenceAction.Low, StringComparison.OrdinalIgnoreCase))
            {
                image = Properties.Resources.checkbox_on;
            }
            else if (QueryPreference.Equals(VisioQueryPreferenceAction.Medium, StringComparison.OrdinalIgnoreCase))
            {
                image = Properties.Resources.checkbox_on;
            }
            else if (QueryPreference.Equals(VisioQueryPreferenceAction.High, StringComparison.OrdinalIgnoreCase))
            {
                image = Properties.Resources.checkbox_on;
            }

            _ribbon.InvalidateControl(VisioQueryPreferenceAction.Low);

            return image;
        }

        public void OnQueryPreferenceAction(Office.IRibbonControl control)
        {
            var document = Globals.ThisAddIn.Application.ActiveDocument;
            document.SetQueryPreferenceProperty(control.Id);

            if (control.Id.Equals(VisioQueryPreferenceAction.Low, StringComparison.OrdinalIgnoreCase))
            {
                QueryPreference = VisioQueryPreferenceAction.Low;
            }
            else if (control.Id.Equals(VisioQueryPreferenceAction.Medium, StringComparison.OrdinalIgnoreCase))
            {
                QueryPreference = VisioQueryPreferenceAction.Medium;
            }
            else if (control.Id.Equals(VisioQueryPreferenceAction.High, StringComparison.OrdinalIgnoreCase))
            {
                QueryPreference = VisioQueryPreferenceAction.High;
            }

            _ribbon.InvalidateControl(control.Id);
        }

QueryPreference是管理状态的类变量。

感谢您的见识。

0 个答案:

没有答案