Ejemplo n.º 1
0
        public void UnregistryWindowType <ViewModel>()
        {
            Type ViewModelType = typeof(ViewModel);

            if (ViewModelType.IsInterface)
            {
                throw new Exception("Cannot registry interfaces");
            }
            if (ViewModelWindowsMapping.ContainsKey(ViewModelType))
            {
                throw new Exception($"Type is already registred");
            }
            ViewModelWindowsMapping.Remove(ViewModelType);
        }
Ejemplo n.º 2
0
        public void RegistryWindowType <ViewModel, Win>() where ViewModel : class where Win : Window, new()
        {
            Type ViewModelType = typeof(ViewModel);

            if (ViewModelType.IsInterface)
            {
                throw new Exception("Cannot registry interfaces");
            }
            if (ViewModelWindowsMapping.ContainsKey(ViewModelType))
            {
                throw new Exception($"Type is already registred");
            }
            ViewModelWindowsMapping[ViewModelType] = typeof(Win);
        }
Ejemplo n.º 3
0
        public Window CreateWindowInstanceWithViewModel(object viewModel)
        {
            if (viewModel == null)
            {
                throw new Exception("View model is null");
            }
            Type WindowType    = null;
            Type ViewModelType = viewModel.GetType();

            while (ViewModelType != null && !ViewModelWindowsMapping.TryGetValue(ViewModelType, out WindowType))
            {
                ViewModelType = ViewModelType.BaseType;
            }
            if (WindowType == null)
            {
                throw new Exception($"No registred window type for argument type {viewModel.GetType().FullName}");
            }
            Window Window = (Activator.CreateInstance(WindowType) as Window);

            Window.DataContext = viewModel;
            return(Window);
        }