【发布时间】:2011-12-21 13:25:36
【问题描述】:
我有一个画布,我想调整其大小以适合背景 ImageBrush。
这里的一个障碍是控件被实例化,然后图像被传入并分配为 ImageBrush。另一个障碍是我正在为 WPF 和 Silverlight 制作此控件,并且 ImageBrush 不同(即它们不共享任何事件)。
编辑:
<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>
问题是,我没有使用 Image 控件,我使用的是 ImageBrush 控件,它没有高度和宽度。
【问题讨论】:
-
你能展示你的 XAML 吗?您可能可以将 Canvas 的
Height/Width绑定到 Image 的ActualHeight/ActualWidth -
嗨,使用 Canvas 代替 Grid 有什么特别的原因吗?前者将根据图像大小自行调整大小。
-
我在用这个控件用鼠标绘制不同的控件。
标签: wpf silverlight imagebrush