Confirm/Information Dialog with Caliburn Micro
From Richard's Wiki
InformationDialogView.xaml:
<Window x:Class="WPFSample1.InformationDialogView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Width="300" Height="300" d:DesignHeight="300" d:DesignWidth="300" Focusable="True" Loaded="ConfirmView_OnLoaded" PreviewKeyDown="ConfirmView_PreviewKeyDown" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner"> <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{Binding Path=Background, ElementName=Text}" > <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="auto" /> </Grid.RowDefinitions> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" > <TextBox BorderThickness="0" IsReadOnly="True" VerticalContentAlignment="Center" TextAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="Text" /> </ScrollViewer> <Button Height="20" Content="OK" HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="1" x:Name="Close" /> </Grid> </Window>
InformationDialogView.xaml.cs:
using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace WPFSample1 { /// <summary> /// Interaction logic for InformationDialogView.xaml /// </summary> public partial class InformationDialogView : Window { public InformationDialogView() { InitializeComponent(); } private void ConfirmView_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { Window window = GetWindow(this); if (window != null) { window.Close(); } } } private void ConfirmView_OnLoaded(object sender, RoutedEventArgs e) { Button closeButton = Close; closeButton.Focus(); } } }