0

我有一个依赖属性,我想在图表上显示。

namespace ViewModels
{
  public partial class MyVM: DependencyObject
  {
    public Double TotalPowerSoFar
        {
            get { return (Double)GetValue(TotalPowerSoFarProperty); }
            set { SetValue(TotalPowerSoFarProperty, value); }
        }

        // Using a DependencyProperty as the backing store for GroupReadingsBy.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TotalPowerSoFarProperty =
            DependencyProperty.Register("TotalPowerSoFar", typeof(Double), typeof(EstimateVM), new UIPropertyMetadata(0.0));


    TotalPowerSoFar=5.0;
   }
}

我想我会做这样的事情:

<UserControl x:Class="Workspace"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DVC:Chart Name="mcChart"   Foreground="DarkBlue" Title="Area Chart" LegendTitle="Month Rating" >
                    <DVC:Chart.Series>
                        <DVC:ColumnSeries DependentValueBinding ="{Binding EstimatedTotalPower}"/>
                    </DVC:Chart.Series>
                </DVC:Chart>
</Grid>

但据我了解,绑定是错误的。有什么帮助吗?

4

1 回答 1

0

首先,依赖属性只对DependencyObject后代有意义,并且您的视图模型不是DependencyObject.

第二,如果您想扩展现有依赖对象的功能(Chart在您的情况下),您应该使用附加属性 - 它们可以附加到 DO 并将数据绑定到您的视图模型。

于 2012-08-02T09:34:33.523 回答