简体   繁体   English

WPF 折线 - 如何突出显示点?

[英]WPF polyline - how to highlight points?

Hello I have a question about polylines in WPF.您好,我有一个关于 WPF 中折线的问题。 How to highlight points in polyline, for example lines are red, but points in mypolyline.Points are blue?如何突出折线中的点,例如线是红色的,但mypolyline.Points中的点是蓝色的?

A Polyline can't do that out of the box, since it renders as a collection of connected line segments only. Polyline不能开箱即用,因为它仅呈现为连接线段的集合。

You could however add an ItemsControl that renders the points like shown below.但是,您可以添加一个ItemsControl来呈现如下所示的点。 It uses Line elements of zero length, but with round start and end caps to show a dot.它使用零长度的Line元素,但使用圆形开始和结束帽来显示一个点。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM