private static UIElement WindowTemplate (Window element) { var grid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch}; grid.RowDefinitions.Add (new RowDefinition () {Height = GridLength.Auto}); grid.RowDefinitions.Add (new RowDefinition ()); grid.ColumnDefinitions.Add (new ColumnDefinition ()); var titleGrid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch}; titleGrid.RowDefinitions.Add (new RowDefinition ()); titleGrid.ColumnDefinitions.Add (new ColumnDefinition ()); titleGrid.ColumnDefinitions.Add (new ColumnDefinition () { Width = GridLength.Auto }); var title = new TextBlock (); title.Foreground = Colors.White; title.HorizontalAlignment = HorizontalAlignment.Center; BindingOperations.SetBinding (element.GetProperty ("Title"), title.GetProperty ("Text")); var closeButton = CloseButton (); closeButton.Click += (sender, e) => element.Close (); titleGrid.Children.Add (title); titleGrid.Children.Add (closeButton); titleGrid.SetColumn (0, title); titleGrid.SetColumn (1, closeButton); var titleThumb = new Thumb () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Template = new ControlTemplate(t => titleGrid) }; titleThumb.DragDelta += (sender, e) => { element.Left += e.HorizontalChange; element.Top += e.VerticalChange; }; var titleBorder = new Border (); titleBorder.Background = GetTitleBrush (); titleBorder.Child = titleThumb; titleBorder.Padding = new Thickness (3); grid.Children.Add (titleBorder); grid.SetRow (0, titleBorder); var border = new Border (); BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); BindingOperations.SetBinding (element.GetProperty ("Content"), border.GetProperty ("Child")); grid.Children.Add (border); grid.SetRow (1, border); return grid; }
private static UIElement WindowTemplate(Window element) { var grid = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); var titleGrid = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; titleGrid.RowDefinitions.Add(new RowDefinition()); titleGrid.ColumnDefinitions.Add(new ColumnDefinition()); titleGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); var title = new TextBlock(); title.Foreground = Colors.White; title.HorizontalAlignment = HorizontalAlignment.Center; BindingOperations.SetBinding(element.GetProperty("Title"), title.GetProperty("Text")); var closeButton = CloseButton(); closeButton.Click += (sender, e) => element.Close(); titleGrid.Children.Add(title); titleGrid.Children.Add(closeButton); titleGrid.SetColumn(0, title); titleGrid.SetColumn(1, closeButton); var titleThumb = new Thumb() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Template = new ControlTemplate(t => titleGrid) }; titleThumb.DragDelta += (sender, e) => { element.Left += e.HorizontalChange; element.Top += e.VerticalChange; }; var titleBorder = new Border(); titleBorder.Background = GetTitleBrush(); titleBorder.Child = titleThumb; titleBorder.Padding = new Thickness(3); grid.Children.Add(titleBorder); grid.SetRow(0, titleBorder); var border = new Border(); BindingOperations.SetBinding(element.GetProperty("Padding"), border.GetProperty("Padding")); BindingOperations.SetBinding(element.GetProperty("Background"), border.GetProperty("Background")); BindingOperations.SetBinding(element.GetProperty("BorderThickness"), border.GetProperty("BorderThickness")); BindingOperations.SetBinding(element.GetProperty("BorderColor"), border.GetProperty("BorderColor")); BindingOperations.SetBinding(element.GetProperty("Content"), border.GetProperty("Child")); grid.Children.Add(border); grid.SetRow(1, border); return(grid); }