1

I have a canvas that I want sized to fit a background ImageBrush.

One hurdle here is that the control is being instantiated and then the image is being passed in and assigned as the ImageBrush. The other hurdle is that I'm making this control for both WPF and Silverlight and the ImageBrush is different (i.e. they share no events).

Edit:

<UserControl x:Class="Escalon.Annotations.AnnotationControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="400" Width="500" >
    <ScrollViewer Name="ctlScrollViewer" HorizontalScrollBarVisibility="Auto" Height="400" Width="500">
        <Canvas Name="ctlSizingCanvas" >
            <Canvas  Name="ctlCanvas" Loaded="ctlCanvas_Loaded" Height="400" Width="500"
                MouseLeftButtonDown="MouseLeftButtonDownHandler" MouseMove="Canvas_MouseMove" MouseLeftButtonUp="Canvas_MouseLeftButtonUp" >
                <Canvas.RenderTransform>
                    <ScaleTransform x:Name="ctlZoomTransform" />
                </Canvas.RenderTransform>
                <Canvas.Background>
                    <ImageBrush ImageSource="{Binding Source}" Stretch="UniformToFill" ></ImageBrush>
                </Canvas.Background>
            </Canvas>
        </Canvas>
    </ScrollViewer>
</UserControl>

The problem is, i'm not using an Image control, I'm using an ImageBrush control, which doesn't have height and width.

PhilBrown
  • 2,949
  • 7
  • 34
  • 53
  • Can you show your XAML? You can probably bind the Canvas's `Height` / `Width` to the Image's `ActualHeight` / `ActualWidth` – Rachel Dec 21 '11 at 13:59
  • Hi, is there any particular reason to use Canvas instead of Grid? The former will size itself by the size of the image. –  Dec 21 '11 at 15:43
  • I am using this control to draw different controls with the mouse. – PhilBrown Dec 21 '11 at 17:22

1 Answers1

0

Instead of using ImageBrush, I just added the image to the canvas and bound the Canvas size to the Image size.

PhilBrown
  • 2,949
  • 7
  • 34
  • 53
  • I know its been a while and I've tried to do that and the canvas doesn't show for some reason...is there an example you could share? – g00n3r Aug 25 '20 at 16:14