gpt4 book ai didi

c# - 未找到 VisualStateGroups?

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:12 26 4
gpt4 key购买 nike

我有一个 ui 控件的 XAML(它继承自一个按钮)并且其中有各种视觉状态组,如下所示:

                            <vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="MouseOver">
</vsm:VisualState>
<vsm:VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Duration="0" To="Green" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Background).(SolidColorBrush.Color)" />
<DoubleAnimation Duration="0" To="0.94" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" />
<DoubleAnimation Duration="0" To="0.94" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" />
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Disabled">
<Storyboard/>
</vsm:VisualState>
</vsm:VisualStateGroup>

<vsm:VisualStateGroup x:Name="MyState">
<vsm:VisualState x:Name="Pressed_Green">
<Storyboard>
<ColorAnimation Duration="0" To="Yellow" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Background).(SolidColorBrush.Color)" />
<DoubleAnimation Duration="0" To="0.94" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" />
<DoubleAnimation Duration="0" To="0.94" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>




</vsm:VisualStateManager.VisualStateGroups>

在 onapplytemplte 函数的代码隐藏中,我尝试:

VisualStateManager.GetVisualStateGroups(this).Count

但是返回值是'0',不应该是2吗?

最佳答案

VisualStateManager.VisualStateGroups在控件的控件模板中的根元素上设置(即 this),而不是在控件本身上。您需要为您的根元素提供一个 x:Name,然后使用 GetTemplateChild 访问它.

关于c# - 未找到 VisualStateGroups?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5891157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com