TreeView没有BrigToFront(TreeViewItem) [英] TreeView didn't have BrigToFront(TreeViewItem)

查看:78
本文介绍了TreeView没有BrigToFront(TreeViewItem)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用树,并且我将层次数据绑定到树中的HierarchicalDataTemplate

Hi all,

I am working with tree and i have Hierarchical Data bind to HierarchicalDataTemplate in the tree

<treeview flowdirection="RightToLeft" name="tree" itemssource="{Binding Jobs}">
            <treeview.itemtemplate>
                <hierarchicaldatatemplate itemssource="{Binding Childs}">
                    <border>
                        <stackpanel orientation="Horizontal">
                            <textblock margin="2" text="{Binding Name}" />
                        </stackpanel>
                    </border>
                </hierarchicaldatatemplate>
            </treeview.itemtemplate>
    </treeview>


我有Job对象,我想带那个对象查看,我该怎么办,


and i have Job object, i want to Bring that object to view, what should i do,

any help Please.

推荐答案

问题不明确,将元素从from引入的目的不明确;请参阅我对这个问题的评论.

但是,该事项减少到以下情况.将TreeViewItem的实例放在前面是没有意义的(您可以考虑将其引入视图,但这是完全不同的问题).也就是说,该问题可能仅对TreeView有意义.但这是一个控件,应该放在从System.Windows.Controls.Panel派生的类的某些FrameworkElement上.这些类具有方法Panel.SetZIndex,该方法为给定元素(在您的情况下为TreeView控件的实例)设置ZIndex附加属性的值.参见:
http://msdn.microsoft.com/en-us/library/system. windows.controls.panel.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.setzindex.aspx [ ^ ].

我觉得这不是您想要的,但这是因为这个问题的表达方式不正确.

要显示项目(System.Windows.Controls.TreeViewItem),应使用其方法System.Windows.FrameworkElement.BringIntoView.
参见:
http://msdn.microsoft.com/zh-cn/library/system.windows.controls.treeviewitem%28v = VS.100%29.aspx [ http://msdn.microsoft.com/en-us/library/ms598110.aspx [ ^ ].

此方法仅尝试使元素可见,这仅与滚动有关.为了在TreeView的情况下使其成为可能,还应确保通过扩展其所有父节点来显示该元素.您可以通过属性IsExpanded对其进行控制,请参见 http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem.isexpanded.aspx [
The question is not clear, the purpose of bringing of an element to from is not clear; please see my comment to the question.

However, this matter is reduced to the following. Bringing an instance of TreeViewItem to front makes no sense (you can think about bringing this into view, but this is completely different issue). That said, the question may only make sense for TreeView. But this is a control which should be placed onto some FrameworkElement of the class derived from System.Windows.Controls.Panel. These classes have the method Panel.SetZIndex which sets the value of the ZIndex attached property for a given element, an instance of TreeView control in your case. See:
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.setzindex.aspx[^].

I feel this is not what you want, but this is because of the question which is not formulated correctly.

To bring an item (System.Windows.Controls.TreeViewItem) into view, you should use its method System.Windows.FrameworkElement.BringIntoView.
See:
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem%28v=VS.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms598110.aspx[^].

This method only attempts to bring the element into view, which is only related to scrolling. To make is possible in case of TreeView, you should also make sure the element is shown by having all of its parent nodes expanded. You can control it by the property IsExpanded, see http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem.isexpanded.aspx[^]. Don''t forget: this is not about the item you want to show but all its parent nodes.

—SA


我找到了一个非常简单的解决方案

只需在绑定对象中添加三个属性,例如Jobs(像我的)

Jobs是Job的集合

1-确定,现在添加三个属性IsSelected和IsExpanded(布尔属性)和Parent(父Job对象)
2-在IsExpanded属性中写
i found a very simple solution

just add three property to your binding object say Jobs (like mine)

Jobs is a collection of Job

1- ok, now add three property IsSelected and IsExpanded (boolean property) and Parent(the parent Job object)
2- in the IsExpanded property write
public bool IsExpanded
{
get{return _isExpanded;}
set
{
if(value!=_isExpanded;)
_isExpanded=value;
if(Parent!=null && _isExpanded == true)
Parent.IsExpanded = true; 
}
}


3-将此内容写入TreeView中的XAML


3- write this to your XAML in the TreeView

<style targettype="{x:Type">
    <setter property="IsSelected" value="{Binging IsSelected,Mode=TowWay}" />
    <setter property="IsExpanded" value="{Binging IsExpanded,Mode=TowWay}" />
</style>


这篇关于TreeView没有BrigToFront(TreeViewItem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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