如何从 ViewModel 开始故事板?
我在示例中使用 Telerik 控件。
<telerik:RadPanelBarItem Collapsed="RadPanelBarItem_Collapsed"
DropPosition="Inside"
Header="Searching for Clients"
IsExpanded="false"
IsTabStop="True"
TabNavigation="Once">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Expanded">
<i:InvokeCommandAction Command="{Binding ExpandedComand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadPanelBarItem>
我想在触发 Expanded 事件时在 ViewModel 中运行代码。到目前为止一切顺利,但我还需要在扩展它时启动动画。但这在 ViewModel 中是不可能的,但它必须在视图上运行:
ArrowStoryboard.Begin();
那么我应该怎么做呢?
更新:
让我详细说明一下,因为它似乎引起了一些混乱。我不必从 ViewModel 执行与视图相关的动画。但我必须在扩展事件时执行两件事。 1) 开始动画,2) 在 viewModel 上运行一组代码。
我知道但不是很好的唯一方法,因为它将代码广告到代码隐藏是这样的: 将 DataContext 转换为 ViewModel 并在动画开始后立即在 ViewModel 上运行相应的方法。
谢谢,
I am utilizing Telerik controls in my example.
<telerik:RadPanelBarItem Collapsed="RadPanelBarItem_Collapsed"
DropPosition="Inside"
Header="Searching for Clients"
IsExpanded="false"
IsTabStop="True"
TabNavigation="Once">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Expanded">
<i:InvokeCommandAction Command="{Binding ExpandedComand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadPanelBarItem>
I would like to Run code within the ViewModel whenever the Expanded event is triggered. So far so good, but I also need to start an animation upon expanding it. But this is not possible from the ViewModel, but it has to run on the view:
ArrowStoryboard.Begin();
So how should I do this?
UPDATE:
Let me elaborate a bit more as it seems it caused some confusion. I don't have to execute the view related animation from the ViewModel. But I have to execute two thing upon expansion event. 1) Begin the Animation and 2) run a set of code on the viewModel.
The only way I know of but isn't great as it ads code to the code-behind is this:
Casting the DataContext to the ViewModel and run the according method on the ViewModel right after beginning of Animation.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在
InvokeCommandAction
旁边附加另一个行为ControlStoryboardAction
?更新
使用 Blend 在样式内制作这种动画实际上并不需要太多工作。
我在这里所做的基本上是使用 Blend 生成 RadPanelBarItem 的默认样式,然后在 Expand 视觉状态下,我创建了一个飞出箭头的动画并使其永远运行。
这并不完全是您想要的动画(箭头向上而不是向右),但它可能会给您一些想法。希望这有帮助。 :)
只需应用样式名称
AnimatedRadPanelBarItemStyle
。Why not attach another behavior
ControlStoryboardAction
aside yourInvokeCommandAction
?UPDATE
It's actually not a lot of work to do this kind of animations inside the style using Blend.
What I've done here basically is I used Blend to generate the default style of RadPanelBarItem, then in the Expand visual state, I created an animation that flys out the arrow and made it run forever.
This is not exactly the animation you want (the arrow goes up rather than right) but it may give you some ideas. Hope this helps. :)
Just apply the style name
AnimatedRadPanelBarItemStyle
.从 ViewModel 引发视图特定操作是一个坏主意,因为故事板与视图模型没有任何关系。有两种方法可以实现您想做的事情。
It's a bad idea to raise view specific action from ViewModel since storyboard has nothing with view model. There're two ways to achieve what you want to do.