2014-03-01 51 views
0

好吧,我有辦法做到這一點如何綁定集合到一個網格WPF

enter image description here

,但我做的方式在C#像這樣

public partial class PlotTest 
    { 
     public PlotTest(double x, double y) 
     { 
      InitializeComponent(); 

      PlotControl.Margin = new Thickness(x, y, 0, 0); 
     } 

     public void setPlot(List<double> tempSol) 
     { 
      double step = (tempSol.Max() - tempSol.Min())/10; 

      for (int ctr = 0; ctr < 10; ctr++) 
      { 
       TextBlock rect = (TextBlock)PlotValue.Children[ctr]; 
       rect.Text = (ctr == 0) ? tempSol.Max().ToString("F") : 
          (ctr == 9) ? tempSol.Min().ToString("F") : 
          (tempSol.Max() - ctr * step).ToString("F"); 
       rect.TextAlignment = TextAlignment.Right; 
       rect.FontSize = 10; 
      } 
     } 
    } 
} 

,因爲我用C#做到這一點,我正在使用wpf我想找到一種方法將其綁定到一個collectionm,正是這一個

private List<double> tempsol = new List<double> {3.21, -5.41, -15.81, -21.69, -21.70, -12.60, -6.41, -0.06, 5.42, 13.32, 14.12, 7.55}; 

但是si nce我是新來的wpf,xaml我真的不確定如何做到這一點,我找不到任何直接適用於我的問題的解決方案我可以使用一些幫助謝謝。

回答

2

A Grid只是Panel的一種類型,但我不認爲它是從您的情況中選擇的正確的一種。

在事情的核心,你想要做的是直觀地顯示一系列值,它們恰好是雙值。當你想直觀地顯示一個序列時,你必須看一個ItemsControl(或這個類的派生物)。從那裏,你可以自定義每個元素是如何在視覺上表示,如何元素的整個序列也是在視覺上表示:

<ItemsControl ItemsSource="{Binding Path=MyCollection}"> 
    <ItemsControl.ItemsPanel> 
    <custom:SomePanel /> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
    <DataTemplate> 
     <!-- Some representation of each element --> 
    </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

當然,這裏有一些補充閱讀材料,如果你決定推出自己的Panel


或者,您可以使用已經創造出了什麼事:WPF chart controls