Ejemplo n.º 1
0
		public PopupButton()
		{
			var content = new ContentPresenter();
			content.SetBinding(ContentPresenter.ContentProperty, new Binding("PopupContent") { Source = this });
			var border = new Border()
			{
				CornerRadius = new CornerRadius(5),
				BorderThickness = new Thickness(1),
				Child = content
			};
			border.SetResourceReference(Border.BackgroundProperty, "BaseWindowBackgroundBrush");
			border.SetResourceReference(Border.BorderBrushProperty, "WindowBorderBrush");
			_popup = new Popup()
			{
				AllowsTransparency = true,
				StaysOpen = false,
				Placement = PlacementMode.Bottom,
				PlacementTarget = this,
				DataContext = this,
				Child = border,
			};
			_popup.SetBinding(Popup.IsOpenProperty, "IsChecked");
			_popup.SetBinding(Popup.WidthProperty, "Width");
			SetBinding(PopupButton.IsHitTestVisibleProperty, new Binding("IsOpen") { Source = _popup, Mode = BindingMode.OneWay, Converter = new InverseBooleanConverter() });
		}
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code 
        /// or internal processes call System.Windows.FrameworkElement.ApplyTemplate().
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Clear cache
            cachedMeasures.Clear();

            if (LauncherButton != null) LauncherButton.Click -= OnDialogLauncherButtonClick;
            LauncherButton = GetTemplateChild("PART_DialogLauncherButton") as Button;
            if (LauncherButton != null)
            {
                LauncherButton.Click += OnDialogLauncherButtonClick;
                if (LauncherKeys != null)
                    KeyTip.SetKeys(LauncherButton, LauncherKeys);
            }

            popup = GetTemplateChild("PART_Popup") as Popup;
            if (popup != null)
            {
                Binding binding = new Binding("IsOpen");
                binding.Mode = BindingMode.TwoWay;
                binding.Source = this;
                popup.SetBinding(Popup.IsOpenProperty, binding);
            }

            downGrid = GetTemplateChild("PART_DownGrid") as Grid;
            upPanel = GetTemplateChild("PART_UpPanel") as Panel;
            parentPanel = GetTemplateChild("PART_ParentPanel") as Panel;
        }
		public GlyphIconButton_WithPopup()
		{
			Popup = new Popup()
			{
				AllowsTransparency = true,
			};
			var contentControl = new ContentControl()
			{
				Focusable = false,
				IsTabStop = false,

			};
			contentControl.SetBinding(ContentProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupContent)}")});
			contentControl.SetBinding(ContentTemplateProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupContentTemplate)}")});
			Popup.Child = new Border
			{
				Child = contentControl,
				Effect = new DropShadowEffect() {BlurRadius = 10, Color = Colors.Black, Opacity = 1, ShadowDepth = 0},
				Margin = new Thickness(10),
			};
			Popup.SetBinding(Popup.IsOpenProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(IsOpened)}")});
			Popup.SetBinding(Popup.PlacementTargetProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupPlacementTarget)}")});
			Popup.SetBinding(Popup.StaysOpenProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(StaysOpen)}")});
			Popup.Placement = PlacementMode.Bottom;
			AddLogicalChild(Popup);
			Click += GlyphIconButton_WithPopup_Click;
		}
        static void SetupRxPopup(object rootModel, UIElement view, Popup popup) {
            var isOpen = rootModel as IIsOpen;
            if (isOpen != null) {
                isOpen.IsOpen = true;
                popup.SetBinding(Popup.IsOpenProperty, new Binding("IsOpen") {Mode = BindingMode.TwoWay});
                popup.SetBinding(Popup.StaysOpenProperty, new Binding("StaysOpen") {Mode = BindingMode.TwoWay});
            }

            var vFor = view as IViewFor;
            if (vFor == null)
                return;
            var rxClose = rootModel as IRxClose;
            if (rxClose != null) {
                // Is this how we want to do it?
                vFor.WhenActivated(
                    d => {
                        d(
                            rxClose.Close.ObserveOn(RxApp.MainThreadScheduler)
                                .Subscribe(x => { popup.IsOpen = !popup.IsOpen; }));
                    });
            }
        }
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or 
        /// internal processes call System.Windows.FrameworkElement.ApplyTemplate().
        /// </summary>
        public override void OnApplyTemplate()
        {
            popup = GetTemplateChild("PART_Popup") as Popup;
            if (popup != null)
            {
                Binding binding = new Binding("IsOpen");
                binding.Mode = BindingMode.TwoWay;
                binding.Source = this;
                popup.SetBinding(Popup.IsOpenProperty, binding);

                popup.CustomPopupPlacementCallback = CustomPopupPlacementMethod;
            }
            if ((ToolbarPanel != null) && (toolBarItems != null))
            {
                for (int i = 0; i < toolBarItems.Count; i++)
                {
                    ToolbarPanel.Children.Remove(toolBarItems[i]);
                }
            }
            toolbarPanel = GetTemplateChild("PART_ToolbarPanel") as Panel;
            if ((ToolbarPanel != null) && (toolBarItems != null))
            {
                for (int i = 0; i < toolBarItems.Count; i++)
                {
                    ToolbarPanel.Children.Add(toolBarItems[i]);
                }
            }
        }
Ejemplo n.º 6
0
        private void HandleLoaded(object sender, RoutedEventArgs e)
        {
            popup = new Popup();

            view = new DocumentPadView() {DataContext = ApplicationModel.Current.DocumentPad};

            ResizablePopupFrameBehavior.SetParentPopup(view, popup);
            ResizablePopupFrameBehavior.SetResizeBounds(view, GetCurrentPopupBounds());

            view.Width = 300;
            view.Height = 300;

            PropertyChangedEventHandler documentPadOnPropertyChanged = null;
            documentPadOnPropertyChanged = (s, args) =>
            {
                ApplicationModel.Current.DocumentPad.PropertyChanged -= documentPadOnPropertyChanged;
                var bounds = GetCurrentPopupBounds();
                if (args.PropertyName == "IsOpen")
                {
                    popup.HorizontalOffset = bounds.Right - view.Width;
                    popup.VerticalOffset = bounds.Bottom - view.Height;
                }
            };

            ApplicationModel.Current.DocumentPad.PropertyChanged += documentPadOnPropertyChanged;
            

            popup.Child = view;
            popup.SetBinding(Popup.IsOpenProperty, new Binding("IsOpen") {Source = ApplicationModel.Current.DocumentPad});
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Hooks up a Popup to a child.
        ///     The child will be required to implement the following properties:
        ///         Popup.IsOpenProperty
        ///         Popup.PlacementProperty
        ///         Popup.PlacementRectangleProperty
        ///         Popup.PlacementTargetProperty
        ///         Popup.HorizontalOffsetProperty
        ///         Popup.VerticalOffsetProperty
        /// </summary>
        /// <param name="popup">The parent popup that the child will be hooked up to.</param>
        /// <param name="child">The element to be the child of the popup.</param>
        public static void CreateRootPopup(Popup popup, UIElement child)
        {
            if (popup == null)
            {
                throw new ArgumentNullException("popup");
            }
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            // When we get here, the Child must not have already been visually or logically parented.
            object currentParent = null;
            if ((currentParent = LogicalTreeHelper.GetParent(child)) != null)
            {
                throw new InvalidOperationException(SR.Get(SRID.CreateRootPopup_ChildHasLogicalParent, child, currentParent));
            }

            if ((currentParent = VisualTreeHelper.GetParent(child)) != null)
            {
                throw new InvalidOperationException(SR.Get(SRID.CreateRootPopup_ChildHasVisualParent, child, currentParent));
            }

            // PlacementTarget must be set before hooking up the child so that resource
            // lookups can work.  The Popup for tooltip and context menu isn't in the tree
            // so FE relies on GetUIParentCore to return the placement target as the
            // effective logical parent
            Binding binding = new Binding("PlacementTarget");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(PlacementTargetProperty, binding);

            // NOTE: this will hook up child as a logical child of Popup.
            // If at a later date this is not desired, then modify the hookup to avoid the logical hookup.
            //
            // NOTE: Logical linking is necessary if property invalidations are to propagate down
            // the tree into the child (unless at a later date an alternate method has been created).
            popup.Child = child;

            binding = new Binding("VerticalOffset");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(VerticalOffsetProperty, binding);

            binding = new Binding("HorizontalOffset");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(HorizontalOffsetProperty, binding);

            binding = new Binding("PlacementRectangle");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(PlacementRectangleProperty, binding);

            binding = new Binding("Placement");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(PlacementProperty, binding);

            binding = new Binding("StaysOpen");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(StaysOpenProperty, binding);

            binding = new Binding("CustomPopupPlacementCallback");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(CustomPopupPlacementCallbackProperty, binding);

            // Note: IsOpen should always be last in this method
            binding = new Binding("IsOpen");
            binding.Mode = BindingMode.OneWay;
            binding.Source = child;
            popup.SetBinding(IsOpenProperty, binding);
        }