首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改ContentTemplate时的动画

更改ContentTemplate时的动画
EN

Stack Overflow用户
提问于 2011-09-23 14:37:06
回答 2查看 648关注 0票数 0

我有一个窗口,随着时间的推移,不同的控件必须显示出来。我通过使用mvvm模式搜索了一个解决方案,最终得到了以下结果

代码语言:javascript
复制
<ContentControl Content="{Binding}">
        <ContentControl.Style>
            <Style TargetType="ContentControl">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ViewType}" Value="RecipeList">
                        <Setter Property="ContentTemplate" Value="{StaticResource RecipeTemplate}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ViewType}" Value="Default">
                        <Setter Property="ContentTemplate" Value="{StaticResource DefaultTemplate}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
</ContentControl>

到目前为止,这还不错,但我对两件事很好奇:

有一种更好的使用

  1. is的方法,我可以为新的数据板中的项目执行一个动画,即将成为shown?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-23 15:07:23

关于问题2:

您可以在模板中的控件中使用EventTrigger启动动画,如下所示:

代码语言:javascript
复制
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Triggers>
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard>
                    <Storyboard x:Name="SomeStoryBoard"/>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
    </Grid>
</Window>
票数 1
EN

Stack Overflow用户

发布于 2011-09-23 14:57:07

由于动画是特定于视图的操作,所以它们应该从视图后面的代码中运行,而不是在ViewModel中运行。在过去,我曾经链接到一个事件,然后从代码背后运行以下代码:

代码语言:javascript
复制
Storyboard animation = (Storyboard)panel.FindResource("MyAnimation");
animation.Begin();

至于问题1,我不认为您的代码会根据ViewModel中的属性显示不同的视图。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7530708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档