WPF-路径几何...是否有绑定数据属性的方法? [英] WPF - Path Geometry...Is there a way to bind the Data Property?

查看:62
本文介绍了WPF-路径几何...是否有绑定数据属性的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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完成吗?由于某种原因,我无法可视化解决方案.我也乐意接受其他选择.

感谢阅读,如果我能提供更多信息,请询问.

解决方案

如果您想要一个可用于将字符串转换为路径数据的值转换器,则可以尝试使用

I have a ControlTemplate that serves as a "Bubble" popup on the AdornerLayer of a given control.

It works fine but I need to be able to calculate where it should display (middle/ bottom).

Instead of:

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

I am looking for (obviously this won't work but it illustrates what I'm trying to accomplish:

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

Can this be done with a ValueConverter? I just can't visualize a solution for some reason. I'm also open to alternatives.

Thanks for reading and if I can provide more info please just ask.

解决方案

If you want a value converter that you can use to convert a string into the path data, you might like to try the universal value converter I wrote a while back.

Alternatively, to bind to a single property, you will have to expand your geometry by adding the various geometry objects into your XAML, rather than using the string shorthand. For example ...

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

这篇关于WPF-路径几何...是否有绑定数据属性的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆