【发布时间】:2012-10-27 22:40:03
【问题描述】:
我正在尝试使用以下代码更改一组以编程方式生成的列表框周围的边距:
newListBox.Margin = new Thickness(0, 0, 0, 0);
但是这给了我错误:
the type or namespace Thickness could not be found
我尝试添加 using System.Windows 命名空间,但仍然遇到同样的错误。有人可以帮忙吗?
【问题讨论】:
我正在尝试使用以下代码更改一组以编程方式生成的列表框周围的边距:
newListBox.Margin = new Thickness(0, 0, 0, 0);
但是这给了我错误:
the type or namespace Thickness could not be found
我尝试添加 using System.Windows 命名空间,但仍然遇到同样的错误。有人可以帮忙吗?
【问题讨论】:
我相信您正在寻找Padding。见Control.Margin
newListBox.Margin = new Padding(0, 0, 0, 0);
【讨论】:
System.Windows.Thickness 是演示框架的一部分。如果您不使用 WPF 或 Silverlight,请尝试引用 PresentationFramework.dll 以访问 Thickness 结构。
但恐怕在这种情况下您的ListBox.Margin 不会接受Thickness 类型的对象。如果您使用的是 WinForms,请尝试 System.Windows.Forms.Padding。
【讨论】:
情报是你的朋友。如您所见,您想使用 Padding 对象。
【讨论】: