2014-03-19 96 views
0

我有使用VisualStateManger的按钮样式。目前这些款式在<Grid.Resources>并且没有任何错误地工作。我试图将这些样式移动到资源字典中,并提供以下错误。任何人都知道为什么它在样式处于用户控制内时工作而在移动到资源字典时不工作。无法将按钮样式与VisualStateManger.VisualStateGroup添加到资源字典

标签 'visualstatemanager.visualstategroups' 不存在XML命名空间 http://schemas.microsoft.com/winfx/2006/xaml/presentation

我使用.net 3.5

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=wpftoolkit" 
    xmlns:system="clr-namespace:System;assembly=mscorlib" 
    > 
    <Style x:Key="Home" BasedOn="{StaticResource PagingButton}" TargetType="{x:Type Button}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType='Button'> 
        <Border Name='border' Background='{StaticResource HomeButtonBackground}' CornerRadius='5,5,0,0'> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal" > 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background)" Storyboard.TargetName="border"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonBackground}"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Pressed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background)" Storyboard.TargetName="border"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonBackgroundPressed}"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style>  
</ResourceDictionary> 
+2

请发表您的资源字典XAML – GazTheDestroyer

+0

这是编译错误或设计师只有错误? –

+0

@RohitVats它的运行时错误 – Sampath

回答

2

问题是你想使用的东西来自未被引用的组件。你需要在与其他名称空间的根补充说,在Window /页标签作为

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" 

然后你可以使用它作为

<vsm:VisualStateManager.VisualStateGroups> 
    <vsm:VisualStateGroup x:Name="CommonStates"> 
    <vsm:VisualState x:Name="MouseOver"> 
     <Storyboard> 
     <ColorAnimation Storyboard.TargetName="tickBox" 
      Storyboard.TargetProperty="(Rectangle.Fill). 
           (SolidColorBrush.Color)" 
      To="PaleGreen" Duration="0:0:0.5" /> 
     </Storyboard> 
    </vsm:VisualState> 
    </vsm:VisualStateGroup> 
</vsm:VisualStateManager.VisualStateGroups> 
+0

谢谢..它的工作.. – Sampath