首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法向资源字典添加带有VisualStateManger.VisualStateGroup的按钮样式

无法向资源字典添加带有VisualStateManger.VisualStateGroup的按钮样式
EN

Stack Overflow用户
提问于 2014-03-19 16:43:51
回答 1查看 1.2K关注 0票数 0

我有使用VisualStateManger的按钮样式。目前,这些样式在<Grid.Resources>中运行,没有任何错误。我试图将这些样式移到资源字典中,它会产生以下错误。任何人都知道,当样式在用户控件中,而在移动到资源字典时,它为什么会工作。

在XML命名空间http://schemas.microsoft.com/winfx/2006/xaml/presentation中不存在标记‘http://schemas.microsoft.com/winfx/2006/xaml/presentation

我用的是.Net 3.5

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-19 16:50:53

问题是,您正在尝试使用程序集中没有引用的内容。您需要将其添加到根的窗口/页标记中,其他名称空间如下

代码语言:javascript
复制
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"

然后你就可以把它当作

代码语言:javascript
复制
<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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22512615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档