Treeview展开的元素未刷新 [英] Treeview expanded elements are not refreshing

查看:98
本文介绍了Treeview展开的元素未刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要一个非常大的问题的支持.

i need a support for a very big problem.

我正在为自己的工作开发一个应用程序,但是TreeView出现了刷新问题.

I'm developing an application for my work, and i'm getting a refresh problem with the TreeView.

代码并不简单,也许我丢失了一些东西,但是我注意到当我输入一个扩展项目时,PropertyChanged事件没有被绑定(空).

The code is not simple, maybe i lost something, but i noticed that when i enter on an expanded item, the PropertyChanged event is not binded (null).

这是我的treeview xaml代码

This is my treeview xaml code

<GroupBox Grid.Row="0" Grid.Column="4" Header="Current Installation" DataContext="{Binding SelectedInstallation, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
      <TreeView Margin="3" ItemsSource="{Binding Collection, Mode=OneWay}">
        <TreeView.ItemContainerStyle>
          <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
          </Style>
        </TreeView.ItemContainerStyle>
        <TreeView.Resources>
          <!-- Modules Type -->
          <HierarchicalDataTemplate DataType="{x:Type mv:ModulesTypeModelView}" ItemsSource="{Binding Modules, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
              <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Output, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text="[" />
                <TextBlock Text="{Binding Modules.Count, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text="]" />
              </StackPanel>
            </CheckBox>
          </HierarchicalDataTemplate>
          <!-- Controls Type -->
          <HierarchicalDataTemplate DataType="{x:Type mv:ControlsTypeModelView}" ItemsSource="{Binding Controls, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
              <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Output, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text="[" />
                <TextBlock Text="{Binding Controls.Count, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text="]" />
              </StackPanel>
            </CheckBox>
          </HierarchicalDataTemplate>
          <!-- Module Type -->
          <HierarchicalDataTemplate DataType="{x:Type mv:ModuleTypeModelView}" ItemsSource="{Binding Projects, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="145" />
                  <ColumnDefinition Width="95" />
                  <ColumnDefinition Width="95" />
                </Grid.ColumnDefinitions>
                <!--<Image Source="{Binding Status.CurrentImage}" Margin="3" />-->
                <TextBlock Grid.Column="0" Margin="3" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <ComboBox Grid.Column="1" Margin="3" ItemsSource="{Binding Platforms, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValue="{Binding Platform, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <ComboBox Grid.Column="2" Margin="3" ItemsSource="{Binding Configurations, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValue="{Binding Configuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
              </Grid>
            </CheckBox>
          </HierarchicalDataTemplate>
          <!-- Projects Type -->
          <DataTemplate DataType="{x:Type mv:ProjectModelView}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding AllowSelection}">
              <CheckBox.Content>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="{Binding Major, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="." Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="{Binding Minor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="." Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="{Binding Build, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="." Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="{Binding Revision, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="[" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="{Binding BuildStatus.Status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Text="]" Foreground="{Binding BuildStatus.ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
              </CheckBox.Content>
              <CheckBox.ToolTip>
                <StackPanel Orientation="Vertical">
                  <TextBlock Text="{Binding BuildStatus.Status}" FontSize="12" FontWeight="Bold" />
                  <TextBlock Text="{Binding BuildStatus.Message}" />
                </StackPanel>
              </CheckBox.ToolTip>
            </CheckBox>
          </DataTemplate>
          <!-- Database Type -->
          <HierarchicalDataTemplate DataType="{x:Type mv:DatabaseTypeModelView}" ItemsSource="{Binding BackupScripts}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Content="Database" />
          </HierarchicalDataTemplate>
          <!-- BackupScript Type-->
          <HierarchicalDataTemplate DataType="{x:Type mv:BackupScriptTypeModelView}" ItemsSource="{Binding Commands}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Content="{Binding Name}" />
          </HierarchicalDataTemplate>
          <!-- Commands Type-->
          <DataTemplate DataType="{x:Type mv:BackupScriptCommandTypeModelView}">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Content="{Binding Value}">
              <CheckBox.ToolTip>
                <Grid>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>
                  <Label Grid.Row="0" Grid.Column="0" Margin="3" Content="Server:" />
                  <Label Grid.Row="1" Grid.Column="0" Margin="3" Content="Database:" />
                  <Label Grid.Row="2" Grid.Column="0" Margin="3" Content="Username:" />
                  <Label Grid.Row="3" Grid.Column="0" Margin="3" Content="Password:" />
                  <Label Grid.Row="4" Grid.Column="0" Margin="3" Content="Query:" />
                  <TextBlock Grid.Row="0" Grid.Column="1" Margin="3" Text="{Binding Server, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Grid.Row="1" Grid.Column="1" Margin="3" Text="{Binding Database, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Grid.Row="2" Grid.Column="1" Margin="3" Text="{Binding Username, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Grid.Row="3" Grid.Column="1" Margin="3" Text="{Binding Password, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                  <TextBlock Grid.Row="4" Grid.Column="1" Margin="3" Text="{Binding Query, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
                </Grid>
              </CheckBox.ToolTip>
            </CheckBox>
          </DataTemplate>
        </TreeView.Resources>
      </TreeView>
    </GroupBox>

ProjectType和ModuleType是隐含的.

ProjectType and ModuleType are the incriminated ones.

以这种方式生成IsChecked,IsExpanded和IsSelected

IsChecked, IsExpanded and IsSelected are generated in this way

 /// <summary>
    /// Currently Checked?
    /// </summary>
    public Boolean IsChecked
    {
      get { return modulesType.IsChecked; }
      set
      {
        if (!modulesType.IsChecked.Equals(value))
        {
          modulesType.IsChecked = value;
          OnPropertyChanged("IsChecked");
          IsExpanded = value;
        }

        for (Int32 i = 0; i < this.Modules.Count; ++i)
        {
          var child = this.Modules[i];
          child.IsChecked = value;
        }
      }
    }
    /// <summary>
    /// Currently Expended?
    /// </summary>
    public Boolean IsExpanded
    {
      get { return isExpanded; }
      set
      {
        if (!isExpanded.Equals(value))
        {
          isExpanded = value;
          OnPropertyChanged("IsExpanded");
        }

        for (Int32 i = 0; i < this.Modules.Count; ++i)
        {
          var child = Modules[i];
          child.IsExpanded = value;
        }
      }
    }

当我有一个扩展项目时,它不会刷新(即使从代码中也是如此).

When i've an expanded item, this is not refreshed (even from code).

当我折叠节点并执行检查时,它们会刷新.

Whan i collapse a node, and perform a check, they are refreshed.

如果先展开,选中然后取消选中复选框,则表示它们已正确取消选中,但是treeview不会显示该复选框.

If  expand, check, and then unckeck checkboxes, they are correctly unchecked, but treeview don't show the check in checkbox.

可以是什么?

感谢您的帮助,很抱歉很长的帖子...

Thanks for any help, and sorry for very long post...

推荐答案

Hello Revan1985,

Hello Revan1985,

根据我对这种情况的理解(猜测),该问题可能与虚拟化有关.

Based on my understanding(guessing) on this case, the problem may related to Virtualizinghttp://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.isvirtualizing(v=vs.110).aspx Have you set this property in your application.  What about try set it to false to see the result?

但是,如果不是上述情况,我可能需要您提供更多详细信息.如果我可以重现此问题,并且知道您对刷新"的意思(您如何通过代码刷新以及想要刷新什么?).我可能了解问题并了解 真正发生了什么.

However If the above thing is not the case, I may need more details from you. If I can reproduce this issue and know what you mean of "refresh"(How you refreshed via code and what you want to refresh?). I may understand the problem and get to know what really happened.

最诚挚的问候,


这篇关于Treeview展开的元素未刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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