public static void Show <TWindow, TViewModel>(BaseNotifyPropertyChanged viewModel, params object[] viewModelParameters) where TWindow : Window where TViewModel : BaseNotifyPropertyChanged { BaseNotifyPropertyChanged vm = null; //viewModel Type vmType = typeof(TViewModel); if (viewModelCache.ContainsKey(vmType)) { vm = viewModelCache[vmType]; } // Si l'instance du ViewModel existe, on le récupère dans le cache else { vm = (TViewModel)Activator.CreateInstance(vmType, viewModelParameters); // Création viewModelCache[vmType] = vm; // Ajout dans le Cache } Window window = null; Type windowType = typeof(TWindow); if (windowsCache.ContainsKey(windowType)) { window = windowsCache[windowType]; } else { window = (TWindow)Activator.CreateInstance(windowType); window.DataContext = viewModel; } window.Show(); }
public static bool?ShowDialog(Type tView, BaseNotifyPropertyChanged vm) { var win = GetViewInstance( tView, vm); var method = win.GetType().GetMethod("ShowDialog"); return((bool?)method?.Invoke(win, null)); }
public void Intercept(IInvocation invocation) { invocation.Proceed(); BaseNotifyPropertyChangedAttribute attribute = ProxyCommon.AsAttribute <BaseNotifyPropertyChangedAttribute>(invocation.Method); if (attribute != null) { BaseNotifyPropertyChanged @base = invocation.InvocationTarget as BaseNotifyPropertyChanged; foreach (string property in attribute.PropertiesToNotify) { @base.OnPropertyChanged(property); } } }
public static void Register(INavigationPage page, BaseNotifyPropertyChanged viewModel, object parameter) { page.DataContext = viewModel; if (viewModel != null) { if (viewModel.GetType().IsChildOf(typeof(NavigateViewModel))) { ((NavigateViewModel)viewModel).NavParameter = parameter; } if (viewModel.GetType().IsChildOf(typeof(InitializableViewModel))) { ((Page)page).Loaded += NavigationPage_Loaded; } } if (viewModel != null && viewModel.GetType().IsChildOf(typeof(InitializableViewModel))) { ((Page)page).Loaded += NavigationPage_Loaded; } }
private readonly BaseNotifyPropertyChanged _decorated; // GameSession public NotifyPropertyChangedProxy(T decorated) : base(typeof(T)) { _decorated = decorated; }