Example #1
0
 public void Register(FrameworkElement elementToValidate, ValidatorBase v)
 {
     items.Add(new ManagerList()
     {
         Element = elementToValidate, Validator = v
     });
 }
Example #2
0
        private void PositionIndicatorToRoot(ValidatorBase validator)
        {
            //double controlTop = (validator.ElementToValidate.ActualHeight / 2) - (this.Height / 2);
            double controlTop  = (validator.ElementToValidate.ActualHeight / 2);
            double controlLeft = validator.ElementToValidate.ActualWidth + 8;

            this.HorizontalAlignment = HorizontalAlignment.Right;
            this.Margin = new Thickness(0, 0, 0, 0);
        }
Example #3
0
        private void PositionIndicator(ValidatorBase validator)
        {
            GeneralTransform gt     = validator.ElementToValidate.TransformToVisual(validator.UserControl);
            Point            offset = gt.Transform(new Point(0, 0));

            double controlTop = offset.Y + (validator.ElementToValidate.ActualHeight / 2) - (this.Height / 2);

            double controlLeft = offset.X + validator.ElementToValidate.ActualWidth + 3;

            this.HorizontalAlignment = HorizontalAlignment.Right;
            this.Margin = new Thickness(0, 0, 0, 0);
        }
Example #4
0
 public static void SetValidator(DependencyObject obj, ValidatorBase value)
 {
     obj.SetValue(ValidatorProperty, value);
 }
Example #5
0
        public void ShowIndicator(ValidatorBase validator)
        {
            try
            {
                //TODO: Refactor Indicator insertion to UserControl
                //There is an issue with adding the Indicator to the LayoutRoot and where it's positioned.
                //This way works for now, but should be refactored.

                //Modified by Reo, 需要显示到被验证控件的父元素
                //if (this.Parent == null)
                //{
                //    Panel g = (Panel)validator.UserControl.FindName("LayoutRoot");
                //    g.Children.Add(this);


                //    if (validator.ElementToValidate.Parent == g)
                //    {
                //        if (g is Grid)
                //        {
                //            var col = Grid.GetColumn(validator.ElementToValidate);
                //            var row = Grid.GetRow(validator.ElementToValidate);

                //            Grid.SetColumn(this, col);
                //            Grid.SetRow(this, row);
                //        }
                //        PositionIndicatorToRoot(validator);
                //    }
                //    else
                //    {
                //        PositionIndicator(validator);
                //    }
                //}

                //暂时不显示
                if (this.Parent == null)
                {
                    Panel g = (Panel)FindParentControl <Grid>(validator.ElementToValidate);
                    g.Children.Add(this);


                    if (validator.ElementToValidate.Parent == g)
                    {
                        if (g is Grid)
                        {
                            var col = Grid.GetColumn(validator.ElementToValidate);
                            var row = Grid.GetRow(validator.ElementToValidate);

                            Grid.SetColumn(this, col);
                            Grid.SetRow(this, row);
                            Grid.SetColumnSpan(this, Grid.GetColumnSpan(validator.ElementToValidate));
                            Grid.SetRowSpan(this, Grid.GetRowSpan(validator.ElementToValidate));
                        }
                        PositionIndicatorToRoot(validator);
                    }
                    else
                    {
                        PositionIndicator(validator);
                    }
                }

                if (!string.IsNullOrEmpty(validator.ErrorMessage))
                {
                    ToolTipService.SetToolTip(this, validator.ErrorMessage);
                }
                validator.UserControl.UpdateLayout();


                HideIndicatorStory.Stop();
                ShowIndicatorStory.Begin();
            }
            catch (Exception e) {
                var s = e;
            }
            // return;
        }