0

我有以下完美运行的 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

有谁知道如何让这个工作?

谢谢

4

1 回答 1

1
BindingOperations.SetBinding(rectGeometry, RectangleGeometry.RectProperty, multiBinding);

或者:

rectGeometry.SetBinding(RectangleGeometry.RectProperty, multiBinding);
于 2011-01-02T09:30:36.600 回答