【发布时间】:2017-01-12 15:04:00
【问题描述】:
您好,我对 WPF 中的折线有疑问。如何突出显示折线中的点,例如线是红色的,而 mypolyline.Points 中的点是蓝色的?
【问题讨论】:
您好,我对 WPF 中的折线有疑问。如何突出显示折线中的点,例如线是红色的,而 mypolyline.Points 中的点是蓝色的?
【问题讨论】:
Polyline 无法立即执行此操作,因为它仅呈现为连接线段的集合。
但是,您可以添加一个 ItemsControl 来呈现如下所示的点。它使用长度为零的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>
【讨论】: