我正在研究Silverlight应用程序,我想通过XAML绑定Canvas Width和Height,但是我如何绑定它。因为画布的宽度和高度我试图绑定它但是在我的情况下不能工作所以如果你伙计们有任何其他绑定方式来绑定它所以请放一些代码,以便我可以找出这个问题的解决方案。
我想将它与图像高度和宽度绑定,所以有时候图像尺寸为1000 x 1200,有时图像尺寸为1400 x 1700,所以如何绑定它?
<Viewbox
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2">
<Canvas
Height="1000"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="1200">
<Image x:Name="imgEdit"
Cursor="Hand"
MouseLeftButtonDown="imgEdit_MouseLeftButtonDown"
MouseMove="imgEdit_MouseMove"
MouseLeftButtonUp="imgEdit_MouseLeftButtonUp"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RenderTransformOrigin="0.5, 0.5">
<Image.Effect>
<l:briconEffect
Brightness="{Binding ElementName=bVal, Path=Value}"
Contrast="{Binding ElementName=cVal, Path=Value}"
Gamma="{Binding ElementName=gVal,Path=Value}"
RedRatio="{Binding ElementName=rVal,Path=Value}"
BlueRatio="{Binding ElementName=blueVal,Path=Value}"
GreenRatio="{Binding ElementName=greenVal,Path=Value}"/>
</Image.Effect>
<Image.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="Rotator">
<RotateTransform.Angle>
<Binding ElementName="sldVerHorizontal" Path="Value" Mode="TwoWay"/>
</RotateTransform.Angle>
</RotateTransform>
<ScaleTransform x:Name="Scale">
<ScaleTransform.ScaleX>
<Binding ElementName="sldZoomInOut" Path="Value" Mode="TwoWay"/>
</ScaleTransform.ScaleX>
<ScaleTransform.ScaleY>
<Binding ElementName="sldZoomInOut" Path="Value" Mode="TwoWay"/>
</ScaleTransform.ScaleY>
</ScaleTransform>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Border
x:Name="maskBorder"
MinWidth="200"
MinHeight="200"
BorderBrush="Black"
BorderThickness="5"
Canvas.Left="250"
Cursor="Hand"
Canvas.Top="250">
<Rectangle
MinWidth="200"
MinHeight="200"
x:Name="maskRect"
Canvas.Left="250"
Cursor="Hand"
Canvas.Top="250">
</Rectangle>
</Border>
</Canvas>
</Viewbox>
答案 0 :(得分:0)
您可以使用像此
的元素绑定来绑定Canvas Width和Height属性宽度= {Binding Element = imgEdit,Path = ActualWidth} 高度= {Binding Element = imgEdit,Path = ActualHeight}
您也可以将Canvas包装在固定宽度和高度的ScrollViewer中,以限制用户屏幕尺寸。