Silverlight:MVVM 和重新初始化表单
我们使用 Prism,从网格中弹出一个编辑表单,其中有两个选项:“保存”和“保存并新建”。我的问题是关于重新初始化表单。我想知道是否有更好或更简单的方法?我所做的是在视图模型上公开 InteractionRequest,然后在 xaml 中使用 InteractionRequestTrigger 来更改表单的属性,如下所示:
private void SubmitAndNewCommandCallback(IEnumerable<ValidationResult> errors)
{
if (errors != null && errors.Any())
{
Errors = errors.Select(x => x.ErrorMessage).ToList();
}
else
{
if (IsNew)
{
_events.GetEvent<BidAgentCreated>().Publish(this.BidAgent);
}
_intializeFormRequest.Raise(this);
}
}
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding InitializeFormRequest}" >
<ei:ChangePropertyAction TargetName="ctlAgentType" PropertyName="SelectedIndex" Value="0" />
<ei:ChangePropertyAction TargetName="ctlAgentSearchBox" PropertyName="Text" Value=""/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
We use Prism and from the grid we pop up a edit form that has two options, "Save" and "Save and New". My question is about re-initializing form. I am wondering if there is a better or simpler way? What I do is expose a InteractionRequest on the view model, and than use InteractionRequestTrigger in xaml to change the properties of the form, like this:
private void SubmitAndNewCommandCallback(IEnumerable<ValidationResult> errors)
{
if (errors != null && errors.Any())
{
Errors = errors.Select(x => x.ErrorMessage).ToList();
}
else
{
if (IsNew)
{
_events.GetEvent<BidAgentCreated>().Publish(this.BidAgent);
}
_intializeFormRequest.Raise(this);
}
}
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding InitializeFormRequest}" >
<ei:ChangePropertyAction TargetName="ctlAgentType" PropertyName="SelectedIndex" Value="0" />
<ei:ChangePropertyAction TargetName="ctlAgentSearchBox" PropertyName="Text" Value=""/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种干净的方法是摆脱 View 中的逻辑并将其保留在 ViewModel 中。
xaml 中
在 ViewModel 的
A clean way is to get rid of the logic in your View and keep it in the ViewModel.
in xaml
in the ViewModel