我有一个窗口,随着时间的推移,不同的控件必须显示出来。我通过使用mvvm模式搜索了一个解决方案,最终得到了以下结果
<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>到目前为止,这还不错,但我对两件事很好奇:
有一种更好的使用
发布于 2011-09-23 15:07:23
关于问题2:
您可以在模板中的控件中使用EventTrigger启动动画,如下所示:
<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>发布于 2011-09-23 14:57:07
由于动画是特定于视图的操作,所以它们应该从视图后面的代码中运行,而不是在ViewModel中运行。在过去,我曾经链接到一个事件,然后从代码背后运行以下代码:
Storyboard animation = (Storyboard)panel.FindResource("MyAnimation");
animation.Begin();至于问题1,我不认为您的代码会根据ViewModel中的属性显示不同的视图。
https://stackoverflow.com/questions/7530708
复制相似问题