在WPF TreeView上对齐按钮 [英] Align buttons on wpf treeview

查看:216
本文介绍了在WPF TreeView上对齐按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在寻找一种在树状视图中对齐按钮的方法,即使它处于任何级别,它也将看起来像在同一列中.例如:

 Item1 [按钮]
 Item2 [按钮]
Item3 [按钮] 


我希望它看起来像

 Item1 [按钮]
 Item2 [按钮]
Item3 [Button] 

解决方案

尝试通过在树视图元素上设置最小宽度,然后将按钮右对齐.


<我不建议您这样做.您确实可以发明一些更好的UI设计.树形结构将不那么可见,但是更重要的是,您将进行更改以截断项目文本的一部分;而且很难调整左侧文本占用的空间并测量树节点的左缩进量以补偿按钮位置.我警告过你;但仍然可以得到想要的对齐方式.

TreeView的元素可以是具有固定宽度的左列的两列单行Grid.在运行时创建节点时,您将读取节点的级别并计算所需的左列宽度.

对我来说,它看起来像一个过分的设计烦人的设计,它不是很容易调试.添加更深的节点总是会破坏图片.

您可以做得更好.例如,每棵树上有一个按钮,其动作取决于所选节点.那呢?

—SA


Hi ,

I am looking for a way to align the buttons in my treeview so that it will look like in the same column even if it is in any level. Eg:

Item1 [Button]
 Item2 [Button]
Item3[Button]


i want it to look like

Item1  [Button]
 Item2 [Button]
Item3  [Button]

解决方案

Try by setting the minwidth on the treeview elements and then right align the buttons.


I won''t advise you to do so. You could really invent some better UI design, really. The tree structure will be less visible, but what''s more important, you will have a change to truncate a part of the item text; and it''s pretty hard to adjust the room taken by the text on left and measure a left indent of a tree node to compensate in in a button position. I warned you; but still you can get an alignment you want.

The element of a TreeView can be a two-column one-line Grid with fixed-width left column. When you create a node during run-time, you read the level of the node and calculate required width of the left column.

To me, it looks like an excessive design annoying design which is not very easy to debug. Adding a deeper node can always break the picture.

You could do much better. For example, one button per a whole tree with action depending on selected node. How about that?

—SA


这篇关于在WPF TreeView上对齐按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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