VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了WPF DataGrid绑定到string.Length而不是字符串文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 WPF的新手,我真的想尽可能地弄清楚自己…

我已经创建了我的第一个DataGrid控件,我试图用一个字符串列表填充它,如下所示:

@H_673_3@<UserControl x:Class="DataGridTest" xmlns="http://scheR_330_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_330_11845@as.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

但是,它实际上填充了标题“长度”,值为字符串的长度.为什么它本身没有填充字符串值?

很明显,我在这里缺少一些基本的东西,但我不能为我的生活弄清楚它是什么.

提前致谢!

因为DataGrid默认情况下会自动生成给定项类的列,所以它将搜索String类中可以转换为列的属性.您可以通过创建自己的列并关闭AutoGeneratecolumns来避免这种情况 @H_673_3@<DataGrid Name="MyDataGrid" Itemssource="{Binding}" ... AutoGeneratecolumns="false"> <DataGrid.columns> <DataGridTextcolumn Binding="{Binding}" Header="Something"/> </DataGrid.columns> </DataGrid>

大佬总结

以上是大佬教程为你收集整理的WPF DataGrid绑定到string.Length而不是字符串文本全部内容,希望文章能够帮你解决WPF DataGrid绑定到string.Length而不是字符串文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。