protected override Size MeasureOverride(Size availableSize)
        {
            // CanvasTextLayout cannot cope with infinite sizes, so we change
            // infinite to some-large-value.
            if (double.IsInfinity(availableSize.Width))
            {
                availableSize.Width = 6000;
            }

            if (double.IsInfinity(availableSize.Height))
            {
                availableSize.Height = 6000;
            }

            var device = CanvasDevice.GetSharedDevice();

            var layout = CreateTextLayout(device, availableSize);
            var bounds = layout.LayoutBounds;

            Size desiredSize = new Size(Math.Min(availableSize.Width, bounds.Width + ExpandAmount), Math.Min(availableSize.Height, bounds.Height + ExpandAmount));

            if (canvas != null)
            {
                canvas.Measure(desiredSize);
            }

            return(desiredSize);
        }
예제 #2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            // CanvasTextLayout cannot cope with infinite sizes, so we change infinite to some-large-value.
            if (double.IsInfinity(availableSize.Width))
            {
                availableSize.Width = 6000;
            }
            if (double.IsInfinity(availableSize.Height))
            {
                availableSize.Height = 6000;
            }

            var device = CanvasDevice.GetSharedDevice();

            using (var layout = CreateTextLayout(device, availableSize)) {
                var bounds = layout.LayoutBounds;

                var desiredSize = new Size(Math.Min(availableSize.Width, bounds.Width + ExpandAmount),
                                           Math.Min(availableSize.Height, bounds.Height + ExpandAmount));

                if (_canvas != null)
                {
                    _canvas.Measure(desiredSize);
                }

                return(desiredSize);
            }


            // https://github.com/Microsoft/Win2D-Samples/blob/master/ExampleGallery/GlowTextCustomControl.cs
        }