简体   繁体   中英

Binding a Canvas size to the image size in its background ImageBrush

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 (ie 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.

我没有使用ImageBrush,而是将图像添加到画布,并将Canvas大小绑定到Image大小。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM