簡體   English   中英

如何將集合綁定到網格WPF

[英]how to bind collection to a grid WPF

好吧,我有辦法實現這一目標

在此處輸入圖片說明

但是我像這樣在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};

但是由於我對wpf,xaml不熟悉,所以我真的不確定該怎么做,並且找不到任何直接適用於我的問題的解決方案,我可以使用一些幫助謝謝。

Grid只是Panel ,但是我認為這不是您所要選擇的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圖表控件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM