Exemplo n.º 1
0
        private void UnderlineContentPresenterText()
        {
            ContentPresenter?contentPresenter = null;

            var contentPresenterPart = GetTemplateChild(ContentPresenterName);

            if (contentPresenterPart != null)
            {
                var contentPresenterPartDO = contentPresenterPart;
                if (contentPresenterPartDO != null)
                {
                    contentPresenter = contentPresenterPartDO as ContentPresenter;
                }

                // If the ContentPresenter in the default template is present, and the TextBlock is one which is
                // generated in ContentPresenter code behind as default, only then do we proceed with the underline.
                if (contentPresenter != null && contentPresenter.IsUsingDefaultTemplate)
                {
                    // TODO Uno: Using ContentPresenter.ContentTemplateRoot instead of this.ContentTemplateRoot, which is null.
                    var contentTemplateRootAsIUIE       = contentPresenter.ContentTemplateRoot;
                    var contentTemplateRootAsITextBlock = contentTemplateRootAsIUIE as TextBlock;
                    if (contentTemplateRootAsITextBlock != null)
                    {
                        contentTemplateRootAsITextBlock.TextDecorations = TextDecorations.Underline;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateHeaderVisibility()
        {
            var headerVisibility = (Header != null || HeaderTemplate != null)
                                        ? Visibility.Visible
                                        : Visibility.Collapsed;

            if (headerVisibility == Visibility.Visible && _headerContentPresenter == null)
            {
                _headerContentPresenter = this.GetTemplateChild("HeaderContentPresenter") as ContentPresenter;
                if (_headerContentPresenter != null)
                {
                    // On Windows, all interactions involving the HeaderContentPresenter don't seem to affect the ComboBox.
                    // For example, hovering/pressing doesn't trigger the PointOver/Pressed visual states. Tapping on it doesn't open the drop down.
                    // This is true even if the Background of the root of ComboBox's template (which contains the HeaderContentPresenter) is set.
                    // Interaction with any other part of the control (including the root) triggers the corresponding visual states and actions.
                    // It doesn't seem like the HeaderContentPresenter consumes (Handled = true) events because they are properly routed to the ComboBox.

                    // My guess is that ComboBox checks whether the OriginalSource of Pointer events is a child of HeaderContentPresenter.

                    // Because routed events are not implemented yet, the easy workaround is to prevent HeaderContentPresenter from being hit.
                    // This only works if the background of the root of ComboBox's template is null (which is the case by default).
                    _headerContentPresenter.IsHitTestVisible = false;
                }
            }

            if (_headerContentPresenter != null)
            {
                _headerContentPresenter.Visibility = headerVisibility;
            }
        }
Exemplo n.º 3
0
        private ContentPresenter?CreateChildContentPresenter(object?item)
        {
            if (item is null)
            {
                return(null);
            }

            ContentPresenter?cp = FindChildContentPresenter(item);

            if (cp is not null)
            {
                return(cp);
            }

            // the actual child to be added.  cp.Tag is a reference to the TabItem
            cp = new ContentPresenter();
            if (item is TabItem tabItem)
            {
                cp.Content = tabItem.Content;
            }
            else
            {
                cp.Content = item;
            }
            cp.ContentTemplate         = SelectedContentTemplate;
            cp.ContentTemplateSelector = SelectedContentTemplateSelector;
            cp.ContentStringFormat     = SelectedContentStringFormat;
            cp.Visibility = Visibility.Collapsed;
            cp.Tag        = (item is TabItem) ? item : (ItemContainerGenerator.ContainerFromItem(item));
            _itemsHolderPanel !.Children.Add(cp);
            return(cp);
        }
Exemplo n.º 4
0
        public override void OnApplyTemplate()
        {
            //label = GetTemplateChild("PART_Label") as Label ?? throw new NullReferenceException("PART_Label object is null");
            hintBox = GetTemplateChild("HintTextBox") as TextBlock ?? throw new NullReferenceException("HintTextBox object is null");
            label   = GetTemplateChild("PART_HeaderPresenter") as ContentPresenter;
            //this.WhenAnyValue(a => a.Header)
            //    .BindTo(label, a => a.Content);

            //Binding parentBinding = bindingExpression.ParentBinding;
            //textBox2.SetBinding(TextBox.TextProperty, parentBinding);

            this.WhenAnyValue(a => a.Hint)
            .BindTo(hintBox, a => a.Text);

            this.WhenAnyValue(a => a.HintColor)
            .Select(a => new SolidColorBrush {
                Color = a
            })
            .BindTo(hintBox, a => a.Foreground);

            //if (Header != null)
            //    label.Content = Header;
            SetupAnimation();
            base.OnApplyTemplate();
        }
Exemplo n.º 5
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_popup is PopupBase oldPopup)
            {
                oldPopup.CustomLayouter = null;
            }

            _popup                = this.GetTemplateChild("Popup") as IPopup;
            _popupBorder          = this.GetTemplateChild("PopupBorder") as Border;
            _contentPresenter     = this.GetTemplateChild("ContentPresenter") as ContentPresenter;
            _placeholderTextBlock = this.GetTemplateChild("PlaceholderTextBlock") as TextBlock;

            if (_popup is PopupBase popup)
            {
                popup.CustomLayouter = new DropDownLayouter(this, popup);

                popup.BindToEquivalentProperty(this, nameof(LightDismissOverlayMode));
                popup.BindToEquivalentProperty(this, nameof(LightDismissOverlayBackground));
            }

            UpdateHeaderVisibility();
            UpdateContentPresenter();

            if (_contentPresenter != null)
            {
                _contentPresenter.SynchronizeContentWithOuterTemplatedParent = false;

                var thisRef = (this as IWeakReferenceProvider).WeakReference;
                _contentPresenter.DataContextChanged += (snd, evt) =>
                {
                    if (thisRef.Target is ComboBox that)
                    {
                        // The ContentPresenter will automatically clear its local DataContext
                        // on first load.
                        //
                        // When there's no selection, this will cause this ContentPresenter to
                        // received the same DataContext as the ComboBox itself, which could
                        // lead to strange result or errors.
                        //
                        // See comments in ContentPresenter.ResetDataContextOnFirstLoad() method.
                        // Fixed in this PR: https://github.com/unoplatform/uno/pull/1465

                        if (evt.NewValue != null && that.SelectedItem == null && that._contentPresenter != null)
                        {
                            that._contentPresenter.DataContext = null;                             // Remove problematic inherited DataContext
                        }
                    }
                };

                UpdateCommonStates();
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            this.dropDownButton = this.GetTemplateChild("PART_ToggleButton") as ToggleButton;
            if (this.dropDownButton is ISimplifiedStateControl control)
            {
                control.UpdateSimplifiedState(this.IsSimplified);
            }

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta -= this.OnResizeVerticalDelta;
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta += this.OnResizeVerticalDelta;
            }

            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta -= this.OnResizeBothDelta;
            }

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;
            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta += this.OnResizeBothDelta;
            }

            this.menuPanel = this.GetTemplateChild("PART_MenuPanel") as Panel;

            this.snappedImage = this.GetTemplateChild("PART_SelectedImage") as Image;
            this.contentSite  = this.GetTemplateChild("PART_ContentSite") as ContentPresenter;

            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown -= this.OnContentBorderPreviewMouseDown;
            }

            this.contentBorder = this.GetTemplateChild("PART_ContentBorder") as Border;
            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown += this.OnContentBorderPreviewMouseDown;
            }

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;

            this.dropDownBorder = this.GetTemplateChild("PART_DropDownBorder") as Border;

            base.OnApplyTemplate();
        }
Exemplo n.º 7
0
        private static bool TryGetDropTarget(object sender, [NotNullWhen(true)] out ContentPresenter?target)
        {
            target = null;
            if (sender is ContentPresenter {
                Content : null
            } cp)
            {
                target = cp;
            }

            return(target != null);
        }
Exemplo n.º 8
0
        private static bool TryGetDropTarget(object sender, [NotNullWhen(true)] out ContentPresenter?target)
        {
            target = null;
            if (sender is ContentPresenter {
                Content : null
            } cp)
            {
                target = cp;
            }

#pragma warning disable CA1508 // Avoid dead conditional code, analyzer broken
            return(target != null);

#pragma warning restore CA1508 // Avoid dead conditional code
        }
Exemplo n.º 9
0
        private void HandleDragStart <TViewModel>(PointerPressedEventArgs e, string format)
            where TViewModel : class
        {
            ContentPresenter?listViewItem = (e.Source as IControl)?.FindAnchestor <ContentPresenter>();

            if (listViewItem == null)
            {
                return;
            }

            this.startPoint = e.GetPosition(this);
            this.isDragging = false;

            this.dragData = new DataObject();
            this.dragData.Set(format, listViewItem.Content);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     When the items change we remove any generated panel children and add any new ones as necessary
        /// </summary>
        /// <param name="e"></param>
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            if (_itemsHolderPanel == null)
            {
                return;
            }

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Reset:
                _itemsHolderPanel.Children.Clear();
                break;

            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:
                if (e.OldItems != null)
                {
                    foreach (object item in e.OldItems)
                    {
                        ContentPresenter?cp = FindChildContentPresenter(item);
                        if (cp is not null)
                        {
                            _itemsHolderPanel.Children.Remove(cp);
                        }
                    }
                }

                // Don't do anything with new items because we don't want to
                // create visuals that aren't being shown

                UpdateSelectedItem();
                break;

            case NotifyCollectionChangedAction.Replace:
                throw new NotImplementedException("Replace not implemented yet");
            }
        }
Exemplo n.º 11
0
        internal void SetPublicRootVisual(UIElement?publicRootVisual, ScrollViewer?rootScrollViewer, ContentPresenter?rootContentPresenter)
        {
            // NOTE: This doesn't check for the root scroll viewer changing independently of the root visual.
            if (publicRootVisual == PublicRootVisual)
            {
                return;
            }

            // If the public root visual changes, we need to remove and re-add the existing roots so that
            // they use the new public visual as namescope owner if needed, but we don't want to release them.
            //
            // Note: This needs to be done even if the public root visual is null. The app can explicitly set
            // a null root, which will cause us to create the popup/print/transition/media root elements. When
            // the app sets a non-null root later, we have to make sure to not add those elements a second time.
            ResetRoots();

            PublicRootVisual     = publicRootVisual;
            RootScrollViewer     = rootScrollViewer;
            RootContentPresenter = rootContentPresenter;

            //EnsureVisualDiagnosticsRoot();
            //EnsureXamlIslandRootCollection();
            //EnsureConnectedAnimationRoot();
                        #if !__MACOS__
            EnsurePopupRoot();
                        #endif

            //TODO Uno specific: We require some additional layers on top
            EnsureFocusVisualRoot();

            //EnsurePrintRoot();
            //EnsureTransitionRoot();
            EnsureFullWindowMediaRoot();

            //if (_pCoreNoRef.IsInBackgroundTask())
            //{
            //	EnsureRenderTargetBitmapRoot());
            //}

            //if (publicRootVisual != null)
            //{
            //	// A visual set as the root of the tree implicitly becomes a permanent
            //	// namescope owner, and will always have a name store.
            //	publicRootVisual.IsStandardNameScopeOwner = true;
            //	publicRootVisual.IsStandardNameScopeMember = false;
            //}

            //TODO Uno specific - we need to add the public content first, until
            //https://github.com/unoplatform/uno/issues/325 is properly supported.
            if (PublicRootVisual != null)
            {
                if (RootScrollViewer != null)
                {
                    //// A visual set as the root SV of the tree implicitly becomes a permanent
                    //// namescope owner, and will always have a name store.
                    //_rootScrollViewer.tIsStandardNameScopeOwner = true;
                    //_rootScrollViewer.IsStandardNameScopeMember = false;

                    //// Add the visual root as the child of the root ScrollViwer
                    //AddVisualRootToRootScrollViewer(PublicRootVisual);

                    //// Add the root ScrollViewer to the hidden root visual
                    //AddRootScrollViewer(RootScrollViewer);

                    //_bIsRootScrollViewerAddedToRoot = true;
                }
                else
                {
                    AddRoot(PublicRootVisual);
                }

                //_pCoreNoRef.RaisePendingLoadedRequests();
            }

            // Re-enter the roots with the new public root's namescope.
            //AddRoot(_visualDiagnosticsRoot));
            //AddRoot(_xamlIslandRootCollection));
            //AddRoot(_connectedAnimationRoot));
            AddRoot(FullWindowMediaRoot);

            AddRoot(PopupRoot);

            //AddRoot(_printRoot));
            //AddRoot(_transitionRoot));

            //TODO Uno specific: Focus visual layer
            AddRoot(FocusVisualRoot);

            //if (_pCoreNoRef.IsInBackgroundTask())
            //{
            //	AddRoot(_renderTargetBitmapRoot));
            //}
        }