Пример #1
0
            public Size MeasureText(VirtualCanvas parent, string label)
            {
                if (_parent != parent)
                {
                    FontFamily  fontFamily  = (FontFamily)parent.GetValue(TextBlock.FontFamilyProperty);
                    FontStyle   fontStyle   = (FontStyle)parent.GetValue(TextBlock.FontStyleProperty);
                    FontWeight  fontWeight  = (FontWeight)parent.GetValue(TextBlock.FontWeightProperty);
                    FontStretch fontStretch = (FontStretch)parent.GetValue(TextBlock.FontStretchProperty);
                    _fontSize = (double)parent.GetValue(TextBlock.FontSizeProperty);
                    _typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
                    _parent   = parent;
                }
                FormattedText ft = new FormattedText(label, CultureInfo.CurrentUICulture,
                                                     FlowDirection.LeftToRight, _typeface, _fontSize, Brushes.Black);

                return(new Size(ft.Width, ft.Height));
            }