WPF图表工具包。(WPF Chart Toolkit. Bind Label's content in ColumnDataPoint to ViewModel DataPoint Pro

编程入门 行业动态 更新时间:2024-10-25 18:24:19
WPF图表工具包。(WPF Chart Toolkit. Bind Label's content in ColumnDataPoint to ViewModel DataPoint Property)

我有一个扩展的ObservableCollection ,它包含数据点和一些额外的信息

public class ExtendedCollection : ObservableCollection<KeyValuePair<string, KeyValuePair<string,int>>> { }

然后我还有一个ViewModel,它持有使用此ExtendedCollection的ColumnSeries

private ExtendedCollection columnValues = new ExtendedCollection(); public ExtendedCollection ColumnValues { get { return columnValues; } set { columnValues = value; PropChanged("ColumnValues"); } }

最后,我试图在每个数据点列中模板化的标签上显示集合项的Value.Key

<chartingToolkit:ColumnSeries Name="columnSeries" DependentValuePath="Value.Value" IndependentValuePath="Key" ItemsSource="{Binding ColumnValues}"> <chartingToolkit:ColumnSeries.DataPointStyle> <Style TargetType="chartingToolkit:ColumnDataPoint"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="chartingToolkit:ColumnDataPoint"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Label Grid.Row="0" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type chartingToolkit:ColumnSeries}},Path=DataContext.ColumnValues.Value.Key, Mode=TwoWay}"></Label> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </chartingToolkit:ColumnSeries.DataPointStyle> </chartingToolkit:ColumnSeries>

我已经为Label的Content尝试了许多不同的Binding但没有效果。 如何将Content链接到ColumnDataPoint的Value.Key

I have an extended ObservableCollection that holds the datapoints plus some extra information

public class ExtendedCollection : ObservableCollection<KeyValuePair<string, KeyValuePair<string,int>>> { }

Then I also have a ViewModel holding the ColumnSeries that uses this ExtendedCollection

private ExtendedCollection columnValues = new ExtendedCollection(); public ExtendedCollection ColumnValues { get { return columnValues; } set { columnValues = value; PropChanged("ColumnValues"); } }

Finally, I am trying to display the collection items' Value.Key on a label templated in each datapoint's column

<chartingToolkit:ColumnSeries Name="columnSeries" DependentValuePath="Value.Value" IndependentValuePath="Key" ItemsSource="{Binding ColumnValues}"> <chartingToolkit:ColumnSeries.DataPointStyle> <Style TargetType="chartingToolkit:ColumnDataPoint"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="chartingToolkit:ColumnDataPoint"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Label Grid.Row="0" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type chartingToolkit:ColumnSeries}},Path=DataContext.ColumnValues.Value.Key, Mode=TwoWay}"></Label> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </chartingToolkit:ColumnSeries.DataPointStyle> </chartingToolkit:ColumnSeries>

I've tried many different Bindings for the Label's Content but none works. How can I link the Content to the Value.Key of ColumnDataPoint

最满意答案

ExtendedCollection属性没有Value属性,但列的DataContext具有:

<Label Grid.Row="0" Content="{Binding Value.Key}"></Label>

The ExtendedCollection property has no Value property but the DataContext of the column has:

<Label Grid.Row="0" Content="{Binding Value.Key}"></Label>

更多推荐

ColumnSeries,Value,Key,ColumnValues,chartingToolkit,电脑培训,计算机培训,IT培训"/>

本文发布于:2023-07-24 01:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具包   图表   Toolkit   Bind   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!