尝试在WPF C#中设置datagrid单元格的属性时,我在堆栈上发现了一个帖子,它提供的内容看起来就像我需要的代码(希望如此) - 奇怪的是我无法让它编译,因为我看起来似乎无法找到如何正确声明Typeof。
代码:
var datagrid = new DataGrid();
Style columnStyle = new Style(Typeof(TextBlock));
datagrid.Columns.Add(new DataGridTextColumn()
{
ElementStyle = columnStyle
}
原始代码发布:
Set DataGridTextColumn.ElementStyle by background code
我要做的是模仿以下内容以启用textwrapping:
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
问题是Typeof在声明我的Style时,编译器输出了以下错误:
当前上下文中不存在名称“Typeof” 'System.Windows.Controls.TextBlock'是'type',但用作'变量'
我做了一些搜索,看看在C#中定义了什么Typeof,但实际上找不到任何东西......任何人都有任何线索?
答案 0 :(得分:4)
C#区分大小写
Typeof != typeof