比較的単純な質問のように思えるかもしれませんが、同じことで、私はまだ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 を使用するのはこれが初めての試みです。この単純なタスクには少しやり過ぎかもしれませんが、どこかから始めなければならず、これは十分に簡単だと思いました。
(説明が必要な場合はお知らせください)