C# 图表的依赖项属性

C# 图表的依赖项属性,c#,wpf,xaml,dependency-properties,C#,Wpf,Xaml,Dependency Properties,我有一个依赖属性,我想在图表上显示 namespace ViewModels { public partial class MyVM: DependencyObject { public Double TotalPowerSoFar { get { return (Double)GetValue(TotalPowerSoFarProperty); } set { SetValue(TotalPowerSoFarPro

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

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>


但据我所知,绑定是错误的。有帮助吗?

首先,依赖项属性仅对
DependencyObject
子体有意义,并且您的视图模型不是
DependencyObject


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

Dennis,我需要为我的项目使用依赖项属性,让我们想当然吧。我编辑了MyVM,使其成为一个DependencyObject。你能帮助我如何将其绑定到图表上吗?@yiannis,在我看来,你误解了DP的概念。请为am XAML样本提供您所需的
TotalPowerSoFar
dependency属性。