0

У меня есть TextBlock и Thumb. Как посчитать минимальную длину HeaderBorder

введите сюда описание изображения введите сюда описание изображения

при которой Text виден внутри Border т.е примерно так

введите сюда описание изображения

<Grid>
  <Border x:Name="HeaderBorder" Height="40" Width="Auto" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,1,1" Background="{TemplateBinding Background}">
    <ContentPresenter SnapsToDevicePixels="True" x:Name="HeaderContent" RecognizesAccessKey="True">
      <ContentPresenter.Resources>
        <Style TargetType="{x:Type TextBlock}">
          <Setter Property="TextAlignment" Value="Left"/>
          <Setter Property="VerticalAlignment" Value="Center"/>
          <Setter Property="HorizontalAlignment" Value="Center"/>
          <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
          <Setter Property="TextAlignment" Value="Left"/>
        </Style>
      </ContentPresenter.Resources>
    </ContentPresenter>
  </Border>
  <Canvas>
    <model:GridViewColumnResizeThumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
  </Canvas>
</Grid>

Знаю что есть TextTrimming, мне нужна длина при которой он срабатывает

Нашел пример

Typeface typeface = new Typeface(
textBlock.FontFamily,
textBlock.FontStyle,
textBlock.FontWeight,
textBlock.FontStretch);

// FormattedText is used to measure the whole width of the text held up by TextBlock container
FormattedText formattedText = new FormattedText(
            textBlock.Text,
            System.Threading.Thread.CurrentThread.CurrentCulture,
            textBlock.FlowDirection,
            typeface,
            textBlock.FontSize,
            textBlock.Foreground);


formattedText.MaxTextWidth = textBlock.ActualWidth;

        // When the maximum text width of the FormattedText instance is set to the actual
        // width of the textBlock, if the textBlock is being trimmed to fit then the formatted
        // text will report a larger height than the textBlock. Should work whether the
        // textBlock is single or multi-line.
        // The "formattedText.MinWidth > formattedText.MaxTextWidth" check detects if any 
        // single line is too long to fit within the text area, this can only happen if there is a 
        // long span of text with no spaces.
return (formattedText.Height > textBlock.ActualHeight || formattedText.MinWidth > formattedText.MaxTextWidth);

но здесь сравнивают а как посчитать?

2

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.