2

我试图在屏幕加载时激活一个状态,但它不起作用。我所做的是,我转到屏幕,右键单击 LayoutRoot,然后转到“激活状态”并选择我的状态。然后,当我单击这个新生成的 [ActivateStateAction] 时,我将 EventName 从 MouseLeftButtonDown 更改为 Loaded。但是,它似乎不起作用。MouseLeftButtonDown 有效,但 Loaded 无效。我在多个屏幕(不仅仅是启动屏幕)上尝试了这个,但它仍然不起作用,有什么想法吗?

4

2 回答 2

2

我有同样的问题。

我发现ActivateStateAction Loaded,只在我的第一个屏幕上调用。然后我导航到的其他屏幕上的类似操作没有调用 Loaded 事件。

我将我的 ActivateStateAction 更改为在除第一个屏幕之外的所有屏幕上使用 Layout Updated 操作。当新屏幕更新布局时会触发此事件,现在我的问题已解决。

于 2010-10-13T19:42:13.710 回答
1

我重复了你给出的步骤,它对我有用。你没有提到 SL 或 WPF,所以我在 Silverlight 中尝试了它。也许检查 activatestateaction 的属性以确保目标状态名称是正确的。如果您仍然无法正常工作,请告诉我,我可以尝试帮助您找到问题(发布您的 xaml)。这是我的操作生成的 xaml:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:pb="clr-namespace:Microsoft.Expression.Prototyping.Behavior;assembly=Microsoft.Expression.Prototyping.Interactivity"
x:Class="SilverlightPrototype2Screens.Screen_1"
Width="640" Height="480">

<Grid x:Name="LayoutRoot" Background="White">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <pb:ActivateStateAction TargetScreen="SilverlightPrototype2Screens.Screen_1" TargetState="VisualState"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="VisualState">
                <Storyboard>
                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                        <EasingColorKeyFrame KeyTime="00:00:00" Value="Red"/>
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Rectangle x:Name="rectangle" Fill="White" Stroke="Black" Height="74" HorizontalAlignment="Left" Margin="171,116,0,0" VerticalAlignment="Top" Width="107" RenderTransformOrigin="0.5,0.5">
        <Rectangle.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Rectangle.RenderTransform>
    </Rectangle>
</Grid>

于 2010-02-05T17:36:59.650 回答