VisualBrush of ViewboxUnits set to absolute,The canvas is applied visualbrush problem with the scroll bars? RRS feed

  • 问题

  • Hi
    I want to achieve on a Canvas thumbnails, use visualbrush.
    Because the contents inside the canvas may be moving beyond the boundaries,Therefore, VisualBrush's ViewboxUnits properties set absolute.However, if the scroll bar appears when the canvas,Drag the scroll bar on the canvas, the thumbnail will move.If ViewboxUnits is a relative value, the thumbnail is not moving.
    ViewboxUnits is the absolute value of the case,How to make thumbnail does not move?
                <RowDefinition Height="52*" />
                <RowDefinition Height="259*" />
                <ColumnDefinition />
                <ColumnDefinition />
            <ListBox Grid.Column="1" Grid.RowSpan="2" Name="listBox1" />
            <ScrollViewer Name="scrollViewer1" Grid.Row="1"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                <Canvas Name="canvas1" Background="Aqua" Width="300" Height="300" AllowDrop="True">
                    <Button Canvas.Left="154" Canvas.Top="82" Content="Button" Height="35" Name="button4" Width="75" />
            <Button Content="Init" Height="23" HorizontalAlignment="Left" Margin="54,12,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
      private void button3_Click(object sender, RoutedEventArgs e)
                Canvas canvas = new Canvas();
                canvas.Width = this.listBox1.ActualWidth;
                canvas.Height = this.listBox1.ActualHeight / 5;
                VisualBrush brush =new VisualBrush();
                brush.Visual = this.canvas1;
                //brush.Viewbox = new Rect(0, 0, 300, 300);
                //brush.ViewboxUnits = BrushMappingMode.Absolute;
                canvas.Background = brush;
    Please help me!thanks!

    2012年1月6日 5:25


  • I think your this post is same with your previous post:

    And I have discussed with my colleagues, unfortnately, we do not find any solution for this behaviour. It is by design. The Absolute unit for the ViewPort just render the spcific region from the visual. And the ScrollViewer just changes the display content region, (0,0 ~ 300,300) region is just rendered as the shown in the ScrollViewer, so we will view the content be moved. You should change the ViewboxUnits to RelativeToBoundingBox.

    But I have seen your other issue when we set the unit to the RelativeToBoundingBox. So I think you just want to get the thumbnail from the left part. You could try to use the RenderTargetBitmap class to get the left part visual, and display the image in the right part.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    • 已标记为答案 张柱敏 2012年1月10日 9:18
    2012年1月9日 3:34