开发者

Cannot assign to property System.Windows.EventTrigger.RoutedEvent in Silverlight 4

开发者 https://www.devze.com 2023-01-31 23:06 出处:网络
The exception shown above is thrown on this XAML for a Silverlight 4 application: <UserControl xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"

The exception shown above is thrown on this XAML for a Silverlight 4 application:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="NewtonsCradle.MainPage"
    Width="640" Height="480">
    <StackPanel Orientation="Horiontal">
        <TextBlock Height="100" Name="TestText">Test</TextBlock>
        <StackPanel.Triggers>
            <EventTrigger RoutedEvent="Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="TestText" 
        开发者_运维问答                                 Storyboard.TargetProperty="Height" 
                                         To="500"
                                         Duration="0:0:1"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </StackPanel.Triggers>
    </StackPanel>

</UserControl>

The code behind:

    using System.Windows.Controls;

namespace NewtonsCradle
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();

        }
    }
}

What's up? It seems perfectly reasonable code to me, coming from a WPF background.


I guess no one has answered this question but to fix the error use

You need to actually put your event triggers within the control you are animating and also specify the full path to the event instead of "Loaded" use Border.Load

 <Border.Triggers>
                    <EventTrigger RoutedEvent="Border.Loaded">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Height"  From="0" To="Auto" Duration="0:0:1" Storyboard.TargetName="Border1"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
</Border.Triggers>
0

精彩评论

暂无评论...
验证码 换一张
取 消