我有使用VisualStateManger的按钮样式。目前这些样式位于<Grid.Resources>
并且没有任何错误。我试图将这些样式移动到资源字典,它给出了以下错误。任何人都知道为什么它在样式处于用户控制内部时工作,而在移动到资源字典时不起作用。
标签&#39; visualstatemanager.visualstategroups&#39;在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>
答案 0 :(得分:2)
问题是你正在尝试使用未引用的程序集中的内容。你需要在根目录的Window / Page标签中添加它,其他名称空间为
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>