WPF VB.NET RectangleGeometry 矩形结构多重绑定

发布于 2024-10-09 16:17:16 字数 1758 浏览 9 评论 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

有人知道如何让它工作吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿与i 2024-10-16 16:17:16
BindingOperations.SetBinding(rectGeometry, RectangleGeometry.RectProperty, multiBinding);

或者:

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

Alternatively:

rectGeometry.SetBinding(RectangleGeometry.RectProperty, multiBinding);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文