<syncfusion:GridDataControl Grid.Column="0" ShowAddNewRow="False" ItemsSource="{Binding UserData}" AllowDelete="False" AllowEdit="False" AllowGroup="False" AutoPopulateColumns="False" AutoPopulateRelations="False" ExcelLikeCurrentCell="False">
<syncfusion:GridDataVisibleColumn HeaderText="Preference Name" Binding="{Binding UserPreferenceName}" Width="200" IsReadOnly="True" AllowResize="True"/>
<syncfusion:GridDataVisibleColumn HeaderText="Last Updated" IsReadOnly="True" Binding="{Binding UpdateTS, StringFormat=d}" Width="100" MinimumWidth="100"/>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReactiveUI;
using ReactiveUI.Xaml;
using MyCode.Models.SupportObjects;
using MyCode.Core;
using MyCode.Core.Extensions;
using MyCode.Models.Main;
using System.Reactive.Linq;
namespace MyCode.ViewModels
{
public class UserPreferenceManagerVM : ReactiveValidatedObject
{
public UserPreferenceManagerVM(string defaultUser)
{
SelectedUser = defaultUser;
FetchPreferencesForUser = new ReactiveAsyncCommand();
FetchPreferencesForUser.RegisterAsyncAction(_ => LoadUserPreferenceData());
UserData = new ReactiveCollection<UserPreference>();
FetchPreferencesForUser.Execute(null);
this.ObservableForProperty(x => x.SelectedUser).Subscribe(_ => FetchPreferencesForUser.Execute(null));
LoadUserProfiles();
}
private string _SelectedUser = string.Empty;
public string SelectedUser
{
get { return this._SelectedUser; }
set { this.RaiseAndSetIfChanged(x => x.SelectedUser, value); }
}
public ReactiveCollection<UserPreference> UserData
{
get;
protected set;
}
public ReactiveCollection<UserProfile> UserProfiles
{
get;
protected set;
}
public ReactiveAsyncCommand FetchPreferencesForUser
{
get;
protected set;
}
private void LoadUserPreferenceData()
{
UserData.Clear();
if (SelectedUser == SystemVariables.ActingUser)
{
if (MyCode.Core.Cache.Items.ContainsKey(CacheKeys.UserPreferences))
{
Dictionary<string, UserPreference> prefs = MyCode.Core.Cache.GetItem<Dictionary<string, UserPreference>>(CacheKeys.UserPreferences);
if (prefs != null)
{
foreach (var item in prefs)
{
UserData.Add(item.Value);
}
}
}
}
}
private void LoadUserProfiles()
{
if (MyCode.Core.Cache.Items.ContainsKey(CacheKeys.UserProfiles))
{
List<UserProfile> profiles = MyCode.Core.Cache.GetItem<List<UserProfile>>(CacheKeys.UserProfiles);
if (profiles != null)
{
UserProfiles = new ReactiveCollection<UserProfile>(profiles.OrderBy(x=>x.LastName));
}
}
}
}
}
The Objects are basic objects that implement the INotifyPropertyChanged stuff.
Attached is the screenshot of a dummy app that replicates the problem. Good state, onload of the app, and Bad State after I have changed the combo and then gone back to another user.