0

我已经设置了一个视图模型来将一个列表控件绑定到我的程序中的一个 ObservableCollection。页面上的 UI 控件向集合添加和删除对象,当列表自动更新时,它工作正常。

在 App-Switching 并返回应用程序后,按钮添加了对象,但绑定似乎丢失了。任何想法即使在返回后我也能保持这一点?我真的不认为需要重新绑定对象(在 XAML 中定义它之后)。有没有办法让这种模式万无一失?并确保在返回应用程序时绑定不会丢失?

XAML 看起来像这样,但它在 UserControl 内 - 忘了提

ItemsControl x:Name="PartyCollection" ItemTemplate="{StaticResource PartyCollectiontemplate}" ItemsSource="{Binding RoomParty, Source={StaticResource FormControlVM}}"

代码隐藏看起来像这样

public class FormControlVM : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public ObservableCollection<Party> RoomParty
    {
        get
        {
            return App.appData.currentChoices.roomParty;
        }
        set
        {
            App.appData.currentChoices.roomParty = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("RoomParty"));
        }
    }
}
4

0 回答 0