WPF 折线 - 如何突出显示点? [英] WPF polyline - how to highlight points?

查看:29
本文介绍了WPF 折线 - 如何突出显示点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个关于 WPF 中折线的问题.如何突出折线中的点,例如线是红色的,但mypolyline.Points 中的点是蓝色的?

解决方案

Polyline 不能开箱即用,因为它仅呈现为连接线段的集合.

然而,您可以添加一个 ItemsControl 来呈现如下所示的点.它使用零长度的 Line 元素,但使用圆形开始和结束帽来显示一个点.

<ItemsControl ItemsSource="{Binding Points, ElementName=polyline}"><ItemsControl.ItemsPanel><ItemsPanelTemplate><画布/></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemContainerStyle><Style TargetType="ContentPresenter"><Setter Property="Canvas.Left" Value="{Binding X}"/><Setter Property="Canvas.Top" Value="{Binding Y}"/></风格></ItemsControl.ItemContainerStyle><ItemsControl.ItemTemplate><数据模板><Line Stroke="蓝色" StrokeThickness="5"StrokeStartLineCap="Round" StrokeEndLineCap="Round"/></数据模板></ItemsControl.ItemTemplate></ItemsControl>

Hello I have a question about polylines in WPF. How to highlight points in polyline, for example lines are red, but points in mypolyline.Points are blue?

解决方案

A Polyline can't do that out of the box, since it renders as a collection of connected line segments only.

You could however add an ItemsControl that renders the points like shown below. It uses Line elements of zero length, but with round start and end caps to show a dot.

<Polyline x:Name="polyline" Points="10,10 50,50 90,10" Stroke="Red"/>

<ItemsControl ItemsSource="{Binding Points, ElementName=polyline}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left" Value="{Binding X}"/>
            <Setter Property="Canvas.Top" Value="{Binding Y}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Line Stroke="Blue" StrokeThickness="5"
                  StrokeStartLineCap="Round" StrokeEndLineCap="Round"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

这篇关于WPF 折线 - 如何突出显示点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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