簡體   English   中英

WPF 折線 - 如何突出顯示點?

[英]WPF polyline - how to highlight 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM