我有一个扩展的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培训"/>
发布评论