예제 #1
0
            public ContentWrapper(ModalControl parent, FrameworkElement element, ModalPosition position, Point?location, bool allowsCloseWithAncestor)
            {
                Contract.Requires(parent != null);
                Contract.Requires(element != null);
                Contract.Requires(element.Parent == null);
                element.VerifyAccess();
                Util.ThrowUnless(element.GetValue(ContentWrapperProperty) == null);

                _mask = new Rectangle {
                    Opacity = 0
                };
                _mask.MouseLeftButtonDown += (sender, args) => parent.maskMouseLeftButtonDown(this);

                _element = element;

                Content = _container = new Grid();
                _container.Children.Add(_mask);
                _container.Children.Add(_element);

                _parent = parent;

                switch (position)
                {
                case ModalPosition.Center:
                    element.HorizontalAlignment   = System.Windows.HorizontalAlignment.Center;
                    element.VerticalAlignment     = System.Windows.VerticalAlignment.Center;
                    element.RenderTransformOrigin = new Point(0.5, 0.5);
                    break;

                case ModalPosition.TopLeft:
                    element.HorizontalAlignment   = System.Windows.HorizontalAlignment.Left;
                    element.VerticalAlignment     = System.Windows.VerticalAlignment.Top;
                    element.RenderTransformOrigin = new Point(0, 0);
                    break;

                default:
                    throw new NotSupportedException();
                }

                _location = location;
                _allowsCloseWithAncestor = allowsCloseWithAncestor;

                State = ContentState.Unloaded;

                _element.RenderTransform = _transform = new CompositeTransform {
                    ScaleX = 0, ScaleY = 0
                };
                _element.SetValue(ContentWrapperProperty, this);
                _element.Loaded += _element_Loaded;

                _mask.SetBinding(Rectangle.FillProperty, new Binding("Background")
                {
                    Source = parent
                });

                IsEnabled = false;
            }
예제 #2
0
            public ContentWrapper(ModalControl parent, FrameworkElement element, ModalPosition position, Point? location)
            {
                Contract.Requires(parent != null);
                Contract.Requires(element != null);
                Contract.Requires(element.Parent == null);
                element.VerifyAccess();
                Util.ThrowUnless(element.GetValue(ContentWrapperProperty) == null);

                _mask = new Rectangle { Opacity = 0 };
                _mask.MouseLeftButtonDown += (sender, args) => parent.maskMouseLeftButtonDown(this);

                _element = element;

                Content = _container = new Grid();
                _container.Children.Add(_mask);
                _container.Children.Add(_element);

                _parent = parent;

                switch (position)
                {
                    case ModalPosition.Center:
                        element.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                        element.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                        element.RenderTransformOrigin = new Point(0.5, 0.5);
                        break;
                    case ModalPosition.TopLeft:
                        element.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        element.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                        element.RenderTransformOrigin = new Point(0, 0);
                        break;
                    default:
                        throw new NotSupportedException();
                }

                _location = location;
                State = ContentState.Unloaded;

                _element.RenderTransform = _transform = new CompositeTransform { ScaleX = 0, ScaleY = 0 };
                _element.SetValue(ContentWrapperProperty, this);
                _element.Loaded += _element_Loaded;

                _mask.SetBinding(Rectangle.FillProperty, new Binding("Background") { Source = parent });

                IsEnabled = false;
            }