无法在我的 WPF 网格中创建列 [英] Can't create Columns in my WPF Grid

查看:18
本文介绍了无法在我的 WPF 网格中创建列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的非常非常基本 WPF 项目的代码.

I have this code for my very very basic WPF Project.

<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>

但是,列定义行给了我一个错误:

However, the column definition line gives me an error:

错误 1 ​​无法将ColumnDefinition"类型的实例添加到UIElementCollection"类型的集合中.只允许使用UIElement"类型的项目.

Error 1 Cannot add instance of type 'ColumnDefinition' to a collection of type 'UIElementCollection'. Only items of type 'UIElement' are allowed.

推荐答案

你必须将它包含在一个 ColumnDefinitions 集合中.

you have to enclose it in a ColumnDefinitions collection.

<Grid Height="27">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
</Grid>

添加行定义的工作方式相同.

Adding row definitions works the same way.

享受吧!

这篇关于无法在我的 WPF 网格中创建列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆