public DocumentView () { HorizontalAlignment = HorizontalAlignment.Stretch; VerticalAlignment = VerticalAlignment.Stretch; newRegionCommand = BuildProperty<ICommand> ("NewRegionCommand"); Focusable = true; itemsControl.ItemsPanel = canvas; itemsControl.ItemTemplate = new DataTemplate (Factory); var adornerDecorator = new AdornerDecorator () { Child = itemsControl }; var grid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch}; grid.RowDefinitions.Add (new RowDefinition ()); grid.RowDefinitions.Add (new RowDefinition () {Height = GridLength.Auto}); grid.ColumnDefinitions.Add (new ColumnDefinition ()); grid.ColumnDefinitions.Add (new ColumnDefinition () {Width = GridLength.Auto}); var textBlock = new TextBlock (){Text ="+"}; var button = new Button () { Content = textBlock}; grid.Children.Add (adornerDecorator); grid.Children.Add (button); grid.SetRow (1, button); Content = grid; PreviewKeyPressEvent += HandlePreviewKeyPressEvent; ButtonPressEvent += HandleButtonPressEvent; AdornerLayer.GetAdornerLayer (itemsControl).Add (documentCursor); Background = Brushes.White; Keyboard.Focus (this); BindingOperations.SetBinding (this, "DataContext.DocumentCursor", documentCursor.GetProperty ("DataContext")); BindingOperations.SetBinding (this, "DataContext.Regions", itemsControl.GetProperty ("ItemsSource")); BindingOperations.SetBinding (this, "DataContext.NewRegionCommand", GetProperty ("NewRegionCommand")); }
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 UIElement DocumentTemplate (object o) { var viewModel = o as DependencyObject; var document = new DocumentView () { DataContext = viewModel, }; var header = new TextBlock (); BindingOperations.SetBinding (viewModel.GetProperty ("Title"), header.GetProperty ("Text")); return new TabItem () { Header = header, Content = document }; }