public TopicDragControl() { InitializeComponent(); if (TopicDragInfo == null) { Topic.TopicDragInfo info = new Topic.TopicDragInfo(); Topic.TopicDragItem option1 = new Topic.TopicDragItem() { Id = 1, Title = "AAA", AnswerId = 5 }; Topic.TopicDragItem option2 = new Topic.TopicDragItem() { Id = 2, Title = "BBB", AnswerId = 6 }; Topic.TopicDragItem option3 = new Topic.TopicDragItem() { Id = 3, Title = "CCC", AnswerId = 7 }; Topic.TopicDragItem option4 = new Topic.TopicDragItem() { Id = 4, Title = "DDD", AnswerId = 8 }; Topic.TopicDragItem option5 = new Topic.TopicDragItem() { Id = 5, Title = "EEE", AnswerId = 1 }; Topic.TopicDragItem option6 = new Topic.TopicDragItem() { Id = 6, Title = "FFF", AnswerId = 2 }; Topic.TopicDragItem option7 = new Topic.TopicDragItem() { Id = 7, Title = "GGG", AnswerId = 3 }; Topic.TopicDragItem option8 = new Topic.TopicDragItem() { Id = 8, Title = "HHH", AnswerId = 4 }; info.LeftOption.Add(option1); info.LeftOption.Add(option2); info.LeftOption.Add(option3); info.LeftOption.Add(option4); // info.LeftOption.AddRange(new ObservableCollection<Topic.TopicDragItem> { option1, option2, option3, option4 }); info.RightOption.Add(option5); info.RightOption.Add(option6); info.RightOption.Add(option7); info.RightOption.Add(option8); // info.RightOption.AddRange(new ObservableCollection<Topic.TopicDragItem> { option5, option6, option7, option8 }); TopicDragInfo = info; } }
private void InitializeComponent() { this.MinWidth = 150; this.MinHeight = 150; // 设计时显示内容 if (DesignerProperties.GetIsInDesignMode(this)) { if (this.TopicDragInfo == null) { Topic.TopicDragInfo info = new Topic.TopicDragInfo(); Topic.TopicDragItem option1 = new Topic.TopicDragItem() { Id = 1, Title = "AAA", AnswerId = 5 }; Topic.TopicDragItem option2 = new Topic.TopicDragItem() { Id = 2, Title = "BBB", AnswerId = 6 }; Topic.TopicDragItem option3 = new Topic.TopicDragItem() { Id = 3, Title = "CCC", AnswerId = 7 }; Topic.TopicDragItem option4 = new Topic.TopicDragItem() { Id = 4, Title = "DDD", AnswerId = 8 }; Topic.TopicDragItem option5 = new Topic.TopicDragItem() { Id = 5, Title = "EEE", AnswerId = 1 }; Topic.TopicDragItem option6 = new Topic.TopicDragItem() { Id = 6, Title = "FFF", AnswerId = 2 }; Topic.TopicDragItem option7 = new Topic.TopicDragItem() { Id = 7, Title = "GGG", AnswerId = 3 }; Topic.TopicDragItem option8 = new Topic.TopicDragItem() { Id = 8, Title = "HHH", AnswerId = 4 }; info.LeftOption.Add(option1); info.LeftOption.Add(option2); info.LeftOption.Add(option3); info.LeftOption.Add(option4); // info.LeftOption.AddRange(new ObservableCollection<Topic.TopicDragItem> { option1, option2, option3, option4 }); info.RightOption.Add(option5); info.RightOption.Add(option6); info.RightOption.Add(option7); info.RightOption.Add(option8); // info.RightOption.AddRange(new ObservableCollection<Topic.TopicDragItem> { option5, option6, option7, option8 }); TopicDragInfo = info; } } this.Background = Brushes.LightCoral; this.SizeChanged += TopicDragControl_SizeChanged; }