1

比較的単純な質問のように思えるかもしれませんが、同じことで、私はまだ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);
            }

私はここで正しい軌道に乗っていますか、それともコースから外れていますか? Visual States を使用するのはこれが初めての試みです。この単純なタスクには少しやり過ぎかもしれませんが、どこかから始めなければならず、これは十分に簡単だと思いました。

(説明が必要な場合はお知らせください)

4

2 に答える 2

1

設定していないことに気づきましたStoryboard.TargetName

これを適切なコントロール名に設定してみてください。

編集:

今は見えると思います。カラー アニメーションのターゲット プロパティ: 「フォアグラウンド」に設定する代わりに、「カラー」に変更します。これを行う場合、ターゲット コントロールを MenuItem から MenuItem の背景ブラシに変更する必要があります。

または、そのままにして、ターゲット プロパティをColorAnimationtoに変更することもできますForeground.SolidColorBrush.Color

の target プロパティを設定する例を次に示しColorAnimationます。

于 2013-06-03T20:46:40.283 に答える