WPF - 路径几何...有没有办法绑定数据属性?

问题描述 投票:0回答:1

我有一个

ControlTemplate
,用作给定控件的
AdornerLayer
上的“气泡”弹出窗口。

它工作正常,但我需要能够计算它应该显示的位置(中间/底部)。

代替:

<Path Stroke="Black" Fill="Black" Data="M 15 20 L 15 0 33 20" Margin="0 1 0 0"/>

我正在寻找(显然这行不通,但它说明了我正在努力实现的目标:

<Path Stroke="Black" Fill="Black" Data="M {TemplateBinding Left} 20 L 15 0 33 20"/>

这可以用

ValueConverter
来完成吗?由于某种原因我无法想象解决方案。我也对替代方案持开放态度。

感谢您的阅读,如果我可以提供更多信息,请询问。

wpf xaml data-binding path geometry
1个回答
10
投票

如果您想要一个可用于将字符串转换为路径数据的值转换器,您可能想尝试一下通用值转换器我不久前写过。

或者,要绑定到单个属性,您必须通过将各种几何对象添加到 XAML 中来扩展几何图形,而不是使用字符串简写。例如...

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure IsClosed="True" StartPoint="10,100">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <LineSegment Point="{Binding MyPropertyPath}" />
                <LineSegment Point="100,50" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>
© www.soinside.com 2019 - 2024. All rights reserved.