我有以下XAML完美运行(以及myRectConverter类)。唯一的问题是我需要将其转换为VB.NET代码,以便可以在应用程序中动态生成。
<Canvas Grid.Column="0" Grid.Row="0" Height="{Binding ElementName=FeatureOverlay1, Path=ActualHeight}" HorizontalAlignment="Stretch" Name="Canvas1" VerticalAlignment="Stretch" Width="{Binding ElementName=FeatureOverlay1, Path=ActualWidth}" Background="Red">
<Canvas.Clip>
<RectangleGeometry x:Name="clipRect" RadiusX="5" RadiusY="5">
<RectangleGeometry.Rect>
<MultiBinding Converter="{StaticResource myRectConverter}">
<Binding ElementName="Canvas1" Path="Width"/>
<Binding ElementName="Canvas1" Path="Height"/>
</MultiBinding>
</RectangleGeometry.Rect>
</RectangleGeometry>
</Canvas.Clip>
<Image Canvas.Left="0" Canvas.Top="0" Name="TestImage" Stretch="Fill" Source="/FluidSize;component/Images/Desert.jpg" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Canvas>
这是我到目前为止所做的:
Dim rectGeometry As RectangleGeometry = New RectangleGeometry
rectGeometry.RadiusX = 5
rectGeometry.RadiusY = 5
Dim multiBinding As MultiBinding = New MultiBinding()
multiBinding.Converter = New RectConverter
Dim binding As Binding = New Binding()
binding.ElementName = "Canvas1"
binding.Path = New PropertyPath("Width")
multiBinding.Bindings.Add(binding)
binding = New Binding()
binding.ElementName = "Canvas1"
binding.Path = New PropertyPath("Height")
multiBinding.Bindings.Add(binding)
' Need to somehow add the multibinding object to the rectGeometry as a Rect structure, then assign to Canvas1.Clip
有谁知道如何使这个工作?
由于
本
答案 0 :(得分:1)
BindingOperations.SetBinding(rectGeometry, RectangleGeometry.RectProperty, multiBinding);
可替换地:
rectGeometry.SetBinding(RectangleGeometry.RectProperty, multiBinding);