Пример #1
0
        CreateHeaderOrFooterLabel
        (
            String sLabelText,
            Double dLabelWidth,
            System.Drawing.Font oLabelFont,
            out Label oLabel,
            out Double dLabelHeight
        )
        {
            Debug.Assert(dLabelWidth > 0);
            Debug.Assert(oLabelFont != null);
            AssertValid();

            if (sLabelText == null)
            {
                oLabel       = null;
                dLabelHeight = 0;
                return;
            }

            // Use a TextBlock to provide wrapping.

            TextBlock oTextBlock = new TextBlock();

            oTextBlock.Text         = sLabelText;
            oTextBlock.TextWrapping = TextWrapping.Wrap;
            WpfGraphicsUtil.SetTextBlockFont(oTextBlock, oLabelFont);

            oLabel            = new Label();
            oLabel.Background = HeaderFooterBackgroundBrush;
            oLabel.MaxWidth   = dLabelWidth;
            oLabel.Content    = oTextBlock;

            // Determine the height of the control.  This will likely be a floating
            // point number.

            oLabel.Measure(new Size(dLabelWidth, Double.PositiveInfinity));

            // The label height must be an integer.  If it's not an integer, any
            // Image controls contained in the parent StackPanel will be distorted
            // because they don't fall on a pixel boundary.

            oLabel.Height = Math.Ceiling(oLabel.DesiredSize.Height);
            oLabel.Measure(new Size(dLabelWidth, Double.PositiveInfinity));

            dLabelHeight = oLabel.DesiredSize.Height;
        }