private static void OnEventsChanged(Control d, string newValue, string?oldValue)
        {
            var ele        = ElementMapper.Create(d);
            var rootOption = ControlBindLogic.FindRoot(ele.AsOption());

            rootOption.Run(
                root => BindInternal(oldValue, newValue, root, ele),
                () => ControlBindLogic.MakeLazy((IUIElement)ele, newValue, oldValue, BindInternal));
        }
예제 #2
0
        protected ControlLogicBase(TControl userControl, IViewModel model)
        {
            Logger = LogManager.GetCurrentClassLogger();

            UserControl             = userControl;
            UserControl.DataContext = model;
            Model     = model;
            BindLogic = new ControlBindLogic(userControl, model);

            // ReSharper disable once VirtualMemberCallInConstructor
            WireUpLoaded();
            // ReSharper disable once VirtualMemberCallInConstructor
            WireUpUnloaded();
        }
예제 #3
0
        protected virtual void UserControlOnLoaded()
        {
            Logger.Debug("Control Loaded {Element}", UserControl.GetType());

            if (!Model.IsInitialized)
            {
                var parentOption = ControlBindLogic.FindParentDatacontext(UserControl);
                parentOption.Run(
                    parent => parent.Actor.Tell(new InitParentViewModel(Model)),
                    () => ViewModelSuperviser.Get(ActorApplication.ActorSystem)
                    .Create(Model));
            }

            Model.AwaitInit(() => Model.Actor.Tell(new InitEvent()));
        }
        private static void SetLinker(AvaloniaObject obj, string?oldName, string?newName, Func <LinkerBase> factory)
        {
            if (string.IsNullOrWhiteSpace(newName))
            {
                return;
            }

            Argument.NotNull(obj, nameof(obj));
            Argument.NotNull(factory, nameof(factory));

            var ele        = ElementMapper.Create(obj);
            var rootOption = ControlBindLogic.FindRoot(ele.AsOption());

            rootOption.Run(
                root => SetLinker(newName, oldName, root, ele, factory),
                () => ControlBindLogic.MakeLazy((IUIElement)ele, newName, oldName, (name, old, controllable, dependencyObject)
                                                => SetLinker(old, name, controllable, dependencyObject, factory)));
        }
예제 #5
0
        private static void OnEventsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }

            var root = ControlBindLogic.FindRoot(May(d));

            if (root.IsNothing())
            {
                if (d is FrameworkElement element)
                {
                    ControlBindLogic.MakeLazy(element, MayNotEmpty(e.NewValue as string), MayNotEmpty(e.OldValue as string), BindInternal);
                }
                return;
            }

            BindInternal(MayNotEmpty(e.OldValue as string), MayNotEmpty(e.NewValue as string), root, d);
        }
예제 #6
0
        private static void OnEventsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }

            var ele        = ElementMapper.Create(d);
            var rootOption = ControlBindLogic.FindRoot(ele.AsOption());

            rootOption.Run(
                root => BindInternal(e.OldValue as string, e.NewValue as string, root, ele),
                () =>
            {
                if (d is FrameworkElement)
                {
                    ControlBindLogic.MakeLazy((IUIElement)ele, e.NewValue as string, e.OldValue as string,
                                              BindInternal);
                }
            });
        }
예제 #7
0
        protected virtual void UserControlOnLoaded()
        {
            Logger.Debug("Control Loaded {Element}", UserControl.GetType());
            ControlUnload?.Invoke();

            if (!Model.IsInitialized)
            {
                var mayParent = ControlBindLogic.FindParentDatacontext(May(UserControl).Cast <TControl, DependencyObject>());

                Match(mayParent,
                      parent => Tell(parent.Actor, new InitParentViewModel(Model)),
                      () => ViewModelSuperviser.Get(ActorApplication.Application.ActorSystem)
                      .Create(Model));
            }

            Model.AwaitInit(() =>
            {
                Tell(Model.Actor, new InitEvent(UserControl.Key));
                CommandManager.InvalidateRequerySuggested();
            });
        }
예제 #8
0
        protected ControlLogicBase(TControl userControl, IViewModel model)
        {
            Logger = Log.ForContext(GetType());

            UserControl             = userControl;
            UserControl.DataContext = model;
            Model     = model;
            BindLogic = new ControlBindLogic(userControl, model, Logger);

            // ReSharper disable once VirtualMemberCallInConstructor
            WireUpLoaded();
            // ReSharper disable once VirtualMemberCallInConstructor
            WireUpUnloaded();

            userControl.DataContextChanged += (sender, args) =>
            {
                Logger.Debug("DataContext Changed Revert");
                if (args.NewValue != model)
                {
                    ((FrameworkElement)sender).DataContext = model;
                }
            };
        }
예제 #9
0
        private static void SetLinker(DependencyObject obj, Maybe <string> oldName, Maybe <string> newName, Func <LinkerBase> factory)
        {
            if (newName.IsNothing())
            {
                return;
            }

            if (DesignerProperties.GetIsInDesignMode(obj))
            {
                return;
            }

            var root = ControlBindLogic.FindRoot(May(obj));

            if (root.IsNothing())
            {
                ControlBindLogic.MakeLazy((FrameworkElement)obj, newName, oldName,
                                          (name, old, controllable, dependencyObject) => SetLinker(old, name, controllable, dependencyObject, factory));
                return;
            }

            SetLinker(newName, oldName, root, obj, factory);
        }
        private DisconnectedDataContextRoot(Maybe <FrameworkElement> mayElementBase)
        {
            var mayRoot = ControlBindLogic.FindRoot(mayElementBase.Cast <FrameworkElement, DependencyObject>());

            var elementBase = mayElementBase.Value;

            void OnLoad(object sender, RoutedEventArgs args)
            {
                elementBase.Loaded -= OnLoad;

                var root = mayRoot.OrElseDefault();

                if (root is IView control && root is FrameworkElement {
                    DataContext : IViewModel model
                })
                {
                    _modelAction?.Invoke(model, control);

                    if (_unload != null)
                    {
                        control.ControlUnload += _unload;
                    }
                }