【问题标题】:WPF - Path Geometry...Is there a way to bind the Data Property?WPF - 路径几何......有没有办法绑定数据属性?
【发布时间】:2013-01-05 01:58:11
【问题描述】:

我有一个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】:

如果您想要一个可用于将字符串转换为路径数据的值转换器,您不妨试试我不久前写的universal value converter

或者,要绑定到单个属性,您必须通过将各种几何对象添加到 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-22
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多