TreeView小改变 [英] TreeView Small change

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

问题描述

您好,


我的应用程序中有一个树视图,其代码如下所示

< TreeView x:Name =" UserTree" 
Horizo​​ntalAlignment =" Stretch" VerticalAlignment = QUOT;拉伸"
ItemsSource =" {Binding Mode = OneWay}"
DataContext =" {Binding Path = Networks}"
SelectedItemChanged =" TreeView_OnSelectedItemChanged"
VirtualizingStackPanel.IsVirtualizing =" True"
VirtualizingStackPanel.VirtualizationMode =" Recycling"
Grid.Row =" 1"
Margin =" 5"
>

代码运行良好,但下面的行

 VirtualizingStackPanel.IsVirtualizing = QUOT;真" 

如果设置为true,则应用程序的性能良好,但如果设置为false,则性能为
难以忍受且非常慢。


如果设置为false,则某些函数可以正常工作,例如折叠树,如果设置为true,则折叠树将不起作用。


请建议我如何管理此功能。


是否可以在运行时将buttton点击并在操作设置为true后将其设置为true。


请建议我是否可以从代码背后使用C#



问候,


Amit




解决方案

我的树视图如下所示

< TreeView X:名称= QUOT; UsersList" 
Horizo​​ntalAlignment =" Stretch" VerticalAlignment = QUOT;拉伸"
ItemsSource =" {Binding Mode = OneWay}"
DataContext =" {Binding Path = Users}"
SelectedItemChanged =" TreeView_OnSelectedItemChanged"
VirtualizingStackPanel.IsVirtualizing =" True"
VirtualizingStackPanel.VirtualizationMode =" Recycling"
Grid.Row =" 1"
Margin =" 5"
>

当以下属性设置为true时为

 

VirtualizingStackPanel.IsVirtualizing =" True"


折叠树视图无法正常运行,但如果设置为false则会崩溃树视图。


我想将上面的属性保持为True并折叠树视图。


请建议使用以上属性集折叠树视图的任何方法



以下是折叠函数


 protected void CollapseFunction()
{
foreach(this.UserList.Items中的对象项)
{
TreeViewItem treeItem = this.UserList.ItemContainerGenerator.ContainerFromItem(item)as TreeViewItem;
if(treeItem!= null)
{
CollapseAll(treeItem,false);
}
//treeItem.IsExpanded = false;
}
}
private void CollapseAll(ItemsControl items,bool expand)
{
foreach(items obj in items.Items)
{
ItemsControl childControl = items.ItemContainerGenerator.ContainerFromItem(obj)as ItemsControl;
if(childControl!= null)
{
CollapseAll(childControl,expand);
}
TreeViewItem item = childControl as TreeViewItem;
if(item!= null)
{
item.IsExpanded = false;
}
}
}


此致,


Amit









Hello,

I have a treeview in my application with following code as shown below

  <TreeView x:Name="UserTree"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  ItemsSource="{Binding Mode=OneWay}"
                  DataContext="{Binding Path=Networks}"
                  SelectedItemChanged="TreeView_OnSelectedItemChanged" 
                  VirtualizingStackPanel.IsVirtualizing="True" 
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  Grid.Row="1"
                  Margin="5"  
            >

The code is working well any ways, however the below line

VirtualizingStackPanel.IsVirtualizing="True" 

if set to true the performance of application is good, but if set to false the performance is unbearable and very slow.

If set to false some functions work such as collapsing tree and if set to true collapsing tree wont work.

Please suggest how shud i manage this function.

Is it posibble to set it to true at runtime on buttton click and after operation set to true.

Please suggest if i can manage from code behind using C#

Regards,

Amit

解决方案

I have a treeview with as shownbelow

<TreeView x:Name="UsersList"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  ItemsSource="{Binding Mode=OneWay}"
                  DataContext="{Binding Path=Users}"
                  SelectedItemChanged="TreeView_OnSelectedItemChanged" 
                  VirtualizingStackPanel.IsVirtualizing="True" 
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  Grid.Row="1"
                  Margin="5"  
            >

when the below property is set to true

VirtualizingStackPanel.IsVirtualizing="True"


Collapse treeview doesn't function properly, however if set to false collapse treeview happens.

I would like to maintain the above property to True and Collapse a treeview.

Kindly suggest any ways available to collapse a treeview with above property set

Below is the collapse function

 protected void CollapseFunction()
        {
            foreach (object item in this.UserList.Items)
            {
                TreeViewItem treeItem = this.UserList.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                if (treeItem != null)
                {
                    CollapseAll(treeItem, false);
                }
                //treeItem.IsExpanded = false;
            }
        }
        private void CollapseAll(ItemsControl items, bool expand)
        {
            foreach (object obj in items.Items)
            {
                ItemsControl childControl = items.ItemContainerGenerator.ContainerFromItem(obj) as ItemsControl;
                if (childControl != null)
                {
                    CollapseAll(childControl, expand);
                }
                TreeViewItem item = childControl as TreeViewItem;
                if (item != null)
                {
                    item.IsExpanded = false;
                }
            }
        }

Regards,

Amit





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

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