Can#39;t create Columns in my WPF Grid(无法在我的 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 网格中创建列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在我的 WPF 网格中创建列
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
