VisualStateManager 不执行任何操作 (silverlight)

发布于 2024-09-27 17:40:11 字数 2858 浏览 1 评论 0原文

我正在使用 studio 2010 和 silverlight 4 构建自定义控件。 我正在尝试使用视觉状态管理器。

使用以下 xml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:SilverView">
    <Style TargetType="controls:ScaleImage">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ScaleImage">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="MouseOver"
                                                      GeneratedDuration="0:0:.5"/>
                                    <VisualTransition To="Normal"
                                                      GeneratedDuration="0:0:.5"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <DoubleAnimation
                                        Storyboard.TargetName="img"
                                        Storyboard.TargetProperty="Width"
                                        From="50" To="100"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation
                                        Storyboard.TargetName="img"
                                        Storyboard.TargetProperty="Width"
                                        From="50" To="100"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image Name="img" Width="50">
                            <Image.RenderTransform>
                                <ScaleTransform x:Name="scale"/>
                            </Image.RenderTransform>
                        </Image>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

当我将鼠标悬停在图像上时,没有任何反应。 当鼠标悬停在图像上时如何放大图像?

谢谢

I am building a custom control using studio 2010 and silverlight 4.
I am trying to use the visual state manager.

With the following xml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:SilverView">
    <Style TargetType="controls:ScaleImage">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ScaleImage">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="MouseOver"
                                                      GeneratedDuration="0:0:.5"/>
                                    <VisualTransition To="Normal"
                                                      GeneratedDuration="0:0:.5"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <DoubleAnimation
                                        Storyboard.TargetName="img"
                                        Storyboard.TargetProperty="Width"
                                        From="50" To="100"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation
                                        Storyboard.TargetName="img"
                                        Storyboard.TargetProperty="Width"
                                        From="50" To="100"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image Name="img" Width="50">
                            <Image.RenderTransform>
                                <ScaleTransform x:Name="scale"/>
                            </Image.RenderTransform>
                        </Image>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Nothing happens when I mouse over the image.
How do I get the image to enlarge when the mouse is over it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这个俗人 2024-10-04 17:40:11

VisualStateManager.VisualStateGroups 附加属性定义视觉状态集,但是组的名称和状态的名称只是名称,它们实际上并不启用它们自动描述的功能。

由控件中的代码决定何时处于特定状态,然后将该选择通知 VisualStateManager。您可以使用如下代码来完成此操作:-

VisualStateManager.GotoState(this, "MouseOver", true);

通常,您会通过各种控件事件收集诸如鼠标是否位于控件上方之类的信息,并使用一个中央 UpdateVisualState 函数来设置所有适当的状态。

The VisualStateManager.VisualStateGroups attached property defines the set of visual states however the names of the groups and the names of the states are just names, they do not actually enable the functionality they describe automatically.

It's up to code in your control to decide when it is in a specific state and then inform the VisualStateManager of that choice. You do that with code like this:-

VisualStateManager.GotoState(this, "MouseOver", true);

Typically you would collect information like whether the mouse is over the control via the various control events and have a central UpdateVisualState function that sets all the appropriate states.

好菇凉咱不稀罕他 2024-10-04 17:40:11

在上面的 XAML 中,您仅定义状态组和具有“MouseOver”等名称的状态。您实际上并没有导致状态发生变化,因为它们显然与任何事件都没有关联。

如果您还没有这样做,请尝试使用 GoToState 行为来触发控件的状态更改。

您还有更多可以触发状态更改的代码或 XML 吗?

In the XAML above you are only defining state groups and states with names like "MouseOver". You are not actually causing the state to change, as they are apparently not connected to any events.

If you are not already, try using GoToState behaviours to trigger the state changes of your control.

Do you have any more code or XML that triggers a state change?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文