C# 如何解决:在网格应用程序中找不到样式中的可附加属性触发器

C# 如何解决:在网格应用程序中找不到样式中的可附加属性触发器,c#,xaml,windows-8,microsoft-metro,datatrigger,C#,Xaml,Windows 8,Microsoft Metro,Datatrigger,我正在Windows8中使用Visual Studio 11。在网格应用程序(Metro)中设置数据触发器会在XAML中显示此错误: 在样式中找不到可附加属性触发器 为什么要给我看这个?在Windows 8 Metro风格的应用程序中触发。我建议您编写一个函数,用默认值替换空值。在Windows 8 Metro风格的应用程序中触发。我建议您编写一个将null值替换为默认值的脚本。您可以使用VisualState而不是object。Windows 8中的触发器代码如下 <Control

我正在Windows8中使用Visual Studio 11。在网格应用程序(Metro)中设置数据触发器会在XAML中显示此错误:

在样式中找不到可附加属性触发器



为什么要给我看这个?

在Windows 8 Metro风格的应用程序中触发。我建议您编写一个函数,用默认值替换空值。

在Windows 8 Metro风格的应用程序中触发。我建议您编写一个将null值替换为默认值的脚本。

您可以使用VisualState而不是object。Windows 8中的触发器代码如下

 <ControlTemplate TargetType="Button">
<VisualStateGroup.Transitions>

  <!--Take one half second to transition to the PointerOver state.-->
  <VisualTransition To="PointerOver" 
                      GeneratedDuration="0:0:0.5"/>
</VisualStateGroup.Transitions>

<VisualState x:Name="Normal" />

<VisualState x:Name="PointerOver">
<Storyboard> 
<ColorAnimation Storyboard.TargetName="ButtonBrush" 
Storyboard.TargetProperty="Color" To="Red" />
 </Storyboard> 
</VisualState> 
</VisualStateGroup>
</VisualStateManager.VisualStateGroups> 
  <Grid.Background>
<SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
 </Grid.Background>
</Grid>
 </ControlTemplate>

您可以使用VisualState而不是object。Windows 8中的触发器代码如下

 <ControlTemplate TargetType="Button">
<VisualStateGroup.Transitions>

  <!--Take one half second to transition to the PointerOver state.-->
  <VisualTransition To="PointerOver" 
                      GeneratedDuration="0:0:0.5"/>
</VisualStateGroup.Transitions>

<VisualState x:Name="Normal" />

<VisualState x:Name="PointerOver">
<Storyboard> 
<ColorAnimation Storyboard.TargetName="ButtonBrush" 
Storyboard.TargetProperty="Color" To="Red" />
 </Storyboard> 
</VisualState> 
</VisualStateGroup>
</VisualStateManager.VisualStateGroups> 
  <Grid.Background>
<SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
 </Grid.Background>
</Grid>
 </ControlTemplate>