【问题标题】:WPF polyline - how to highlight points?WPF折线 - 如何突出显示点?
【发布时间】:2017-01-12 15:04:00
【问题描述】:

您好,我对 WPF 中的折线有疑问。如何突出显示折线中的点,例如线是红色的,而 mypolyline.Points 中的点是蓝色的?

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

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>

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2017-09-12
    • 2023-03-05
    • 1970-01-01
    • 2020-02-06
    相关资源
    最近更新 更多