Control for adding business rule validation to the form. Assign a value or binding to source for the business object or collection of business objects to validate.
Inheritance: System.Windows.Controls.Control, IUniqueIdentifyable
コード例 #1
0
        /// <summary>
        /// Unsubscribes the warning and error validator.
        /// </summary>
        /// <param name="validator">The validator.</param>
        /// <remarks>
        /// Keep in mind that this method is normally handled by Catel. Only use this method if you really know
        /// what you are doing.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="validator"/> is <c>null</c>.</exception>
        public void UnsubscribeWarningAndErrorValidator(WarningAndErrorValidator validator)
        {
            Argument.IsNotNull("validator", validator);

            if (_warningAndErrorValidators.ContainsKey(validator.UniqueIdentifier))
            {
                validator.Validation -= OnInfoBarMessageValidation;
                _warningAndErrorValidators.Remove(validator.UniqueIdentifier);
            }
        }
コード例 #2
0
        private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions)
        {
            var content = GetContent(view) as FrameworkElement;
            if (content == null)
            {
                return null;
            }

            object tempObj = null;
            if (_weakIsWrappingTable.TryGetValue(view, out tempObj))
            {
                return null;
            }

            _weakIsWrappingTable.Add(view, new object());

            var vmGrid = new Grid();
            vmGrid.Name = InnerWrapperName.GetUniqueControlName();
            vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource });

#if NET || SL5
            if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel))
            {
                var warningAndErrorValidator = new WarningAndErrorValidator();
                warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding());

                vmGrid.Children.Add(warningAndErrorValidator);
            }
#endif

            if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid))
            {
                content.TransferStylesAndTransitions(vmGrid);
            }

            SetContent(view, null);
            vmGrid.Children.Add(content);
            SetContent(view, vmGrid);

            Log.Debug("Created target control content wrapper grid for view model");

            return new ViewModelWrapper(vmGrid);
        }
コード例 #3
0
        private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions)
        {
            var content = GetContent(view) as FrameworkElement;
            if (content == null)
            {
                return null;
            }

            object tempObj = null;
            if (_weakIsWrappingTable.TryGetValue(view, out tempObj))
            {
                return null;
            }

            var viewTypeName = view.GetType().Name;

            _weakIsWrappingTable.Add(view, new object());

            Grid vmGrid = null;

            var existingGrid = GetContent(view) as Grid;
            if (existingGrid != null)
            {
                if (existingGrid.Name.StartsWith(InnerWrapperName))
                {
                    Log.Debug($"No need to create content wrapper grid for view model for view '{viewTypeName}', custom grid with special name defined");

                    vmGrid = existingGrid;
                }
            }

            if (vmGrid == null)
            {
                Log.Debug($"Creating content wrapper grid for view model for view '{viewTypeName}'");

                vmGrid = new Grid();
                vmGrid.Name = InnerWrapperName.GetUniqueControlName();

#if NET || SL5
                if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel))
                {
                    var warningAndErrorValidator = new WarningAndErrorValidator();
                    warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding());

                    vmGrid.Children.Add(warningAndErrorValidator);
                }
#endif

                if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid))
                {
                    content.TransferStylesAndTransitions(vmGrid);
                }

                SetContent(view, null);
                vmGrid.Children.Add(content);
                SetContent(view, vmGrid);

                Log.Debug($"Created content wrapper grid for view model for view '{viewTypeName}'");
            }

            var binding = vmGrid.GetBindingExpression(FrameworkElement.DataContextProperty);
            if (binding == null)
            {
                vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding
                {
                    Path = new PropertyPath("ViewModel"),
                    Source = viewModelSource
                });
            }

            return new ViewModelWrapper(vmGrid);
        }
コード例 #4
0
        /// <summary>
        /// Unsubscribes the warning and error validator.
        /// </summary>
        /// <param name="validator">The validator.</param>
        /// <remarks>
        /// Keep in mind that this method is normally handled by Catel. Only use this method if you really know
        /// what you are doing.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="validator"/> is <c>null</c>.</exception>
        public void UnsubscribeWarningAndErrorValidator(WarningAndErrorValidator validator)
        {
            Argument.IsNotNull("validator", validator);

            if (_warningAndErrorValidators.ContainsKey(validator.UniqueIdentifier))
            {
                validator.Validation -= OnInfoBarMessageValidation;
                _warningAndErrorValidators.Remove(validator.UniqueIdentifier);
            }
        }