private void BaseObject_Loaded(object sender, RoutedEventArgs e) { Console.WriteLine("Base Object Loaded"); if (this.Template != null) { ContentPresenter contentPresenter = this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter; MoveThumb thumb = this.Template.FindName("PART_MoveThumb", this) as MoveThumb; if (contentPresenter != null && thumb != null) { UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement; if (contentVisual != null) { ControlTemplate template = BaseObject.GetMoveThumbTemplate(contentVisual) as ControlTemplate; if (template != null) { thumb.Template = template; } } } ResizeDecorator resizeDecorator = this.Template.FindName("PART_BaseObjectDecorator", this) as ResizeDecorator; if (resizeDecorator != null) { resizeDecorator.ShowAdorner(); } } }
public MoveThumbAdorner(FrameworkElement designerItem) : base(designerItem) { this.SnapsToDevicePixels = true; this.designerItem = designerItem; this.visuals = new VisualCollection(this); moveThumb = new MoveThumb(); visuals.Add(moveThumb); this.moveThumb.DataContext = designerItem; }
public Highlight() { InitializeComponent(); MouseDown += (sender, e) => { MoveThumb.RaiseEvent(e); }; MoveThumb.DragDelta += (sender, e) => { HorizontalOffset += e.HorizontalChange; VerticalOffset += e.VerticalChange; }; }
private void CreateNote(NoteView note) { ContentControl noteControl = new ContentControl(); noteControl.Name = "Note" + newNoteCount++; noteControl.Tag = note; Style template = this.TryFindResource("DesignerItemStyle") as Style; noteControl.Style = template; noteControl.ApplyTemplate(); SolidColorBrush brush = new SolidColorBrush(); brush.Color = ColorHelpers.GetColorByName(note.Color); noteControl.Background = brush; noteControl.Width = note.Width; noteControl.Height = note.Height; Canvas.SetTop(noteControl, note.Y); Canvas.SetLeft(noteControl, note.X); Transform rotate = new RotateTransform(note.RotateAngle, note.RotateCenterX, note.RotateCenterY); noteControl.RenderTransform = rotate; Button btnClose = noteControl.Template.FindName("btnClose", noteControl) as Button; Button btnChangeColor = noteControl.Template.FindName("btnChangeColor", noteControl) as Button; RichTextBox rtbBody = noteControl.Template.FindName("rtbNoteBody", noteControl) as RichTextBox; rtbBody.LoadFromRTF(note.Body); //SetValueToRichTextBox(note, rtbBody); MoveThumb moveThumb = noteControl.Template.FindName("moveThumb", noteControl) as MoveThumb; moveThumb.ApplyTemplate(); TextBlock txtTitle = moveThumb.Template.FindName("txtTitle", moveThumb) as TextBlock; txtTitle.Text = note.User == null ? "新建" : note.User.Realname + note.AddTime.ToShortDateString(); btnClose.Click += new RoutedEventHandler(btnClose_Click); btnChangeColor.Click += new RoutedEventHandler(btnChangeColor_Click); rtbBody.TextChanged += new TextChangedEventHandler(rtbBody_TextChanged); this.NoteCanvas.Children.Add(noteControl); }