【问题标题】:How to bind a polyline in template?如何在模板中绑定折线?
【发布时间】:2012-08-14 14:50:25
【问题描述】:

我正在尝试在控件模板中绑定折线的点。这些点应该绑定到代码隐藏中的点集合。我目前的xaml代码如下:

<Style TargetType="{x:Type c:LineDragThumb}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type c:LineDragThumb}">
                <Polyline Stroke="Transparent" Points="{Binding}"
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我是否需要创建一个依赖属性来保存点集合?

请指导..

【问题讨论】:

标签: wpf templates polyline


【解决方案1】:

不,您可以在代码隐藏中使用简单的 Notifiable property of PointCollection 进行绑定,但请确保实现 INotifyPropertyChanged 以刷新 UI 上的绑定。

public PointCollection Points { get; set; }

要绑定 xaml,您可以这样做 -

<Polyline Stroke="Transparent" Points="{Binding Points,
       RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 2013-11-13
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    相关资源
    最近更新 更多