每次触发时,Interactivity都可以重置弹出视图模型吗?

时间:2016-07-22 10:56:47

标签: c# prism

交互性是展示新窗口的最佳方式吗?如果是这样,我如何重置/重新初始化UserControl的ViewModel?因为我看到它重复使用弹出窗口。

1 个答案:

答案 0 :(得分:1)

在您的ViewModel中,您应该有一个名为Notification的属性。每次调用请求时都会设置该值。在那里添加一些逻辑来清除列表框。 见下文:

public INotification Notification
{
    get
    {
        return notification;
    }
    set
    {
        if (value is ItemSelectionNotification)
        {
            notification = value as ItemSelectionNotification;
            OnPropertyChanged(() => Notification);
            //*** Add ListBox clearing code here!!
            // Maybe a call to a method -> ClearListBoxes();
        }
    }
}

这就是我的ItemSelectionNotification类在您需要时的样子。

public class ItemSelectionNotification : Confirmation
{
    public ItemSelectionNotification() { }
    public ItemSelectionNotification(object payload)
    {
        Payload = payload;
    }
    public object SelectedItem { get; set; }
    public object Payload { get; } = null;
}