我有一个看似相对简单的问题,但在同一张纸条上,我对 WPF 仍然相对陌生,所以请客气。我的问题很简单,我在上下文菜单中的 MenuItems 上有一个 VisualStateManager,我想处理更改前景色。这是我的尝试
           **WPF PORTION**
           <VisualStateManager.VisualStateGroups>
              <VisualStateGroup Name="ExcelVisualState">
                <VisualState Name="XLSXNormal">
                  <Storyboard>
                    <ColorAnimation Storyboard.TargetProperty="Foreground" To="#FF003471" Duration="00:00:00.0010000" />
                  </Storyboard>
                </VisualState>
                <VisualState Name="XLSXDisabled">
                  <Storyboard>
                    <ColorAnimation Storyboard.TargetProperty="Foreground" To="#A99B9A71" Duration="00:00:00.0010000" />
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            **C# Code**
            //Fires when the isEnabled method changes for my menu item
            private void MenuItem_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
               //If MS Excel is installed set the visual state to XLSXNormal
               if (miExportXLSX.IsEnabled)
                  VisualStateManager.GoToState(miExportXLSX, "XLSXNormal", true);
               //MS Excel is not installed so set the state to XLSXDisabled
               else
                  VisualStateManager.GoToState(miExportXLSX, "XLSXDisabled", true);
            }
我是在正确的轨道上,还是偏离了轨道?这是我第一次尝试使用视觉状态,我知道这对于这个简单的任务来说可能有点矫枉过正,但我必须从某个地方开始,并认为这很容易。
(如果需要任何澄清,请告诉我)