locked
Canvas Width and Height RRS feed

  • Question

  • Hello:

    I have a Canvas that I am setting the background.  However, I do not want to STRETCH the background at all; I want to see the background in its native resolution.  However, if the image is larger than the display area, I am not seeing any scrollbars.  I've tried using the ScrollViewer, but it is not working.  Any suggestions?

    Here's what I have:

    <Canvas Width="Auto" Height="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
    </Canvas>
    

    I've even tried creating a ScrollViewer and have a Canvas element inside, but that doesn't work either.  Any ideas?

     

    Trecius

    Monday, December 19, 2011 6:54 PM

Answers

  • Then something like this should work:

            <Canvas Background="{Binding SomeBrush}"
                    Width="{Binding SomeBrush.ImageSource.Width}"
                    Height="{Binding SomeBrush.ImageSource.Height}">
                
            </Canvas>
    
    

     

    • Marked as answer by Trecius Monday, December 19, 2011 8:16 PM
    Monday, December 19, 2011 7:20 PM

All replies

  • What exactly is this background you are talking about? Something like an ImageBrush that you set as the Background of the canvas?

    Anyway, keep in mind that the background of a control doesn't affect it's layout. If you want the control size to match the background you'll have to use some explicit width/height values.

    Monday, December 19, 2011 7:06 PM
  • Yes, the Background of the canvas is bound to an ImageBrush.  Because it is bound, I guess I don't really know the width and the height.  Is it possible to get this information from the databinding?

     

    Trecius

    Monday, December 19, 2011 7:14 PM
  • Then something like this should work:

            <Canvas Background="{Binding SomeBrush}"
                    Width="{Binding SomeBrush.ImageSource.Width}"
                    Height="{Binding SomeBrush.ImageSource.Height}">
                
            </Canvas>
    
    

     

    • Marked as answer by Trecius Monday, December 19, 2011 8:16 PM
    Monday, December 19, 2011 7:20 PM