当前位置: 首页>>代码示例>>C#>>正文


C# GeneralTransformGroup.TryTransform方法代码示例

本文整理汇总了C#中System.Windows.Media.GeneralTransformGroup.TryTransform方法的典型用法代码示例。如果您正苦于以下问题:C# GeneralTransformGroup.TryTransform方法的具体用法?C# GeneralTransformGroup.TryTransform怎么用?C# GeneralTransformGroup.TryTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.GeneralTransformGroup的用法示例。


在下文中一共展示了GeneralTransformGroup.TryTransform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PlaceRibbonToolTip

        /// <summary>
        ///     RibbonToolTip custom placement logic
        /// </summary>
        /// <param name="popupSize">The size of the popup.</param>
        /// <param name="targetSize">The size of the placement target.</param>
        /// <param name="offset">The Point computed from the HorizontalOffset and VerticalOffset property values.</param>
        /// <returns>An array of possible tooltip placements.</returns>
        private CustomPopupPlacement[] PlaceRibbonToolTip(Size popupSize, Size targetSize, Point offset)
        {
            UIElement placementTarget = this.PlacementTarget;
            double belowOffsetY = 0.0;
            double aboveOffsetY = 0.0;
            double offsetX = FlowDirection == FlowDirection.LeftToRight ? 0.0 : -popupSize.Width;

            if (IsPlacementTargetInRibbonGroup)
            {
                // If the PlacementTarget is within a RibbonGroup we proceed
                // with the custom placement policy.

                // Walk up the visual tree from PlacementTarget to find the Ribbon
                // if exists or the root element which is likely a PopupRoot.
                Ribbon ribbon = null;
                DependencyObject rootElement = null;
                DependencyObject element = placementTarget;
                while (element != null)
                {
                    ribbon = element as Ribbon;
                    if (ribbon != null)
                    {
                        break;
                    }

                    rootElement = element;
                    element = VisualTreeHelper.GetParent(element);
                }

                double additionalOffset = 1.0;
                FrameworkElement referenceFE = null;

                if (ribbon != null)
                {
                    additionalOffset = 0.0;
                    referenceFE = ribbon;
                }
                else
                {
                    if (rootElement != null)
                    {
                        referenceFE = rootElement as FrameworkElement;
                    }
                }

                if (referenceFE != null)
                {
                    // When RibbonControl (PlacementTarget) is within a collapsed group RibbonToolTip is
                    // placed just below the Popup or just above the Popup (in case there is not enough
                    // screen space left below the Popup).

                    MatrixTransform transform = referenceFE.TransformToDescendant(placementTarget) as MatrixTransform;
                    if (transform != null)
                    {
                        MatrixTransform deviceTransform = new MatrixTransform(RibbonHelper.GetTransformToDevice(referenceFE));
                        GeneralTransformGroup transformGroup = new GeneralTransformGroup();
                        transformGroup.Children.Add(transform);
                        transformGroup.Children.Add(deviceTransform);

                        Point leftTop, rightBottom;
                        transformGroup.TryTransform(new Point(0, 0), out leftTop);
                        transformGroup.TryTransform(new Point(referenceFE.ActualWidth, referenceFE.ActualHeight), out rightBottom);

                        belowOffsetY = rightBottom.Y + additionalOffset;
                        aboveOffsetY = leftTop.Y - popupSize.Height - additionalOffset;
                    }
                }
            }
            else
            {
                // If PlacementTarget isn't within a RibbonGroup we shouldn't have
                // gotten here in the first place. But now that we are we will make
                // the best attempt at emulating PlacementMode.Bottom.
                FrameworkElement placementTargetAsFE = placementTarget as FrameworkElement;
                if (placementTargetAsFE != null)
                {
                    belowOffsetY = targetSize.Height;
                    aboveOffsetY = -popupSize.Height;
                }
            }

            // This is the prefered placement, below the ribbon for controls within Ribbon or below the Popup for controls within Popup.
            CustomPopupPlacement placementPreffered = new CustomPopupPlacement(new Point(offsetX, belowOffsetY), PopupPrimaryAxis.Horizontal);

            // This is a fallback placement, if the tooltip will not fit below the ribbon or Popup, place it above the ribbon or Popup.
            CustomPopupPlacement placementFallback = new CustomPopupPlacement(new Point(offsetX, aboveOffsetY), PopupPrimaryAxis.Horizontal);

            return new CustomPopupPlacement[] { placementPreffered, placementFallback };
        }
开发者ID:amitkr2007,项目名称:groups-dct-sms,代码行数:96,代码来源:RibbonToolTip.cs


注:本文中的System.Windows.Media.GeneralTransformGroup.TryTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。