public static IViewModelResolver IfInheritsFrom(this IViewModelResolver @this, Type genericInterfaceType, Action<FrameworkElement, object, IGenericInterface> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom<FrameworkElement>(
                genericInterfaceType,
                (view, viewModel, interfaceInstance, container) => configuration(view, viewModel, interfaceInstance));
        }
        public static IViewModelResolver ApplyDefaultConfigure(this IViewModelResolver @this)
        {
            @this
            .IfInheritsFrom <ViewModelBase>((view, viewModel) =>
            {
                viewModel.Dispatcher = view.Dispatcher;
            })
            .IfInheritsFrom <IAwareViewLoadedAndUnloaded>((view, viewModel) =>
            {
                view.Loaded   += (sender, e) => viewModel.OnLoaded();
                view.Unloaded += (sender, e) => viewModel.OnUnloaded();
            })
            .IfInheritsFrom(typeof(IAwareViewLoadedAndUnloaded <>), (interfaceInstance, view, viewModel) =>
            {
                var viewType = view.GetType();
                if (interfaceInstance.GenericArguments.Single() != viewType)
                {
                    throw new InvalidOperationException();
                }

                var onLoadedMethod   = interfaceInstance.GetMethod <Action <object> >("OnLoaded", viewType);
                var onUnloadedMethod = interfaceInstance.GetMethod <Action <object> >("OnUnloaded", viewType);

                view.Loaded   += (sender, args) => onLoadedMethod(sender);
                view.Unloaded += (sender, args) => onUnloadedMethod(sender);
            })
            .IfInheritsFrom <ILocalizable>((view, viewModel) =>
            {
                viewModel.I18nManager = I18nManager.Instance;
                view.Loaded          += (sender, args) => I18nManager.Instance.CurrentUICultureChanged += viewModel.OnCurrentUICultureChanged;
                view.Unloaded        += (sender, args) => I18nManager.Instance.CurrentUICultureChanged -= viewModel.OnCurrentUICultureChanged;
            });
            //.IfInheritsFrom<IAwareTabItemSelectionChanged>((view, viewModel) =>
            //{
            //    TabControlHelper.SetAwareSelectionChanged(view, true);
            //});

            return(@this);
        }
        public static IViewModelResolver UseDefaultConfigure(this IViewModelResolver @this) => @this
            .IfInheritsFrom<ViewModelBase>((view, viewModel) =>
            {
                viewModel.Dispatcher = view.Dispatcher;
            })
            .IfInheritsFrom<ILocalizable>((view, viewModel) =>
            {
                viewModel.I18nManager = I18nManager.Instance;
                view.Loaded += (sender, args) => I18nManager.Instance.CurrentUICultureChanged += viewModel.OnCurrentUICultureChanged;
                view.Unloaded += (sender, args) => I18nManager.Instance.CurrentUICultureChanged -= viewModel.OnCurrentUICultureChanged;
            })
            .IfInheritsFrom<IViewLoadedAndUnloadedAware>((view, viewModel) =>
            {
                view.Loaded += (sender, e) => viewModel.OnLoaded();
                view.Unloaded += (sender, e) => viewModel.OnUnloaded();
            })
            .IfInheritsFrom(typeof(IViewLoadedAndUnloadedAware<>), (view, viewModel, interfaceInstance) =>
            {
                var viewType = view.GetType();
                if (interfaceInstance.GenericArguments.Single() != viewType)
                {
                    throw new InvalidOperationException();
                }

                var onLoadedMethod = interfaceInstance.GetMethod<Action<object>>("OnLoaded", viewType);
                var onUnloadedMethod = interfaceInstance.GetMethod<Action<object>>("OnUnloaded", viewType);

                view.Loaded += (sender, args) => onLoadedMethod(sender);
                view.Unloaded += (sender, args) => onUnloadedMethod(sender);
            })
            .IfInheritsFrom<INotificable>((view, viewModel, container) =>
            {
                viewModel.GlobalMessageQueue = container.Resolve<ISnackbarMessageQueue>();
            });
        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel, IContainerProvider> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom(configuration);
        }
            //.IfInheritsFrom<IAwareTabItemSelectionChanged>((view, viewModel) =>
            //{
            //    TabControlHelper.SetAwareSelectionChanged(view, true);
            //});

        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom<FrameworkElement, TViewModel>((view, viewModel, container) => configuration(view, viewModel));
        }
Example #6
0
        /// <summary>
        /// Uses the default configure.
        /// </summary>
        /// <param name="this">The this.</param>
        /// <returns></returns>
        public static IViewModelResolver UseDefaultConfigure(this IViewModelResolver @this) => @this
        .IfInheritsFrom <ViewModelBase>((view, viewModel) =>
        {
            viewModel.Dispatcher = view.Dispatcher;
        })
        .IfInheritsFrom <IViewLoadedAndUnloadedAware>((view, viewModel) =>
        {
            view.Loaded   += (sender, e) => viewModel.OnLoaded();
            view.Unloaded += (sender, e) => viewModel.OnUnloaded();
        })
        .IfInheritsFrom(typeof(IViewLoadedAndUnloadedAware <>), (view, viewModel, interfaceInstance) =>
        {
            var viewType = view.GetType();
            if (interfaceInstance.GenericArguments.Single() != viewType)
            {
                throw new InvalidOperationException();
            }

            var onLoadedMethod   = interfaceInstance.GetMethod <Action <object> >("OnLoaded", viewType);
            var onUnloadedMethod = interfaceInstance.GetMethod <Action <object> >("OnUnloaded", viewType);

            view.Loaded   += (sender, args) => onLoadedMethod(sender);
            view.Unloaded += (sender, args) => onUnloadedMethod(sender);
        });