none
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?
    Code:
    Xaml
     
    <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="52*" />
                <RowDefinition Height="259*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <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" />
                </Canvas>
            </ScrollViewer>
            <Button Content="Init" Height="23" HorizontalAlignment="Left" Margin="54,12,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
    </Grid>
    
    cs
    
      private void button3_Click(object sender, RoutedEventArgs e)
            {
                this.listBox1.Items.Clear();
    
                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;
    
                this.listBox1.Items.Add(canvas);
            }
    
    Please help me!thanks!

    2012年1月6日 5:25

答案

  • I think your this post is same with your previous post: http://social.microsoft.com/Forums/zh-CN/wpfzhchs/thread/14b3a271-14da-4646-9f80-ba95cc6d6d44

    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.

    Sincerely,


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