madhu babu
madhu babu

Reputation: 39

How to get guesture from one canvas to set on another canvas programatically in windows phone 8 app

i'm creating simple canvas application which is to get the signature from canvas which is named as "ContentPanelCanvas" which is from Grid named as "pop-up" and to set that signature from "Pop-up" and to set on canvas named as "maincanvas". If you know Please help me to resolve this issue how to get the canvas context and set it to blank canvas.Here is the code i used.

In Xaml:

<Grid x:Name="ContentPanel">
    <Grid.RowDefinitions>
           <RowDefinition Height="*"></RowDefinition>
           <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
     <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
     </Grid.ColumnDefinitions>
     <Grid Grid.Column="0">
            <Canvas Name="maincanvas">

            </Canvas>
        </Grid>

    <Grid  Name="Popup" Visibility="Collapsed" Grid.Row="0" Width="480" Height="300" Background="Black">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
            <Canvas Name="ContentPanelCanvas"  Background="Beige">

            </Canvas>
            </Grid>
            <Grid Grid.Row="1" HorizontalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Button Grid.Column="0" x:Name="btnOK" Content="OK" Tap="btnOK_Tap"/>
                <Button Grid.Column="1" x:Name="btnCancel" Content="Clear" Tap="btnCancel_Tap"/>
            </Grid>
        </Grid>
</Grid>

Here is the .CS file:

    private Point currentPoint;
    private Point oldPoint;
    Line line;

    public SingleImage()
    {
        InitializeComponent();
        this.ContentPanelCanvas.MouseMove += new MouseEventHandler(ContentPanelCanvas_MouseMove);
        this.ContentPanelCanvas.MouseLeftButtonDown += new MouseButtonEventHandler(ContentPanelCanvas_MouseLeftButtonDown);

    }

    void ContentPanelCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        currentPoint = e.GetPosition(ContentPanelCanvas);
        oldPoint = currentPoint;
    }

    void ContentPanelCanvas_MouseMove(object sender, MouseEventArgs e)
    {

        currentPoint = e.GetPosition(this.ContentPanelCanvas);

        line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };

        line.Stroke = new SolidColorBrush(Colors.Purple);
        line.StrokeThickness = 3;

        this.ContentPanelCanvas.Children.Add(line);
        oldPoint = currentPoint;
    }

    private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        Popup.Visibility = Visibility.Visible;
        ContentPanelCanvas.Children.Clear();
    }

    private void btnOK_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        Popup.Visibility = Visibility.Collapsed;          
       // Here i want to set signature to main canvas how to pass signature
          from one canvas to another?//    
    }

    private void btnCancel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        ContentPanelCanvas.Children.Clear();
    }

Upvotes: 2

Views: 72

Answers (1)

Arun.P
Arun.P

Reputation: 163

private void btnOK_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        Popup.Visibility = Visibility.Collapsed;          
         int k = ContentPanelCanvas.Children.Count;
          for (int i = 0; i < k; i++)
          {
              line =(System.Windows.Shapes.Line)    ContentPanelCanvas.Children[0];
              line.StrokeThickness = 3;
              ContentPanelCanvas.Children.RemoveAt(0);
              maincanvas.Children.Add(line);
           }

    }

Upvotes: 1

Related Questions