none
WPF InkCanvas类的InkCanvas.Paste ()方法怎么没有把InkCanvas.CutSelection()剪切的内容全部粘贴呢?? RRS feed

  • 问题

  • WPF  InkCanvas类的InkCanvas.Paste ()方法怎么没有把InkCanvas.CutSelection()剪切的内容全部粘贴呢??

    就是只粘贴了stroke,并没有把图片,视频这些UIElement这些元素粘贴呢??

    2014年11月5日 2:49

答案

全部回复

  • 你好,

    可以提供你关于InkCanvas的Select方法是怎么写的么?根据MSDN文档,比如你可以看这里:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.inkcanvas.cutselection(v=vs.100).aspx

    “This example assumes that there is a TextBox called textbox1 and a Button called button1 - and that both controls are child elements of the InkCanvas.”

    有一点必须要确认的是既然你调用的是InkCanvas的方法,你首先要确保你的UIElement那些个元素是给予InkCanvas的,属于InkCanvas的子元素。

    我觉得你的问题可能就是在这里产生的。



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2014年11月6日 7:40
    版主
  •  private void selectBtn_TouchUp(object sender, TouchEventArgs e)
     {
              DrawInkCanvas.EditingMode = InkCanvasEditingMode.Select;
     }
     private void cutBtn_TouchUp(object sender, TouchEventArgs e)
      {
                if (DrawInkCanvas.GetSelectedStrokes().Count > 0 || DrawInkCanvas.GetSelectedElements().Count > 0)
                {
                        DrawInkCanvas.CutSelection();
                }
    }
    点击选择按钮,把inkCanvas 的EditingMode 设为Select,然后在InkCanvas上的stroke或UiElement周围画圈就选择了一组strokes或UiElement元素,然后点击剪切按钮,就会把选择的区域剪切掉,并复制在粘贴板上,在里外一个InkCanvas上面点击粘贴按钮:执行InkCanvas.Paste();可是就只有strokes被粘贴上,UiElement并没有被粘贴??哪里出现问题了吗??
    2014年11月6日 7:54
  • 那你的XAML代码呢,关于InkCanvas和你的这些选择的UIElement的?这里特制的这些UIElement是InkCanvas的子元素么?我可以帮你做下测试


    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2014年11月6日 8:24
    版主
  • <Window x:Class="WhiteBoard.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WhiteBoard"
            Title="MainWindow" WindowStyle="None"  WindowState="Maximized"  Loaded="MainWindow_Loaded" >
     <Border x:Name="DrawBorder"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <InkCanvas x:Name="DrawInkCanvas"  Background="DarkSlateGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>                        
                </Border>
    </Window>

    后台代码是:

     
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
     {                   
    
    
    }
    
      private void AddFile_Click(object sender, RoutedEventArgs e)
            {
    
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.CheckFileExists = true;
                dlg.Filter =
                    "图片(*.jpg;*.png) |*.png;*.jpg;*.jpeg" +
                    "|视频(*.mp4;*.wmv) |*.mp4;*.wmv" +                
                    "|所有文件 (*.*)|*.*";
                if ((bool)dlg.ShowDialog(this))
                {             
                        var fileName = dlg.FileName;
                        if (dlg.FileName.ToLower().EndsWith(".png") || dlg.FileName.ToLower().EndsWith(".jpg"))          //插入图片
                        {
                            Image addimage = new Image();
                            addimage.Width = 400; //SystemParameters.PrimaryScreenWidth;
                            addimage.Height = 300; //SystemParameters.PrimaryScreenHeight;
                            addimage.Source = new BitmapImage(new Uri(fileName, UriKind.Absolute));
                            addimage.Stretch = Stretch.Fill;
                            InkCanvas.SetTop(addimage, 20);
                            InkCanvas.SetLeft(addimage, 20);
                            DrawInkCanvas.Children.Add(addimage);
                           
                        }
                        else if (dlg.FileName.ToLower().EndsWith(".mp4") || dlg.FileName.ToLower().EndsWith(".wmv"))   //插入视频
                        {
                          
                                MediaElement addmedia = new MediaElement();
                                addmedia.Width = 400;
                                addmedia.Height = 300;
                                addmedia.Source = new Uri(fileName, UriKind.Absolute);
                                addmedia.Stretch = Stretch.Fill;
                                InkCanvas.SetTop(addmedia, 40);
                                InkCanvas.SetLeft(addmedia, 40);
                                DrawInkCanvas.Children.Add(addmedia);
                                                   }                               
                }
            }
    
    
    
    
    
    有一个按钮,点击之后选择文件然后就可以往Inkcanvas上加入元素
    2014年11月6日 9:01
  • @heller,

    重点还在我第一个post里面说的children,你的button没有在XAML里面定义,你现在的Add_File响应的是你所说的按钮的事件,但是没有代码表示你的Button是属于你的InkCanvas的子集,

    例如我们看这里:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.inkcanvas.children(v=vs.110).aspx

    你试试用代码把你的Button加入到InkCanvas的子集里面:

    inkCanvas1.Children.Add(addfilebutton);

    或者Xaml里面这样,参照这里http://msdn.microsoft.com/en-us/library/ms747386(v=vs.110).aspx

    <InkCanvas>
      <Button Name="AddFileButton"/>
    </InkCanvas>
    
    这个时候你再选着试试,看看有效果没有。




    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年11月10日 2:10
    版主