에 맞을 때까지
의사 코드
// Function added to TextBlock as SizeChanged event handler.
private void textBlock_SizeChanged(object sender, SizeChangedEventArgs e)
{
TextBlock textBlock = sender as TextBlock;
if(textBlock.IsTrimmed && textBlock.FontSize > 10) // NOTE: IsTrimmed Property does not exist.
{
textBlock.FontSize -= 10;
}
}
그런 다음 UI 스레드가 반복적으로 여기에 작동하는 솔루션입니다 텍스트를 축소합니다.
private void textBlock_SizeChanged(object sender, SizeChangedEventArgs e)
{
TextBlock tb = sender as TextBlock;
if (tb != null)
{
Grid parent = tb.Parent as Grid;
if(parent != null)
{
if(parent.ActualWidth < tb.ActualWidth)
{
tb.FontSize -= 10;
}
}
}
}
매우 효율적이지는 않지만. 글꼴 크기, 문자열 길이 및 픽셀 너비를 결정하는 데 사용할 수있는 알고리즘이있는 경우이를 향상시킬 수 있습니다.
출처
2014-07-10 10:14:35
Ne0
TextBlock을 Viewbox에 넣으면 필요에 따라 축소되어 표시됩니다. – Jon