【发布时间】:2014-10-22 18:38:54
【问题描述】:
我是 WPF 的新手,我真的想尽可能多地自己弄清楚...
我已经创建了我的第一个 DataGrid 控件,我正在尝试使用如下字符串列表填充它:
<UserControl x:Class="DataGridTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Style="{StaticResource ContentRoot}">
<DataGrid Name="MyDataGrid" ItemsSource="{Binding}" HorizontalAlignment="Stretch" Height="500"/>
</Grid>
</UserControl>
Private Sub DataGridTest_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim StringCollection As List(Of String) = New List(Of String)
StringCollection.Add("Test")
StringCollection.Add("Test1")
StringCollection.Add("Test2")
StringCollection.Add("Test3")
StringCollection.Add("Test4")
MyDataGrid.DataContext = StringCollection
End Sub
但是,它实际上填充了标题“长度”和值作为字符串的长度。为什么它本身不填充字符串值?
很明显,我在这里遗漏了一些基本的东西,但我终生无法弄清楚它是什么。
提前致谢!
【问题讨论】:
标签: wpf vb.net binding datagrid