Ejemplo n.º 1
0
 private void MessageBoxWindow_Loaded(object sender, RoutedEventArgs e)
 {
     // Center message box window in application.
     if (Owner == null)
     {
         ControlsHelper.CenterWindowOnApplication(this);
     }
 }
Ejemplo n.º 2
0
 private void MessageBoxWindow_Loaded1(object sender, RoutedEventArgs e)
 {
     if (SizeToContent == SizeToContent.Manual)
     {
         ControlsHelper.CenterWindowOnApplication(this);
     }
     else
     {
         // Get text size (from 256 to 512).
         var measureSize    = Math.Min(Math.Max(256, MessageTextBlock.Text.Length), 512);
         var measureMessage = new string('a', measureSize);
         var size           = MeasureString(measureMessage, MessageTextBlock);
         size = ApplyAspectRatio(size);
         var boxWidth  = Math.Round(size.Width, 0);
         var boxHeight = Math.Round(size.Height, 0);
         // Set window size.
         var winWidthDif  = Width - MessageTextBox.ActualWidth;
         var winHeightDif = Height - MessageTextBox.ActualHeight;
         SizeToContent = SizeToContent.Manual;
         Width         = boxWidth + winWidthDif;
         Height        = boxHeight + winHeightDif;
     }
 }