我有一个可能看起来相对简单的问题,但在同一方面,我仍然是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 State,我知道对于这个简单的任务来说,这可能有点夸张,但我必须从某个地方开始,并认为这将是足够简单的。
(如果需要澄清,请告诉我)
发布于 2013-06-04 05:00:54
试一试
VisualStateManager.GoToElementState而不是
VisualStateManager.GoToState发布于 2013-06-04 04:46:40
我注意到你没有设置Storyboard.TargetName
尝试将其设置为适当的控件名称。
编辑:
我想我现在明白了。您的颜色动画的目标属性:不是将其设置为“前景”,而是将其更改为“颜色”。如果这样做,您必须将目标控件从MenuItem更改为MenuItem的背景画笔。
或者,您可以保持原样,并将ColorAnimation中的目标属性更改为Foreground.SolidColorBrush.Color。
下面是设置ColorAnimation的an example属性的目标。
https://stackoverflow.com/questions/16905411
复制相似问题