Лента XAML и смена нескольких изображений - PullRequest
0 голосов
/ 20 мая 2019

У меня есть VSTO Addin с пользовательской лентой, и я создаю раскрывающийся список, в котором я хочу использовать графический элемент для представления флажка для 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 - переменная класса, которая управляет состоянием.

Спасибо за понимание.

...