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.

2 つ目は、既存の依存関係オブジェクトの機能を拡張する場合 (Chartこの場合)、添付プロパティを使用する必要があります。DO に添付し、ビュー モデルにデータ バインドすることができます。

于 2012-08-02T09:34:33.523 に答える