Thursday, April 21, 2011

Five Minute Silverlight 5 Aides-Memoire #3 – Out-of-Browser Native Windows

Native Window creation in code
  1. private void ButtonClick(object sender, RoutedEventArgs e)
  2. {
  3.     if (!Application.Current.IsRunningOutOfBrowser)
  4.     {
  5.         return;
  6.     }
  7.  
  8.     var newGrid = new Grid
  9.     {
  10.         Background = new SolidColorBrush(Colors.White),
  11.         HorizontalAlignment = HorizontalAlignment.Stretch,
  12.         VerticalAlignment = VerticalAlignment.Stretch
  13.     };
  14.  
  15.     var newTextBlock = new TextBlock
  16.     {
  17.         HorizontalAlignment = HorizontalAlignment.Center,
  18.         VerticalAlignment = VerticalAlignment.Center,
  19.         Text = "New TextBlock in a new Window..."
  20.     };
  21.  
  22.     newGrid.Children.Add(newTextBlock);
  23.  
  24.     new Window { Content = newGrid, Visibility = Visibility.Visible, Width = 300, Height = 300 };
  25. }

NativeWindows

No comments: