What you're asking is more complex than it sounds, but I'll give you an idea:
<DockPanel x:Name="LayoutRoot">
<TextBox x:Name="text" Text="this is some text and some more text I don't see any problems..." DockPanel.Dock="Top" TextChanged="text_TextChanged"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding ElementName=tb, Path=FontSize}"/>
<Border Name="bd" BorderBrush="Black" BorderThickness="1">
<TextBlock Name="tb" Text="{Binding ElementName=text, Path=Text}" TextWrapping="Wrap"/>
</Border>
</DockPanel>
And in code behind:
public MainWindow()
{
this.InitializeComponent();
RecalcFontSize();
tb.SizeChanged += new SizeChangedEventHandler(tb_SizeChanged);
}
void tb_SizeChanged(object sender, SizeChangedEventArgs e)
{
RecalcFontSize();
}
private void RecalcFontSize()
{
if (tb == null) return;
Size constraint = new Size(tb.ActualWidth, tb.ActualHeight);
tb.Measure(constraint);
while (tb.DesiredSize.Height < tb.ActualHeight)
{
tb.FontSize += 1;
tb.Measure(constraint);
}
tb.FontSize -= 1;
}
private void text_TextChanged(object sender, TextChangedEventArgs e)
{
RecalcFontSize();
}
Try it, drag it around, change the text...