コード例 #1
0
 /// <summary>
 /// Plays media from the current position.
 /// </summary>
 public void Play()
 {
     if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
     {
         if (_mediaElement != null)
         {
             INTERNAL_HtmlDomManager.CallDomMethod(_mediaElement, "play");
         }
         else if (_mediaElement_ForAudioOnly_ForSimulatorOnly != null)
         {
             _mediaElement_ForAudioOnly_ForSimulatorOnly.Play();
         }
     }
 }
コード例 #2
0
 void ManageDomBoolProperty_Changed(string htmlPropertyName, bool newValue)
 {
     if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) && _mediaElement != null)
     {
         if (newValue)
         {
             INTERNAL_HtmlDomManager.SetDomElementAttribute(_mediaElement, htmlPropertyName, "true");
         }
         else
         {
             INTERNAL_HtmlDomManager.RemoveDomElementAttribute(_mediaElement, htmlPropertyName, forceSimulatorExecuteImmediately: true);
         }
     }
 }
コード例 #3
0
 void ManageVolume_Changed()
 {
     if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
     {
         if (_mediaElement != null)
         {
             INTERNAL_HtmlDomManager.SetDomElementProperty(_mediaElement, "volume", Volume);
         }
         else if (_mediaElement_ForAudioOnly_ForSimulatorOnly != null)
         {
             _mediaElement_ForAudioOnly_ForSimulatorOnly.Pause();
         }
     }
 }
コード例 #4
0
ファイル: StackPanel.cs プロジェクト: modulexcite/OpenSilver
        static void Orientation_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var         stackPanel = (StackPanel)d;
            Orientation newValue   = (Orientation)e.NewValue;

            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(stackPanel) &&
                stackPanel._renderedOrientation.HasValue &&
                stackPanel._renderedOrientation.Value != newValue)
            {
                //todo: refresh the whole stackpanel (so that we display the children in the right orientation)

                throw new NotSupportedException("Changing the orientation of a StackPanel while it is in the visual tree is not yet supported.");
            }
        }
コード例 #5
0
ファイル: AutoCompleteBox.cs プロジェクト: qasimnaeem/CSHTML5
        protected override void ApplySelectedIndex(int index)
        {
            base.ApplySelectedIndex(index);


            UIElement newSelectedContent;

            if (index == -1)
            {
                // index is sometimes at -1, for exemple when the app is starting
                // not en exception but we don't want to treat it as there is no item
                newSelectedContent = null;
            }
            else if (this.Items != null && index < this.Items.Count)
            {
                var item = this.Items[index];

                // If the item is a FrameworkElement, we detach it from its current parent (if any) so that we can later put it into the ContentPresenter:
                if (item is FrameworkElement)
                {
                    // Detach it from the current parent:
                    if (((FrameworkElement)item).INTERNAL_VisualParent is UIElement)
                    {
                        INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(((FrameworkElement)item), (UIElement)((FrameworkElement)item).INTERNAL_VisualParent);
                    }
                }
                else if (item != null)
                {
                    // Otherwise, we create a FrameworkElement out of the item:
                    item = GenerateFrameworkElementToRenderTheItem(item);
                }

                newSelectedContent = (FrameworkElement)item; // Note: this can be null.

                if (_textBox != null)
                {
                    if (newSelectedContent is TextBlock)
                    {
                        TextBlock textblock = (TextBlock)newSelectedContent;
                        _textBox.Text = textblock.Text;
                    }
                }
            }
            else
            {
                throw new IndexOutOfRangeException();
            }

            _selectedContent = newSelectedContent;
        }
コード例 #6
0
ファイル: SelectorItem.cs プロジェクト: vladfe123/OpenSilver
        virtual internal protected void HandleIsSelectedChanged(bool oldValue, bool newValue)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
            {
                //todo: remove what's inside the "if" above once we will have defined a default style for the ItemsControl, that does about the same thing.
                if (INTERNAL_ParentSelectorControl != null)
                {
                    Selector selector = INTERNAL_ParentSelectorControl;

                    if (selector.ItemContainerStyle == null)
                    {
                        //bool newValue = (bool)e.NewValue;
                        if (newValue != oldValue)
                        {
                            if (newValue)
                            {
                                // Remember the values of the Background and Foreground before selection, in order to be able to revert them back when needed:
                                _backgroundBeforeBeingSelected = this.Background;
                                _foregroundBeforeBeingSelected = this.Foreground;
                                _hasEverBeenSelected           = true;

                                // Set the Background and Foreground:
                                this.Background = selector.SelectedItemBackground;
                                this.Foreground = selector.SelectedItemForeground;
                            }
                            else
                            {
                                // Restore the Background and Foreground that the item had before being selected:
                                if (_hasEverBeenSelected)
                                {
                                    this.Background = _backgroundBeforeBeingSelected;
                                    this.Foreground = _foregroundBeforeBeingSelected;
                                }
                                //selectorItem.Background = selector.UnselectedItemBackground ?? selector.Background;
                                //selectorItem.Foreground = selector.UnselectedItemForeground ?? selector.Foreground;
                            }
                        }
                    }
                }
            }
            if (newValue)
            {
                VisualStateManager.GoToState(this, "Selected", false);
            }
            else
            {
                VisualStateManager.GoToState(this, "Unselected", false);
            }
        }
コード例 #7
0
        internal void OnMaxLengthChanged(int maxLength)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) &&
                INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                if (!IsRunningInJavaScript())
                {
                    //--- SIMULATOR ONLY: ---
                    // Set the "data-maxlength" property (that we have made up) so that the "keydown" JavaScript event can retrieve this value:
                    INTERNAL_HtmlDomManager.ExecuteJavaScript($@"
var element = document.getElementByIdSafe(""{((INTERNAL_HtmlDomElementReference)_contentEditableDiv).UniqueIdentifier}"");
element.setAttribute(""data-maxlength"", ""{maxLength}"");");
                }
            }
        }
コード例 #8
0
        internal void OnAcceptsReturnChanged(bool acceptsReturn)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) &&
                INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                if (!IsRunningInJavaScript())
                {
                    //--- SIMULATOR ONLY: ---
                    // Set the "data-accepts-return" property (that we have invented) so that the "keydown" JavaScript event can retrieve this value:
                    INTERNAL_HtmlDomManager.ExecuteJavaScript($@"
var element = document.getElementByIdSafe(""{((INTERNAL_HtmlDomElementReference)_contentEditableDiv).UniqueIdentifier}"");
element.setAttribute(""data-acceptsreturn"", ""{acceptsReturn.ToString().ToLower()}"");");
                }
            }
        }
コード例 #9
0
ファイル: Panel.cs プロジェクト: ashotkhachatryan/OpenSilver
        private async void ProgressivelyAttachChildren(IList <UIElement> newChildren)
        {
            for (int i = 0; i < newChildren.Count; ++i)
            {
                await Task.Delay(1);

                if (!INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
                {
                    //this can happen if the Panel is detached during the delay.
                    break;
                }
                INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(newChildren[i], this);
                INTERNAL_OnChildProgressivelyLoaded();
            }
        }
コード例 #10
0
        private async void ProgressivelyAttachChildren(UIElementCollection newChildren)
        {
            foreach (UIElement child in newChildren)
            {
                await Task.Delay(1);

                if (!INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
                {
                    //this can happen if the Panel is detached during the delay.
                    break;
                }
                INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(child, this);
                INTERNAL_OnChildProgressivelyLoaded();
            }
        }
コード例 #11
0
ファイル: Panel.cs プロジェクト: ag-csharp/OpenSilver
        internal virtual void OnChildrenReplaced(UIElement oldChild, UIElement newChild, int index)
        {
            if (oldChild == newChild)
            {
                return;
            }

            INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(oldChild, this);

#if REWORKLOADED
            this.AddVisualChild(newChild, index);
#else
            INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(newChild, this, index);
#endif
        }
コード例 #12
0
 internal protected virtual void ManageIsEnabled(bool isEnabled)
 {
     if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
     {
         var domElementToEnableOrDisable = (INTERNAL_OptionalSpecifyDomElementConcernedByIsEnabled != null ? INTERNAL_OptionalSpecifyDomElementConcernedByIsEnabled : INTERNAL_OuterDomElement);
         if (isEnabled)
         {
             INTERNAL_HtmlDomManager.RemoveDomElementAttribute(domElementToEnableOrDisable, "disabled", forceSimulatorExecuteImmediately: true);
         }
         else
         {
             INTERNAL_HtmlDomManager.SetDomElementAttribute(domElementToEnableOrDisable, "disabled", true, forceSimulatorExecuteImmediately: true);
         }
     }
 }
コード例 #13
0
ファイル: PasswordBox.cs プロジェクト: zeta1999/OpenSilver
        static void Password_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var passwordBox = (PasswordBox)d;

            if (!passwordBox._isUserChangingPassword)
            {
                passwordBox._isCodeProgrammaticallyChangingPassword = true; // So that when the c# caller sets the password programmatically, it does not get set multiple times.
                string newPassword = e.NewValue as string ?? string.Empty;
                if (INTERNAL_VisualTreeManager.IsElementInVisualTree(passwordBox))
                {
                    INTERNAL_HtmlDomManager.SetUIElementContentString(passwordBox, newPassword);
                }
                passwordBox._isCodeProgrammaticallyChangingPassword = false;
            }
        }
コード例 #14
0
ファイル: Border.cs プロジェクト: ag-csharp/OpenSilver
        protected internal override void INTERNAL_OnAttachedToVisualTree()
        {
            base.INTERNAL_OnAttachedToVisualTree();

            if (this.BorderBrush == null)
            {
                INTERNAL_PropertyStore.ApplyCssChanges(null, null, Border.BorderBrushProperty.GetMetadata(typeof(Border)), this);
            }

#if REWORKLOADED
            this.AddVisualChild(this._child);
#else
            INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(_child, this);
#endif
        }
コード例 #15
0
ファイル: Border.cs プロジェクト: salvrtsy/OpenSilver
        private async void ProgressivelyAttachChild()
        {
            await Task.Delay(1);

            if (!INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
            {
                //this can happen if the Panel is detached during the delay.
                return;
            }
#if REWORKLOADED
            this.AddVisualChild(this._child);
#else
            INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(_child, this);
#endif
        }
コード例 #16
0
ファイル: ComboBox.cs プロジェクト: rjmcguire/CSHTML5
        public void SetSelectedIndexInNativeHtmlDom(int value)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) && _nativeComboBoxDomElement != null)
            {
                int selectedIndexInHtmlDom = value;

                // Compensate for the fact that the ComboBox contains an empty element at the beginning (see note in the CreateDomElement method):
                if (selectedIndexInHtmlDom >= 0)
                {
                    selectedIndexInHtmlDom += 1;
                }

                INTERNAL_HtmlDomManager.SetDomElementProperty(_nativeComboBoxDomElement, "selectedIndex", selectedIndexInHtmlDom, forceSimulatorExecuteImmediately: true);
            }
        }
コード例 #17
0
ファイル: Shape.cs プロジェクト: xiongzhaoxu/CSHTML5
        /// <summary>
        /// This is used to redraw only once instead of on every property change.
        /// </summary>
        internal void ScheduleRedraw()
        {
            if (!_redrawPending) // This ensures that the "BeginInvoke" method is only called once, and it is not called again until its delegate has been executed.
            {
                if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
                {
                    _redrawPending = true;
                    INTERNAL_DispatcherHelpers.QueueAction(() => // We use a dispatcher to avoid redrawing every time that a dependency property is set (the result is as if we waited for the last property to be set). We use "INTERNAL_DispatcherHelpers.QueueAction" instead of "Dispatcher.BeginInvoke" because it has better performance than calling Dispatcher.BeginInvoke directly.
                    {
                        _redrawPending = false;

                        // We check whether the Shape is visible in the HTML DOM tree, because if the HTML canvas is hidden (due to a "Dispay:none" on one of the ancestors), we cannot draw on it (this can be seen by hiding a canvas, drawing, and then showing it: it will appear empty):
                        if (INTERNAL_VisibilityChangedNotifier.IsElementVisible(this))
                        {
                            Redraw();

                            // Stop listening to the ancestors' Visibility_Changed, if it was listening:
                            if (_isListeningToAncestorsVisibilityChanged)
                            {
                                INTERNAL_VisibilityChangedNotifier.StopListeningToAncestorsVisibilityChanged(this);
                            }
                            _isListeningToAncestorsVisibilityChanged = false;
                        }
                        else
                        {
                            // We listen to the Visibility_Changed event of the ancestors so as try again if a parent becomes visible:
                            if (!_isListeningToAncestorsVisibilityChanged)
                            {
                                _isListeningToAncestorsVisibilityChanged = true;
                                INTERNAL_VisibilityChangedNotifier.StartListeningToAncestorsVisibilityChanged(this,
                                                                                                              () =>
                                {
                                    // Stop listening to the ancestors' Visibility_Changed:
                                    if (_isListeningToAncestorsVisibilityChanged)
                                    {
                                        INTERNAL_VisibilityChangedNotifier.StopListeningToAncestorsVisibilityChanged(this);
                                    }
                                    _isListeningToAncestorsVisibilityChanged = false;

                                    // Try again:
                                    ScheduleRedraw();
                                });
                            }
                        }
                    });
                }
            }
        }
コード例 #18
0
ファイル: ItemsControl.cs プロジェクト: xiongzhaoxu/CSHTML5
        protected override void OnApplyTemplate()
#endif
        {
            base.OnApplyTemplate();

            // Attempt to find the <ItemsPresenter /> in the ControlTemplate and, if it was found, use it as the place where all the items should be added:
            ItemsPresenter itemsPresenter = INTERNAL_VisualTreeManager.GetChildOfType <ItemsPresenter>(this);

            if (itemsPresenter != null)
            {
                _placeWhereItemsPanelWillBeRendered = itemsPresenter;
            }

            // Update the ItemsPanel:
            UpdateItemsPanel(ItemsPanel);
        }
コード例 #19
0
ファイル: Image.cs プロジェクト: interlocksystems/CSHTML5
        static void Stretch_Changed(DependencyObject i, DependencyPropertyChangedEventArgs e)
        {
            var     image    = (Image)i;
            Stretch newValue = (Stretch)e.NewValue;

            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(image))
            {
                string objectFitvalue = "";
                string objectPosition = "center top"; //todo: see if the values are correct for this and if it should take into consideration the Vertical/HorizontalAlignment.
                switch (newValue)
                {
                case Stretch.None:
                    //img.width = "auto";
                    //img.height = "auto";
                    objectFitvalue = "none";
                    objectPosition = "left top";
                    break;

                case Stretch.Fill:
                    // Commented because it should be the same as the one set by the FrameworkElement Width/Height.
                    //img.width = "100%";
                    //img.height = "100%";
                    objectFitvalue = "100% 100%";
                    objectPosition = "center center";
                    break;

                case Stretch.Uniform:     //todo: make it work when the image needs to be made bigger to fill the container
                    //img.maxWidth = "100%";
                    //img.maxHeight = "100%";
                    objectFitvalue = "contain";
                    objectPosition = "center center";
                    break;

                case Stretch.UniformToFill:     //todo: add a negative margin top and left so that the image is centered
                    //img.minWidth = "100%";
                    //img.minHeight = "100%";
                    objectFitvalue = "cover";
                    objectPosition = "left top";
                    break;

                default:
                    break;
                }
                CSHTML5.Interop.ExecuteJavaScript(@"$0.style.objectFit = $1;
$0.style.objectPosition = $2", image._imageDiv, objectFitvalue, objectPosition);
            }
        }
コード例 #20
0
ファイル: Path.cs プロジェクト: xiongzhaoxu/CSHTML5
        //protected internal override void INTERNAL_OnAttachedToVisualTree()
        //{
        //    ScheduleRedraw();
        //}

        protected internal override void Redraw()
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
            {
                if (Data != null)
                {
                    double minX = double.MaxValue;
                    double minY = double.MaxValue;
                    double maxX = double.MinValue;
                    double maxY = double.MinValue;
                    if (Data is PathGeometry)
                    {
                        ((PathGeometry)Data).UpdateStrokeThickness(StrokeThickness);
                    }
                    Data.GetMinMaxXY(ref minX, ref maxX, ref minY, ref maxY);

                    Size shapeActualSize;
                    INTERNAL_ShapesDrawHelpers.PrepareStretch(this, _canvasDomElement, minX, maxX, minY, maxY, Stretch, out shapeActualSize);
                    double horizontalMultiplicator;
                    double verticalMultiplicator;
                    double xOffsetToApplyBeforeMultiplication;
                    double yOffsetToApplyBeforeMultiplication;
                    double xOffsetToApplyAfterMultiplication;
                    double yOffsetToApplyAfterMultiplication;
                    double strokeThickness = StrokeThickness;
                    if (Stroke == null)
                    {
                        strokeThickness = 0;
                    }

                    INTERNAL_ShapesDrawHelpers.GetMultiplicatorsAndOffsetForStretch(this, strokeThickness, minX, maxX, minY, maxY, Stretch, shapeActualSize, out horizontalMultiplicator, out verticalMultiplicator, out xOffsetToApplyBeforeMultiplication, out yOffsetToApplyBeforeMultiplication, out xOffsetToApplyAfterMultiplication, out yOffsetToApplyAfterMultiplication, out _marginOffsets);

                    ApplyMarginToFixNegativeCoordinates(new Point());
                    if (Stretch == Stretch.None)
                    {
                        ApplyMarginToFixNegativeCoordinates(_marginOffsets);
                    }

                    // A call to "context.beginPath" is required on IE and Edge for the figures to be drawn properly (cf. ZenDesk #971):
                    CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.getContext('2d').beginPath()", _canvasDomElement);

                    //problem here: the shape seems to be overall smaller than intended due to the edges of the path not being sharp?
                    Data.DefineInCanvas(this, _canvasDomElement, horizontalMultiplicator, verticalMultiplicator, xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, xOffsetToApplyAfterMultiplication, yOffsetToApplyAfterMultiplication, shapeActualSize); //puts the lines and stuff in the context
                    Shape.DrawFillAndStroke(this, Data.GetFillRuleAsString(), minX, minY, maxX, maxY, horizontalMultiplicator, verticalMultiplicator, xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, shapeActualSize);
                }
            }
        }
コード例 #21
0
        private void ColumnDefinitions_CollectionChanged_CSSVersion(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
            {
                if (e.NewItems != null)
                {
                    Grid_InternalHelpers.RefreshAllColumnsWidth_CSSVersion(this);
                }

                if (this._isLoaded)
                {
                    Grid_InternalHelpers.RefreshAllColumnsWidth_CSSVersion(this);

                    LocallyManageChildrenChanged();
                }
            }
        }
コード例 #22
0
        private object FindAncestor(DependencyObject target, RelativeSource relativeSource)
        {
            // todo: support bindings in style setters and then remove the following test.
            // To reproduce the issue:
            // <Style x:Key="LegendItemControlStyle"
            //        TargetType="legend:LegendItemControl">
            //   <Setter Property="DefaultMarkerGeometry"
            //           Value="{Binding DefaultMarkerGeometry, RelativeSource={RelativeSource AncestorType=telerik:RadLegend}}"/>
            // </Style>
            if (!(target is UIElement uiE))
            {
                return(null);
            }

            // make sure the target is in the visual tree:
            if (!INTERNAL_VisualTreeManager.IsElementInVisualTree(uiE))
            {
                return(null);
            }

            // get the AncestorLevel and AncestorType:
            int  ancestorLevel = relativeSource.AncestorLevel;
            Type ancestorType  = relativeSource.AncestorType;

            if (ancestorLevel < 1 || ancestorType == null)
            {
                return(null);
            }

            // look for the target's ancestor:
            UIElement currentParent = (UIElement)uiE.INTERNAL_VisualParent;

            while (!ancestorType.IsAssignableFrom(currentParent.GetType()) || --ancestorLevel > 0)
            {
                currentParent = (UIElement)currentParent.INTERNAL_VisualParent;
                if (currentParent == null)
                {
                    return(null);
                }
            }
            if (ancestorLevel == 0)
            {
                return(currentParent);
            }
            return(null);
        }
コード例 #23
0
ファイル: ItemsControl.cs プロジェクト: xiongzhaoxu/CSHTML5
        protected virtual void UpdateItemsPanel(ItemsPanelTemplate newTemplate)
        {
            if (!_disableDefaultRendering)
            {
                if (_placeWhereItemsPanelWillBeRendered != null
                    //&& INTERNAL_VisualTreeManager.IsElementInVisualTree(_placeWhereItemsPanelWillBeRendered))
                    && _placeWhereItemsPanelWillBeRendered._isLoaded) //Note: we replaced "IsElementInVisualTree" with _isLoaded on on March 22, 2017 to fix an issue where a "Binding" on ListBox.ItemsSource caused the selection to not work properly. This change can be reverted the day that the implementation of the "IsElementInVisualTree" method becomes based on the "_isLoaded" property (at the time of writing, it was implemented by checking if the visual parent is null).
                {
                    INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(this._renderedItemsPanel, _placeWhereItemsPanelWillBeRendered);

                    if (newTemplate != null)
                    {
                        // Create an instance of the Panel:
                        _renderedItemsPanel = newTemplate.INTERNAL_InstantiateFrameworkTemplate();

                        // Make sure the panel derives from the type "Panel":
                        if (!(_renderedItemsPanel is Panel))
                        {
                            throw new InvalidOperationException("ItemsControl.ItemsPanelTemplate must derive from Panel.");
                        }

                        // Make sure that the panel contains no children:
                        if (((Panel)_renderedItemsPanel).Children != null && ((Panel)_renderedItemsPanel).Children.Count > 0)
                        {
                            throw new InvalidOperationException("Cannot explicitly modify Children collection of Panel used as ItemsPanel for ItemsControl. ItemsControl generates child elements for Panel.");
                        }

                        // Attach the panel:
                        INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(_renderedItemsPanel, _placeWhereItemsPanelWillBeRendered);

                        // Update the children:
                        if (_actualItemsSource != null)
                        {
                            OnItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                            UpdateChildrenInVisualTree(_actualItemsSource, _actualItemsSource, forceUpdateAllChildren: true);
                        }
                    }
                    else
                    {
                        // The ItemsPanel is null, so we display nothing (like in WPF):
                        _renderedItemsPanel = null;
                        _itemContainerGenerator.INTERNAL_Clear();
                    }
                }
            }
        }
コード例 #24
0
ファイル: Popup.cs プロジェクト: qasimnaeem/CSHTML5
        private void RefreshPopupPosition(Point placementTargetPosition, Size placementTargetSize)
        {
            //we check if there is a placementTarget, if yes, if it is no longer in the visual tree, we remove it from the PositionsWatcher:
            if (PlacementTarget != null && !INTERNAL_VisualTreeManager.IsElementInVisualTree(PlacementTarget))
            {
                Window.Current.INTERNAL_PositionsWatcher.RemoveControlToWatch(_controlToWatch);
                HidePopupRootIfVisible();
            }
            else if (PlacementTarget != null)
            {
                //We change the position so that the popup goes to the correct relative position:
                switch (Placement)
                {
                case PlacementMode.Bottom:
                    if (!double.IsNaN(placementTargetSize.Height))
                    {
                        placementTargetPosition.Y += placementTargetSize.Height;
                    }
                    break;

                //case PlacementMode.Right:
                //    break;
                //case PlacementMode.Mouse:
                //    break;
                //case PlacementMode.Left:
                //    break;
                //case PlacementMode.Top:
                //    break;
                default:     //note: we currently consider Right as the default placement (only Bottom and Right are supported)
                    if (!double.IsNaN(placementTargetSize.Width))
                    {
                        placementTargetPosition.X += placementTargetSize.Width;
                    }
                    break;
                }

                HorizontalOffset = placementTargetPosition.X;
                VerticalOffset   = placementTargetPosition.Y;
            }

            // Raise the internal "PopupMoved" event, which is useful for example to hide the validation popups of TextBoxes in case the user scrolls and the TextBox is no longer visible on screen (cf. ZenDesk 628):
            if (INTERNAL_PopupMoved != null)
            {
                INTERNAL_PopupMoved(this, new EventArgs());
            }
        }
コード例 #25
0
ファイル: DataGridRow.cs プロジェクト: dragonxu/CSHTML5
        private static void HeaderTemplate_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataGridRow dataGridRow = (DataGridRow)d;

            if (dataGridRow != null)
            {
                if (INTERNAL_VisualTreeManager.IsElementInVisualTree(dataGridRow._datagrid))
                {
                    if (e.NewValue != e.OldValue)
                    {
                        if (dataGridRow._headerUIElement != null && INTERNAL_VisualTreeManager.IsElementInVisualTree(dataGridRow._headerUIElement))
                        {
                            //we remove the header that was there before the new one:
                            dataGridRow._datagrid.RemoveElementFromGrid(dataGridRow._headerUIElement);
                        }
                        //we add the new header
                        DataTemplate template = (DataTemplate)e.NewValue;
                        if (template != null)
                        {
                            dataGridRow._headerUIElement = template.INTERNAL_InstantiateFrameworkTemplate();
                            Grid.SetRow(dataGridRow._headerUIElement, dataGridRow._rowIndex);
                            Grid.SetColumn(dataGridRow._headerUIElement, 0);
                            if (dataGridRow._headerUIElement is FrameworkElement)
                            {
                                ((FrameworkElement)dataGridRow._headerUIElement).DataContext = dataGridRow;
                            }
                            bool isCSSGrid = Grid_InternalHelpers.isCSSGridSupported();
                            if (isCSSGrid)
                            {
                                if (dataGridRow._headerUIElement is Control)
                                {
                                    ((Control)dataGridRow._headerUIElement).BorderBrush     = dataGridRow._datagrid.HorizontalGridLinesBrush;
                                    ((Control)dataGridRow._headerUIElement).BorderThickness = new Thickness(1, 0, 1, 1);
                                }
                                else if (dataGridRow._headerUIElement is Border)
                                {
                                    ((Border)dataGridRow._headerUIElement).BorderBrush     = dataGridRow._datagrid.HorizontalGridLinesBrush;
                                    ((Border)dataGridRow._headerUIElement).BorderThickness = new Thickness(1, 0, 1, 1);
                                }
                            }
                            dataGridRow._datagrid.AddElementToGrid(dataGridRow._headerUIElement);
                        }
                    }
                }
            }
        }
コード例 #26
0
        internal virtual void ManageChildrenChanged(UIElementCollection oldChildren, UIElementCollection newChildren)
        {
            if (oldChildren != null)
            {
                // Detach old children only if they are not in the "newChildren" collection:
                foreach (UIElement child in oldChildren) //note: there is no setter for Children so the user cannot change the order of the elements in one step --> we cannot have the same children in another order (which would keep the former order with the way it is handled now) --> no problem here
                {
#if PERFSTAT
                    var t2 = Performance.now();
#endif
                    if (newChildren == null || !newChildren.Contains(child))
                    {
#if PERFSTAT
                        Performance.Counter("Panel.ManageChildrenChanged 'Contains'", t2);
#endif
                        INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(child, this);
                    }
                    else
                    {
#if PERFSTAT
                        Performance.Counter("Panel.ManageChildrenChanged 'Contains'", t2);
#endif
                    }
                }
            }
            if (newChildren != null)
            {
                // Note: we attach all the children (regardless of whether they are in the oldChildren collection or not) to make it work when the item is first added to the Visual Tree (at that moment, all the properties are refreshed by calling their "Changed" method).

                if (this.EnableProgressiveRendering)
                {
                    this.ProgressivelyAttachChildren(newChildren);
                }
                else
                {
                    foreach (UIElement child in newChildren)
                    {
#if REWORKLOADED
                        this.AddVisualChild(child);
#else
                        INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(child, this);
#endif
                    }
                }
            }
        }
コード例 #27
0
ファイル: Popup.cs プロジェクト: bamby084/OpenSilver
        private Point?CalculateReferencePosition(Window parentWindow)
        {
            UIElement placementTarget = this.PlacementTarget;

            if (placementTarget != null && INTERNAL_VisualTreeManager.IsElementInVisualTree(placementTarget))
            {
                GeneralTransform gt = placementTarget.TransformToVisual(parentWindow);
                Point            p  = gt.Transform(new Point(0d, 0d));
            }
            else if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this))
            {
                GeneralTransform gt = this.TransformToVisual(parentWindow);
                Point            p  = gt.Transform(new Point(0d, 0d));
                return(p);
            }
            return(new Point());
        }
コード例 #28
0
        private static void Width_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var columnDefinition = (ColumnDefinition)d;

            Grid grid = columnDefinition.Parent;

            if (grid != null &&
                INTERNAL_VisualTreeManager.IsElementInVisualTree(grid))
            {
                if (Grid_InternalHelpers.isCSSGridSupported())
                {
                    //-------------
                    // CSS Grid
                    //-------------

                    // We refresh all the columns:
                    Grid_InternalHelpers.RefreshAllColumnsWidth_CSSVersion(grid);
                }
                else
                {
                    //-------------
                    // Non-CSS Grid
                    //-------------

                    bool isStar = (e.OldValue != null && ((GridLength)e.OldValue).IsStar) || (e.NewValue != null && ((GridLength)e.NewValue).IsStar);
                    if (isStar)
                    {
                        // If we are dealing with a "Star" column, we need to refresh all the columns (because of the need to recalculate percentages normalization etc.):
                        Grid_InternalHelpers.RefreshAllColumnsWidth_NonCSSVersion(grid);
                    }
                    else
                    {
                        // Only refresh the current column:
                        if (grid._columnDefinitionsOrNull != null)
                        {
                            int  columnIndex     = grid._columnDefinitionsOrNull.IndexOf(columnDefinition);
                            bool isTheOnlyColumn = grid._columnDefinitionsOrNull == null || grid._columnDefinitionsOrNull.Count < 2;
                            Grid_InternalHelpers.RefreshColumnWidth_NonCSSVersion(grid, columnIndex, isTheOnlyColumn); //Note: we do not need to pass the normalized column definition because this method will only be called when we change the column's width without any star measurement involved (nor star before nor after).
                        }
                    }
                }
            }

            columnDefinition.Parent?.InvalidateMeasure();
        }
コード例 #29
0
        static void Orientation_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var         wrapPanel = (WrapPanel)d;
            Orientation newValue  = (Orientation)e.NewValue;

            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(wrapPanel))
            {
                if (newValue == Orientation.Vertical)
                {
                    throw new NotSupportedException("Vertical orientation is not yet supported for the WrapPanel");
                }
                else
                {
                    //todo: change all the wrappers of the children to set their style.display to inline-block
                    INTERNAL_HtmlDomManager.GetFrameworkElementOuterStyleForModification(wrapPanel).textAlign = "left";
                }
            }
        }
コード例 #30
0
        private void ChangeChild(object newChild)
        {
            this.DetachChild(); // Detach current child.

            UIElement newChildAsUIElement = newChild as UIElement;

            if (newChildAsUIElement != null)
            {
                INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(newChildAsUIElement, this);
                this.Child = newChildAsUIElement;
            }
            else
            {
                string contentAsString = newChild == null ? string.Empty : newChild.ToString();
                INTERNAL_HtmlDomManager.SetContentString(this, contentAsString, removeTextWrapping: true);
                this.Child = this; // In the case where the child is not an UIElement, we consider the child to be this Control because we don't add a child (we directly set the content of this element).
            }
        }