I'm writing the WPF app that uses TreeView control inside the UserControl. TreeView control has the same width as the UserControl.
我正在编写在UserControl中使用TreeView控件的WPF应用程序。 TreeView控件的宽度与UserControl的宽度相同。
The problem is that I need to make the children nodes to have the full with of the TreeView. I can't assign the width by the static expression as well as UserControl that contains TreeView may have variable width.
问题是我需要让子节点充分利用TreeView。我不能通过静态表达式分配宽度,以及包含TreeView的UserControl可能具有可变宽度。
I thought that the solution can be reached by assigning the TreeView child item the width of the UserControl. But if I do so the TreeView child item will be out of control, as well as there is margin in the children item. For example
我认为可以通过为TreeView子项分配UserControl的宽度来达到解决方案。但是如果我这样做,TreeView子项将失控,并且子项中有余量。例如
Item A
---Item B
Can you tell, how can I get the width of --- ? Or to make ItemB be under the Item A without using static margin metrics?
你能告诉我,我怎样才能得到---的宽度?或者在不使用静态保证金指标的情况下将ItemB置于项目A下?
Thank you
1 个解决方案
#1
0
You can edit the Style of TreeViewItem and make its Horizontal Alignment as Stretch instead of Left. Also ensure you host your ContentPresenter inside the Grid.
您可以编辑TreeViewItem的样式并使其水平对齐为Stretch而不是Left。还要确保在Grid中托管ContentPresenter。
In this case, eventhough the header text seems to be leeser in width, the mouse hover or Selected color will cover the entire width of treeview. I hope that is what you need.
在这种情况下,尽管标题文本的宽度似乎是leeser,但鼠标悬停或选定颜色将覆盖树视图的整个宽度。我希望这就是你所需要的。
#1
0
You can edit the Style of TreeViewItem and make its Horizontal Alignment as Stretch instead of Left. Also ensure you host your ContentPresenter inside the Grid.
您可以编辑TreeViewItem的样式并使其水平对齐为Stretch而不是Left。还要确保在Grid中托管ContentPresenter。
In this case, eventhough the header text seems to be leeser in width, the mouse hover or Selected color will cover the entire width of treeview. I hope that is what you need.
在这种情况下,尽管标题文本的宽度似乎是leeser,但鼠标悬停或选定颜色将覆盖树视图的整个宽度。我希望这就是你所需要的。