如何在Silverlight 4中从login.xaml调用mainpage.xaml中的动画 [英] how to call an animation in mainpage.xaml from login.xaml in silverlight 4

查看:74
本文介绍了如何在Silverlight 4中从login.xaml调用mainpage.xaml中的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用表情Blend 4.0创建Silverlight应用程序.我有mainpage.xaml,并已赋予用户控件(loginpage.xaml).然后,在用户控件中有登录按钮(loginpage.xaml).我还在mainpage.xaml上准备了动画,以便当用户单击登录按钮时,动画就开始了.我不知道应该在登录按钮中给出什么命令,以便动画在用户单击时开始播放.还是您想提出另一个建议?任何帮助对我都会非常有帮助.谢谢.我正在使用xaml和c#.

I am making a Silverlight Application using expression Blend 4.0. I have mainpage.xaml and I've given the user control (loginpage.xaml) on it. Then I have the login button in user control (loginpage.xaml). I have prepared the animation also on the mainpage.xaml, so that when the user click the login button, then the animation is started. I have no idea what should the command I give in the login button so that the animation will start when the user click it. or would you like to give another suggestion? Any helps would be very helpful for me. Thanks. I am using xaml and c#.

推荐答案

这是一个不错的方法:

您的视图可能与此类似(请注意,将数据上下文装饰性地设置为您的视图模型,并将其上的Storyboard属性设置为静态资源Storyboard):

Your view could resemble this (notice the data context being decoratively set to your view model and the storyboard property on it being set to the static resource storyboard):

<UserControl x:Class="SilverlightApplication2.MainPage"
         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"
         xmlns:local="clr-namespace:SilverlightApplication2"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
    <Storyboard x:Name="MyStoryboard">
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="firstGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
            <EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>
<UserControl.DataContext>
    <local:My_ViewModel MyStoryboard="{StaticResource MyStoryboard}" />
</UserControl.DataContext>
<Grid x:Name="LayoutRoot" Background="White">
    <StackPanel>
    <Grid x:Name="firstGrid" Height="100" Width="100" Background="Red" />
    <Button x:Name="firstButton" Content="Click Me" Click="firstButton_Click" Height="100" Width="100" />
    </StackPanel>
</Grid>

您的视图模型将类似于此:

Your view model would resemble this:

    public class My_ViewModel
{
    public Storyboard MyStoryboard { get; set; }
}

在视图的代码背后,您可能会遇到类似这样的事情:

And in the code-behind of your view you could have something like this:

    public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
    }

    private My_ViewModel _viewModel
    {
        get { return this.DataContext as My_ViewModel; }
    }

    private void firstButton_Click(object sender, RoutedEventArgs e)
    {
        this._viewModel.MyStoryboard.Begin();
    }
}

希望这会有所帮助!

这篇关于如何在Silverlight 4中从login.xaml调用mainpage.xaml中的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆