0
我試圖用WPF繪製一些分散圖表,並努力繪製通常出現在圖表軸上的小刻度標記。我的視圖模型使用每個軸的List<Tick>
來定義刻度的位置,其中每個Tick
項只是刻度落在軸上的笛卡爾座標。我有一個IMultiValueConverter
,它使用畫布大小將單個點轉換爲可以呈現的Line對象...但是如何將其綁定? WPF希望我指定X1,X2,Y1和Y2,但我只想給它一行。WPF - 使用返回一行的轉換器綁定一行
我的想法是定義如下的數據模板,但它不能編譯,因爲我不能直接給Line
多重綁定。是否有我可以使用的中間元素/屬性?
<DataTemplate DataType="{x:Type viewModel:Tick}" x:Key="TickTemplate">
<Line>
<WhatsMissing?>
<MultiBinding Converter="{StaticResource PointsConverter}">
<Binding Path="Points"/>
<Binding Path="DataContext.MinPoint" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
<Binding Path="DataContext.MaxPoint" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
<Binding Path="ActualWidth" ElementName="ChartCanvas"/>
<Binding Path="ActualHeight" ElementName="ChartCanvas"/>
</MultiBinding>
</WhatsMissing?>
</Line>
</DataTemplate>