【问题标题】:WPF Chart Toolkit. Bind Label's content in ColumnDataPoint to ViewModel DataPoint PropertyWPF 图表工具包。将 ColumnDataPoint 中 Label 的内容绑定到 ViewModel DataPoint 属性
【发布时间】:2017-09-19 14:09:36
【问题描述】:

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

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

}

然后我还有一个持有 ColumnSeries 的 ViewModel 使用这个 ExtendedCollection

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>

我为LabelContent 尝试了许多不同的Bindings,但没有一个有效。如何将Content 链接到ColumnDataPointValue.Key

【问题讨论】:

    标签: c# wpf wpftoolkit


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-01
      • 2011-08-26
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多