c# - 无法在我的 WPF 网格中创建列

标签 c# wpf grid

我的非常非常基本的 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/

相关文章:

c# - 匹配字符串(段落)中的大型短语字典中的项目的有效方法是什么

wpf - WPF中如何显示多层控件?

c# - 随着时间的推移,DispatcherTimer 会占用 CPU,导致 WPF 视觉对象无法正确呈现

php - 为 PHP 查询创建 GridView

c# - 如何播放 Windows 通知声音? (它未在 System.Media.SystemSounds 中定义)

c# - XAML - ListViewItem - IsEnabled 绑定(bind)

c# - 在工作组的情况下,如何在远程计算机上授予 Windows 服务访问权限?

c# - 如何创建 dpi 感知 wpf 应用程序?

python - 在扫雷器的网格中放置 1's around "b"

android - Android 中的 GMGridView 等价物