Ben Fisher
Ben Fisher

Reputation: 13

WPF VB.NET RectangleGeometry Rect Structure Multibinding

I have the following XAML which works perfectly (along with the myRectConverter class). The only problem is I need this to be converted into VB.NET code so it can be produced in the application dynamically.

  <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>

Here is what I have so far:

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

Does anyone know how to get this working?

Thanks

Ben

Upvotes: 0

Views: 1121

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178710

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

Alternatively:

rectGeometry.SetBinding(RectangleGeometry.RectProperty, multiBinding);

Upvotes: 1

Related Questions