Reputation: 947
Hi i am trying to implement the MessageBox resizing bahavior depending on the size of the Text (not caption) string in a custom DialogBox i am building in WPF. It's my custom MessageBox with the layout of my app.
But how MessageBox does to depending in the size of the string, the height of the MessageBox grows automatically? How to do that?
Thanks in advance!
Upvotes: 1
Views: 2657
Reputation: 184516
This is how i normally do this:
<Window SizeToContent="WidthAndHeight" ResizeMode="NoResize" ...>
Additionally you could have a ScrollViewer
as the child of the window and set the MaxHeight
& MaxWidth
properties on the window to restrict it further.
Edit: To give a discreet example of what the window might look like:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize" MaxWidth="400" MaxHeight="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Children>
<FlowDocumentScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
<FlowDocument>
<Paragraph>
<Run Text="{Binding DisplayText}"/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
<StackPanel Grid.Row="1">
<!-- Buttons -->
</StackPanel>
</Grid.Children>
</Grid>
</Window>
Upvotes: 3
Reputation: 7342
In WPF you usually use the FormattedText class to finetune text.
What you need exactly if I got it right is the BuildGeometry method:
http://msdn.microsoft.com/en-us/library/system.windows.media.formattedtext.buildgeometry.aspx
So you need:
Upvotes: 0