我的非常非常基本的 WPF 项目有这段代码。
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid ShowGridLines="True">
<ColumnDefinition x:Name="LeftColumn"></ColumnDefinition>
</Grid>
但是,列定义行给我一个错误:
Error 1 Cannot add instance of type 'ColumnDefinition' to a collection of type 'UIElementCollection'. Only items of type 'UIElement' are allowed.
最佳答案
您必须将其包含在 ColumnDefinitions 集合中。
<Grid Height="27">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
添加行定义的方式相同。
尽情享受吧!
关于c# - 无法在我的 WPF 网格中创建列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1719093/