2011-01-02 19 views
0

次のXAMLは完全に(myRectConverterクラスと共に)動作します。唯一の問題は、アプリケーションで動的に生成できるように、これをVB.NETコードに変換する必要があることです。ここでWPF VB.NET RectangleGeometry Rect構造体マルチバインド

<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 

は、この作業を取得する方法を誰もが知っていますか?

おかげ

ベンまた

答えて

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

rectGeometry.SetBinding(RectangleGeometry.RectProperty, multiBinding); 
+0

こんにちはケント。提案していただきありがとうございますが、期待される結果を達成していないようです。 rectGeometryはSetBindingを使用できないため、BindingOperationsオプションを使用しました。 RectConverterクラスが呼び出されると、次のエラーが表示されます。「型 'NamedObject'から 'Double'型への変換は無効です」。デバッガでオブジェクトを参照すると、Rect構造体が空でCanvas1 Width/HeightプロパティがRect構造体ではなくRectangularGeometryオブジェクトのルートにバインドされていることがわかります。 –