Exemplo n.º 1
0
        private static void onAttachPropertyChanged(
            DependencyObject @this,
            DPChangedEventArgs <bool> args)
        {
            var window = @this.AsOrDefault <Window>();

            if (window == null)
            {
                throw new NotSupportedException(
                          $"The {nameof(AttachProperty).SQuote()} attached property can only be used on the " +
                          $"type {nameof(Window).SQuote()}.");
            }

            if (args.NewValue)
            {
                window
                .CommandBindings
                .Add(
                    new CommandBinding(
                        SystemCommands.CloseWindowCommand,
                        OnCloseWindow));

                window
                .CommandBindings
                .Add(
                    new CommandBinding(
                        SystemCommands.MaximizeWindowCommand,
                        OnMaximizeWindow,
                        OnCanResizeWindow));

                window
                .CommandBindings
                .Add(
                    new CommandBinding(
                        SystemCommands.MinimizeWindowCommand,
                        OnMinimizeWindow,
                        OnCanMinimizeWindow));

                window
                .CommandBindings
                .Add(
                    new CommandBinding(
                        SystemCommands.RestoreWindowCommand,
                        OnRestoreWindow,
                        OnCanResizeWindow));
            }
        }
Exemplo n.º 2
0
        private static void onValidatorChanged(
            DependencyObject @this,
            DPChangedEventArgs <IStringValidator> args)
        {
            var frameworkElement = @this.AsOrDefault <FrameworkElement>();

            if (frameworkElement == null)
            {
                throw new ArgumentException(
                          $"The service \'HintAssist.Validator\' can only be used with elements that inherit " +
                          $"from the \'FrameworkElement\' type.");
            }

            var managerService = frameworkElement.GetTextFieldInputVisualStateService();

            managerService?.EvaluateValidationState(frameworkElement);
        }
Exemplo n.º 3
0
        private static void onTextFieldInputVisualStateServiceChanged(
            DependencyObject @this,
            DPChangedEventArgs <TextFieldInputVisualStateService> args)
        {
            var visualStateManagerService = args.NewValue;

            var frameworkInputElement = @this.AsOrDefault <IFrameworkInputElement>();

            if (frameworkInputElement == null)
            {
                throw new ArgumentException(
                          $"The service \'HintAssist.TextFieldInputVisualStateService\' can only be used " +
                          $"with elements that implement the \'IFrameworkInputElement\' interface.");
            }

            visualStateManagerService
            .AttachElement(
                frameworkInputElement);
        }