【发布时间】:2013-08-02 15:31:10
【问题描述】:
我正在尝试在 c# 中设置 TreeViewItem -> StackPanel 的属性,例如 this question。在我尝试在Border 中编辑Background 的部分之前,这似乎很有意义。 Borders 中有 Background 对象,但对于我的生活,我无法设置颜色或任何东西。这似乎是不一致的,因为我可以通过简单地说 Content = "Title" 将 Content 添加到 Label。
无论如何,这是我的代码:
public static TreeViewItem childNode = new TreeViewItem() //Child Node
{
Header = new StackPanel
{
Orientation = Orientation.Horizontal,
Children =
{
new Border {
Width = 12,
Height = 14,
Background = ? //How do I set the background?
},
new Label {
Content = "Child1"
}
}
}
};
PS - 我在尝试添加 BorderBrush 时遇到同样的问题
谢谢!
【问题讨论】:
-
您有什么理由选择这种方法而不是视图/视图模型类型方法?
-
我还是刚开始使用 MVVM,发现有时不使用它更容易。
-
This MSDN article 可能会比您想要的更详细,但它可能会大大简化您的 WPF 开发。
标签: c# wpf background stackpanel