While trying to set a property of a datagrid cell in WPF C# I found a post on stack that provides what looks like exactly the code I need (hopefully) - oddly enough I can't get it to compile as I cannot seem to find how to properly declare Typeof.
Code:
var datagrid = new DataGrid();
Style columnStyle = new Style(Typeof(TextBlock));
datagrid.Columns.Add(new DataGridTextColumn()
{
ElementStyle = columnStyle
}
Original code posting:
Set DataGridTextColumn.ElementStyle by background code
What I am trying to do is mimic the following to enable textwrapping:
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
The issue is the Typeof when declaring my Style, the compiler outs the following errors:
The name 'Typeof' does not exist in the current context
'System.Windows.Controls.TextBlock' is a 'type' but is used like a 'variable'
I did a bit of searching to see in what Typeof is defined in C# but actually couldn't find anything ... anyone have any clues?
C#区分大小写
Typeof != typeof
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.