Make the MessageBox display properly with multi-line content

This commit is contained in:
Antony Male 2015-02-28 13:25:35 +00:00
parent 48ee25ba29
commit b11a9dabff
3 changed files with 32 additions and 3 deletions

View File

@ -10,7 +10,6 @@
ResizeMode="NoResize"
SizeToContent="WidthAndHeight"
FlowDirection="{Binding FlowDirection}"
WindowStartupLocation="CenterScreen"
ShowInTaskbar="False"
MinWidth="160" MaxWidth="485"
x:Name="RootObject">
@ -25,12 +24,24 @@
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" Grid.Column="1" Margin="19,0,0,0" VerticalAlignment="Center"
<Image Grid.Row="0" Grid.Column="1"
Source="{Binding ImageIcon, Converter={x:Static s:IconToBitmapSourceConverter.Instance}}"
Visibility="{Binding ImageIcon, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
<Image.Style>
<Style TargetType="Image">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="19,0,0,0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding TextIsMultiline}" Value="True">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Margin" Value="19,25,0,0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Text}" Margin="8,30,15,30" TextWrapping="Wrap" TextAlignment="{Binding TextAlignment}"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Text}" Margin="8,25,15,30" TextWrapping="Wrap" TextAlignment="{Binding TextAlignment}"/>
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<ItemsControl ItemsSource="{Binding ButtonList}"

View File

@ -182,6 +182,14 @@ namespace Stylet
/// </summary>
public virtual string Text { get; protected set; }
/// <summary>
/// Gets a value indicating whether the Text contains many lines
/// </summary>
public virtual bool TextIsMultiline
{
get { return this.Text.Contains("\n"); }
}
/// <summary>
/// Gets or sets the icon which the user specified
/// </summary>

View File

@ -37,6 +37,16 @@ namespace StyletUnitTests
Assert.AreEqual("this is the text", this.vm.Text);
}
[Test]
public void DeterminesTextIsMultilineCorrectly()
{
this.vm.Setup("this is the text", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null);
Assert.IsFalse(this.vm.TextIsMultiline);
this.vm.Setup("hello\nworld", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null);
Assert.IsTrue(this.vm.TextIsMultiline);
}
[Test]
public void SetsTitleCorrectly()
{