我有一個包含Curve對象列表的Log對象。每條曲線都有一個Name屬性和一個雙精度數組。我希望名稱位於列標題和它下面的數據中。我有一個用datagid的用戶控件。這是XAML;如何將數組綁定到WPF數據網格中的列
<UserControl x:Class="WellLab.UI.LogViewer"
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"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="500">
<Grid>
<StackPanel Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="stackPanel1" VerticalAlignment="Stretch" Width="Auto">
<ToolBarTray Height="26" Name="toolBarTray1" Width="Auto" />
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" CanContentScroll="True" Background="#E6ABA4A4">
<DataGrid AutoGenerateColumns="True" Height="Auto" Name="logDataGrid" Width="Auto" ItemsSource="{Binding}" HorizontalAlignment="Left">
</DataGrid>
</ScrollViewer>
</StackPanel>
</Grid>
在後面我已經找到了如何創建列,他們的名字,但我還沒有想出如何綁定數據的代碼。
public partial class LogViewer
{
public LogViewer(Log log)
{
InitializeComponent();
foreach (var curve in log.Curves)
{
var data = curve.GetData();
var col = new DataGridTextColumn { Header = curve.Name };
logDataGrid.Columns.Add(col);
}
}
}
我甚至不會顯示我試圖用綁定的數組「數據」的代碼,因爲沒有甚至差點。我確信我錯過了一些簡單的事情,但經過幾個小時的搜索網絡,我不得不乞求答案。
可能重複的[如何顯示的數組元素在WPF DataGrid中?](http://stackoverflow.com/questions/5582226/how-can-i-display-array-elements-in-a-wpf-datagrid) –
@dbaseman:這對陣列沒有幫助因爲沒有b處理它們的內在邏輯。 –
@ H.B。謝謝澄清。我誤解了這個問題。 – McGarnagle