답변됨 Re-render Canvas

  • 2012년 8월 8일 수요일 오후 9:59
     
      코드 있음

    Hi, there.

    I working in a kind of a paint program which can zoom in and out and has a pan option too.

    I have implemented the code in a Canvas object.

    Now, how can I re-render the canvas and replace it to fit the outside border?

    Thanks,

    Tiago.

    <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Name="MenuColumn" Width="250" />
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Name="PreviousButton">Previous</Button>
                <Button Name="ForwardButton">Forward</Button>
            </StackPanel>

            
            <!--<Border Grid.Row="1" Grid.Column="0" Name="MeshBorder" BorderBrush="red" BorderThickness="2">-->
            <Viewbox Grid.Row="1" Grid.Column="0" Stretch="UniformToFill">
                <Canvas Name="MeshCanvas" Background="Gray">
                    <Canvas.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform x:Name="st" />
                            <TranslateTransform x:Name="tt" />
                        </TransformGroup>
                    </Canvas.RenderTransform>
                    <Ellipse Canvas.Left="58" Canvas.Top="71" Height="65" Name="ellipse1" Stroke="Black" Width="84" />
                </Canvas>
            <!--</Border>-->
            </Viewbox>

            <Grid Grid.Row="1" Grid.Column="1" Height="500" Width="250">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ItemsControl Grid.Column="0" ItemsSource="Menu" HorizontalAlignment="Center" />
                <StackPanel Grid.Column="1">
                    <Button HorizontalAlignment="Right">Pin</Button>
                    <Button>Test Button</Button>
                </StackPanel>
            </Grid>
        </Grid>

    Private Sub MeshCanvas_MouseWheel(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseWheelEventArgs) Handles MeshCanvas.MouseWheel
    
            Dim zoom As Double = 0
            If e.Delta > 0 Then
                zoom = 0.2
            Else
                zoom = -0.2
            End If
            Dim center As Point = e.GetPosition(MeshCanvas)
            st.ScaleX = st.ScaleX * (1 + zoom)
            st.ScaleY = st.ScaleY * (1 + zoom)
            st.CenterX = center.X
            st.CenterY = center.Y
            
        End Sub
    
        Dim start As Point
        Private Sub MeshCanvas_MouseLeftButtonDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles MeshCanvas.MouseLeftButtonDown
    
            MeshCanvas.CaptureMouse()
            start = e.GetPosition(MeshCanvas)
    
        End Sub
    
        Private Sub MeshCanvas_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles MeshCanvas.MouseMove
    
            Dim currentPoint As Point = e.GetPosition(MeshCanvas)
            If MeshCanvas.IsMouseCaptured Then
                tt.X = tt.X + (currentPoint.X - start.X)
                tt.Y = tt.Y + (currentPoint.Y - start.Y)
            End If
    
        End Sub
    
        Private Sub MeshCanvas_MouseLeftButtonUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles MeshCanvas.MouseLeftButtonUp
            MeshCanvas.ReleaseMouseCapture()
        End Sub

모든 응답

  • 2012년 8월 9일 목요일 오전 9:24
     
     

    Hi,

    i think you can re-render you can by accessing e.Source property as follows

    (e.Source as Canvas).LayoutTransform=st


    Thanks & Regards dhampall

  • 2012년 8월 10일 금요일 오전 6:44
    중재자
     
     답변됨

    Hi Lion's Claw,

    I think the simply method is remove your canvas from parent control, and then add it again, it will re-render.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • 2012년 8월 17일 금요일 오전 7:20
    중재자
     
     

    Hi Lion's Claw,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.