2012-02-27 8 views
0

誰かがちょっとイライラした問題を助けてくれることを願っています。Silverlightデータバインディングの問題 - POCOにバインディングされていない - Visifire

私はGraph(visifire)を持っていますが、標準のSilverlightデータバインドコントロールとして見ています。

INotifyPropertyChangedから継承するオブジェクト(カスタム)のリスト<を含むPOCOオブジェクトに直接バインドしようとすると、何も起こりません!

これにより私の辞書エントリクラス

class GraphValue : INotifyPropertyChanged 
    { 

    public event PropertyChangedEventHandler PropertyChanged; 

    private string name; 
    public string IndicatorName 
    { 
     get 
     { 
      return name;     
     } 

     set 
     { 
      name = value; 
      onPropertyChanged(this, "IndicatorName"); 
     } 
    } 
    private double _value; 
    public double IndicatorValue 
    { 
     get 
     { 
      return _value; 
     } 
     set 
     { 
      _value = value; 
      onPropertyChanged(this, "IndicatorValue"); 
     } 
    } 

    private void onPropertyChanged(object sender, string propertyName) 
    { 
     if (this.PropertyChanged != null) 
     { 
      PropertyChanged(sender, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

は、私は、リストを作成し、それをClosedSameDayListと呼ばPOCOクラスの内部で入れています。データはうまく取り込まれ、チェックされています。

最終的にdatacontextを設定すると、何も起こりません!

MyGraph.DataContext = ClosedSameDayList.GraphValues.OrderBy(z => z.IndicatorName); 

ただし、ここではキッカーです。

次の操作を実行すると、すべての作品:XAMLこれにより

ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>(); 

foreach (var item in ClosedSameDayList.GraphValues) 
{ 
    g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue)); 
}  
MyGraph.DataContext = g.OrderBy(z => z.Key); 

をチャート用:

  <vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts" DataContext="{Binding}" Name="MyGraph" Height="240" BorderThickness="0" Theme="Theme2" View3D="True" ToolBarEnabled="True" > 
       <vc:Chart.Titles> 
        <vc:Title Text="My Title" /> 
       </vc:Chart.Titles> 
       <vc:Chart.AxesX> 
        <vc:Axis Title="My Title" /> 
       </vc:Chart.AxesX> 
       <vc:Chart.AxesY> 
        <vc:Axis Title="My Title" AxisType="Primary" /> 
       </vc:Chart.AxesY> 
       <vc:Chart.Series> 
        <vc:DataSeries RenderAs="Column" DataSource="{Binding}"> 
         <vc:DataSeries.DataMappings> 
          <vc:DataMapping MemberName="AxisXLabel" Path="IndicatorName"></vc:DataMapping> 
          <vc:DataMapping MemberName="YValue" Path="IndicatorValue"></vc:DataMapping> 
         </vc:DataSeries.DataMappings> 
        </vc:DataSeries> 
       </vc:Chart.Series> 
      </vc:Chart> 

これによりコードClosedSameDay

ため
class ClosedSameDay 
    { 
     public CamlQuery CamlQuery { get; set; } 
     public List List { get; set; } 
     public ListItemCollection Listitems { get; set; } 
     public List<GraphValue> GraphValues { get; set; } 

     public ClosedSameDay() 
     { 
      GraphValues = new List<GraphValue>(); 
      CamlQuery = new CamlQuery(); 
      CamlQuery.ViewXml = "<View>" + 
      " <Method Name='ITServicedesk_Dashboard_ClosedSameday_Individuals_Readlist'/>" + 
      " <Query>" + 
      "  <OrderBy>" + 
      "   <FieldRef Name='id'/>" + 
      "  </OrderBy>" + 
      "  </Query>" + 
      "  <ViewFields>" + 
      "   <FieldRef Name='id'/>" + 
      "   <FieldRef Name='Name'/>" + 
      "   <FieldRef Name='Total'/>" + 
      "  </ViewFields>" + 
      "</View>"; 
     } 
     public void PopulateObjectData() 
     { 
      foreach (ListItem item in Listitems) 
      { 
       double value = -1; 
       double.TryParse(item["Total"].ToString(), out value); 

       if (item["Name"] != null && !string.IsNullOrEmpty(item["Name"].ToString()) && value != -1) 
       { 
        this.GraphValues.Add(new GraphValue 
        { 
         IndicatorName = item["Name"].ToString(), 
         IndicatorValue = value 
        }); 
       } 
      } 
     } 
     public DataSeries BuildDataSeries() 
     { 

      ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>(); 
      foreach (var item in this.GraphValues) 
      { 
       g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue)); 
      } 
      Visifire.Charts.DataSeries ds = new Visifire.Charts.DataSeries(); 
      ds.RenderAs = Visifire.Charts.RenderAs.Column; 
      ds.DataSource = g.OrderBy(i => i.Key); 

      Visifire.Charts.DataMapping dm = new Visifire.Charts.DataMapping(); 
      dm.MemberName = "AxisXLabel"; 
      dm.Path = "Key"; 
      ds.DataMappings.Add(dm); 

      Visifire.Charts.DataMapping dm2 = new Visifire.Charts.DataMapping(); 
      dm2.MemberName = "YValue"; 
      dm2.Path = "Value"; 
      ds.DataMappings.Add(dm2); 

      return ds; 
     } 
    } 
+0

XAMLを共有できるため、バインディング設定を理解しやすくなりますか? – Vivek

+0

XAMLを共有してくれてありがとう。私はVisioの最新バージョンを使用してPOCOクラスで同じものを作成しようとしました。ここでうまくいきます。使用しているVisifireのバージョンは? ClosedSameDayListのコードを共有できますか? – Somnath

+0

こんにちは。私はVisifire 4.0.0.0を使用しています。 ClosedSameDayクラスのインスタンスであるClosedSameDayListクラスのコードで質問を更新しました。 – Fox

答えて

0

私はこの質問を閉じます。以下のマニュアルデータバインディングメソッドを使用してDataSeriesを作成すると、すべて正常に動作します

public DataSeries BuildDataSeries() 
{ 

    ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>(); 
    foreach (var item in this.GraphValues) 
    { 
     g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue)); 
    } 
    Visifire.Charts.DataSeries ds = new Visifire.Charts.DataSeries(); 
    ds.RenderAs = Visifire.Charts.RenderAs.Column; 
    ds.DataSource = g.OrderBy(i => i.Key); 

    Visifire.Charts.DataMapping dm = new Visifire.Charts.DataMapping(); 
    dm.MemberName = "AxisXLabel"; 
    dm.Path = "Key"; 
    ds.DataMappings.Add(dm); 

    Visifire.Charts.DataMapping dm2 = new Visifire.Charts.DataMapping(); 
    dm2.MemberName = "YValue"; 
    dm2.Path = "Value"; 
    ds.DataMappings.Add(dm2); 

    return ds; 
} 
0

"Quick Start With DataBinding"サンプルapplicaionフォームを試してみてくださいVisibire Example Area.

+0

私は何らかの理由でそれが機能していない。それは、データバインドしないPOCOオブジェクトを扱うときだけです。 – Fox

関連する問題