private void CreateTextPostAt(Point position, double width, double height, DateTime creationTime, string postFile, Color background) { DesignerItem newItem = null; UserControl content = new PostEditor(); content.Margin = new Thickness(2, 10, 2, 2); if (content != null) { newItem = new DesignerItem(); newItem.CreationTime = creationTime; newItem.Content = content; ((PostEditor)content).BackgroundColor = background; ((PostEditor)content).SetCreationTime(newItem.CreationTime); ((PostEditor)content).LoadPost(postFile); newItem.Width = width; //newItem.Height = height; DesignerCanvas.SetLeft(newItem, position.X); DesignerCanvas.SetTop(newItem, position.Y); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; newItem.SaveMethod = ((PostEditor)content).SavePost; } }
public void CreateTextPostAt(Point position, Color postColor) { DesignerItem newItem = null; UserControl content = new PostEditor(); content.Margin = new Thickness(2, 10, 2, 2); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; ((PostEditor)content).SetCreationTime(newItem.CreationTime); ((PostEditor)content).BackgroundColor = postColor; if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; //newItem.Height = content.MinHeight * 2; } else { newItem.Width = 250; //newItem.MinHeight = 285; } DesignerCanvas.SetLeft(newItem, position.X); // Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, position.Y); // Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; newItem.SaveMethod = ((PostEditor)content).SavePost; } }
private void CreatePostAt(Point position) { DesignerItem newItem = null; //FrameworkElement content = new RichTextBox(); string imageFile = SelectImageFromDisk(); if (imageFile == string.Empty) { return; } Image content = new Image(); BitmapImage bmImage = new BitmapImage(); bmImage.BeginInit(); bmImage.UriSource = new Uri(imageFile, UriKind.Absolute); bmImage.EndInit(); content.Source = bmImage; //content.IsHitTestVisible = false; if (content != null) { newItem = new DesignerItem(); newItem.Content = content; if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }