小编Ric*_*d E的帖子

在VisualState Storyboard中使用绑定

我正在为WPF应用程序编写自定义控件.我想StoryboardVisualState定义中使用颜色动画.该To动画的属性应绑定到我的控件对象的依赖项属性.这似乎不起作用.

我在Silverlight论坛中找到了一个线程,描述了完全相同的问题,声称这可以在SL4 RTM中运行:http://forums.silverlight.net/forums/p/174655/423324.aspx.但是,当我尝试使用我的VS2010 WPF应用程序中发布的代码时,它不起作用,这意味着颜色不会改变.我能在a内完成的唯一约束VisualState StoryboardStaticResource.

有任何想法吗?

编辑:

添加了代码段:

来自Generic.xaml:

<Style TargetType="{x:Type local:TestCustomControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:TestCustomControl}">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Name="MyBorder">
                    <Border.Background>
                        <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ColdColor}" />
                    </Border.Background>

                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <!-- This works: -->
                                    <!--<ColorAnimation Storyboard.TargetProperty="Background.Color" Storyboard.TargetName="MyBorder" To="Red"  Duration="0:0:0.2"/>-->

                                    <!-- This also works: --> 
                                    <!--<ColorAnimation Storyboard.TargetProperty="Background.Color" Storyboard.TargetName="MyBorder" To="{StaticResource HotColorRes}"  Duration="0:0:0.2"/>-->

                                    <!-- This doesn't work: -->
                                    <ColorAnimation …
Run Code Online (Sandbox Code Playgroud)

wpf binding visualstatemanager storyboard

5
推荐指数
1
解决办法
2062
查看次数

在WPF中设置初始VisualState

在WPF中使用VisualStateManager时,可能需要在控件初始化时转换为VisualState。据我所知,没有办法在Xaml中声明初始状态,这给了您有限的选择权,可以在初始化后将代码转换为所需的状态。

在后面使用代码并非总是可取的,如果您使用绑定来控制VisualState,那么也不总是可能的。

所以问题是:如何在WPF中设置初始VisualState,而不在后面的代码中进行设置?

wpf visualstatemanager

5
推荐指数
1
解决办法
3838
查看次数

标签 统计

visualstatemanager ×2

wpf ×2

binding ×1

storyboard ×1