private void FlatThumb(Thumb thumb, Color bgColor) { //template作成 ControlTemplate template = new ControlTemplate(typeof(Thumb)); //Templateの見た目の作成、ベースにはGrid要素を使った //任意の名前をつけておくと、これをもとに検索して要素を取得できる template.VisualTree = new FrameworkElementFactory(typeof(Grid), "tempGrid"); thumb.Template = template; //再構築、これを実行しないと名前検索で取得できない thumb.ApplyTemplate(); //名前検索で取得して背景色に水色指定 Grid myGrid = (Grid)thumb.Template.FindName("tempGrid", thumb); myGrid.Background = new SolidColorBrush(bgColor); var inside = new Thumb() { Width = 20, Height = 20, Background = Brushes.Red }; Canvas.SetLeft(inside, 0); Canvas.SetTop(inside, 0); myGrid.Children.Add(inside); inside.DragDelta += Inside_DragDelta; }
private void FlatThumbCanvasBase(Thumb thumb, Color bgColor) { //template作成 ControlTemplate template = new ControlTemplate(typeof(Thumb)); //Templateの見た目の作成、ベースにはGridではなくCanvas要素を使ったのは //子Thumbの移動にはCanvas.Setを使うから //任意の名前をつけておくと、これをもとに検索して要素を取得できる template.VisualTree = new FrameworkElementFactory(typeof(Canvas), "tempCanvas"); thumb.Template = template; //再構築、これを実行しないと名前検索で取得できない thumb.ApplyTemplate(); //名前検索で取得して背景色に水色指定 Canvas bCanvas = (Canvas)thumb.Template.FindName("tempCanvas", thumb); bCanvas.Background = new SolidColorBrush(bgColor); //子Thumbを追加 var inside = new Thumb() { Width = 20, Height = 20, Background = Brushes.Red }; Canvas.SetLeft(inside, 0); Canvas.SetTop(inside, 0); bCanvas.Children.Add(inside); inside.DragDelta += Inside_DragDelta; }
//public void Set8Point(Thumb parentThumb, double size, Color bgColor) //{ // mySizeChangePointThumbs = new MySizeChangePointThumb[8]; // for (int i = 0; i < 8; i++) // { // var pThumb = new MySizeChangePointThumb(parentThumb, size, bgColor, // (LocateDirection)Enum.GetValues(typeof(LocateDirection)).GetValue(i)); // mySizeChangePointThumbs[i] = pThumb; // MyCanvas.Children.Add(pThumb); // } //} /// <summary> /// Thumbの見た目変更、ControlTemplateを使って、フラットなThumbにする /// </summary> /// <param name="thumb"></param> /// <param name="bgColor">背景色</param> private void FlatThumb(Thumb thumb, Color bgColor) { //template作成 ControlTemplate template = new ControlTemplate(typeof(Thumb)); //Templateの見た目の作成、ベースにはGrid要素を使った //任意の名前をつけておくと、これをもとに検索して要素を取得できる template.VisualTree = new FrameworkElementFactory(typeof(Grid), "tempGrid"); thumb.Template = template; //再構築、これを実行しないと名前検索で取得できない thumb.ApplyTemplate(); //名前検索で取得して背景色に水色指定 Grid myGrid = (Grid)thumb.Template.FindName("tempGrid", thumb); myGrid.Background = new SolidColorBrush(bgColor); }
/// <summary> /// Pins an element; /// </summary> /// <param name="element">Element to pin.</param> public void Pin(PinDebuggerControl element) { if (element == null) { throw new NullReferenceException("Element is null!"); } Thumb currentThumb = new Thumb(); // check for saved position if (!element.Mark.PinPosition.HasValue) { // this is satisfied when pinning the first time element.Mark.PinPosition = new Point { X = element.Location.X + textView.HorizontalOffset, Y = element.Location.Y + textView.VerticalOffset }; Canvas.SetTop(currentThumb, element.Location.Y); Canvas.SetLeft(currentThumb, element.Location.X); } else { // this is satisfied when loading the pins - so we might have hidden pins element.Location = new Point { X = element.Mark.PinPosition.Value.X - textView.HorizontalOffset, Y = element.Mark.PinPosition.Value.Y - textView.VerticalOffset }; Canvas.SetTop(currentThumb, element.Mark.PinPosition.Value.Y); Canvas.SetLeft(currentThumb, element.Mark.PinPosition.Value.X); } currentThumb.Style = element.TryFindResource("PinThumbStyle") as Style; currentThumb.ApplyTemplate(); currentThumb.DragDelta += onDragDelta; currentThumb.DragStarted += currentThumb_DragStarted; currentThumb.DragCompleted += currentThumb_DragCompleted; var container = TryFindChild <StackPanel>(currentThumb); container.Children.Add(element); this.Children.Add(currentThumb); }
private void callOutImg1_Tap(object sender, System.Windows.Input.GestureEventArgs e) { Image img = (Image)sender; if (img.Name == "callOutConnector") { drawConnector = true; } else if (img.Name == "callOutConnectorDel") { drawConnector = false; List <int> indices = new List <int>(); foreach (var item in canvas1.Children.OfType <Line>()) { indices.Add(canvas1.Children.IndexOf(item)); } /* foreach (var i in indices) * { * if(canvas1.Children[i]!=null) * canvas1.Children.RemoveAt(i); * }*/ } else if (img.Name == "callOutText") { drawConnector = false; TextBlock txtCallout = new TextBlock(); txtCallout.Foreground = new SolidColorBrush(Colors.Black); Image m = (Image)sender; pop.Width = 400; pop.Height = 400; pop.Name = "Popup"; CalloutInput ci = new CalloutInput(); pop.Child = ci; pop.IsOpen = true; ci.btnDone.Click += (s, args) => { txtCallout.Text = ci.txtCallout.Text; //create thumb so it can dragged around var name = "thumb" + Guid.NewGuid().ToString(); var drag = new Thumb(); drag.Name = name; //drag aorund the element drag.DragDelta += new DragDeltaEventHandler(drag_DragDelta); //create template for the thumb string template = "<ControlTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " + "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " + "x:Key=\"template1\" x:Name=\"tst\">" + "<StackPanel x:Name=\"imgGrid\" Orientation=\"Vertical\" Width=\"200\">" + "<TextBlock xml:space=\"preserve\" TextWrapping=\"Wrap\" Foreground=\"Black\" Text=\"" + HttpUtility.HtmlEncode(txtCallout.Text) + "\" />" + "</StackPanel>" + "</ControlTemplate>"; //parse template and assign to thumb template. drag.Template = (ControlTemplate)XamlReader.Load(template); //drag.Width = "{Binding BindsDirectlyToSource=True}"; //to make the textblock flexible. Binding b1 = new Binding(); b1.Path = new PropertyPath("Height"); b1.BindsDirectlyToSource = true; Binding b2 = new Binding(); b2.Path = new PropertyPath("Width"); b2.BindsDirectlyToSource = true; drag.SetBinding(HeightProperty, b1); drag.SetBinding(WidthProperty, b2); drag.ApplyTemplate(); // drag.Width = 200; //add thumb to canvas canvas1.Children.Add(drag); pop.IsOpen = false; }; ci.btnNopes.Click += (s, args) => { pop.IsOpen = false; }; } else if (img.Name == "calloutCancelAll") { Image imgBin = (Image)canvas1.FindName("dustbin"); canvas1.Children.Clear(); canvas1.Children.Add(imgBin); } else { //do nothing. } }