English 中文(简体)
是什么使我的世界森林论坛的 com箱项目花了这么长时间才能在改变项目来源时重新更新?
原标题:What is causing my WPF combobox items to take so long to refresh when the itemssource is changed?

我有一个数据网(称为Dat1),该网有一个物品来源,必须接受可观察的海关类型收集,称作A型。 类型A的特性之一是另一种习俗的可观察收集,称为类型B。 之后,我有一只 com子,其物品来源必须达1英寸。

因此,当用户选择1类A时, com体显示从选定的类型A中可观测到的类型B中的物品。 是否有意义?

具有约束力的指定经营实体的工作及其最新信息。 问题在于,当“ com”箱中展示的物品已经展示出,用户选择了不同的“ Type”类型,并试图查看“ com”箱中的新项目时,就会出现长时间的停顿,而项目介绍者产生新项目。

为了检验问题,我可以简化情况。

复制步骤:

  1. 采用......创建新的WPF项目。 NET 4.0。

  2. 该法典如下。

  3. 为了采取冻结行动,你必须放弃 com子,看看这些物品,然后点击 but子,以便改变物品来源,然后又把 com子再次 drop。 com子在几秒后倒塌,但为什么如此缓慢?

XAML

<Window x:Class="ComboBoxTest.MainWindow"
        xmlns:System="clr-namespace:System;assembly=mscorlib"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <ComboBox x:Name="cbo" DisplayMemberPath="Junk1"></ComboBox>
            <Button Content="Click Me!" Click="btn_Click"></Button>
        </StackPanel>
    </Grid>
</Window>

法典

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.cbo.ItemsSource = junk1;
    }

    ObservableCollection<Junk> junk1 = new ObservableCollection<Junk>() {
        new Junk() { Junk1 = "junk1 - 1" },
        new Junk() { Junk1 = "junk1 - 2" } };

    ObservableCollection<Junk> junk2 = new ObservableCollection<Junk>() {
        new Junk() { Junk1 = "junk2 - 1" },
        new Junk() { Junk1 = "junk2 - 2" },
        new Junk() { Junk1 = "junk2 - 3" },
        new Junk() { Junk1 = "junk2 - 4" } };

    private void btn_Click(object sender, RoutedEventArgs e)
    {
        if (this.cbo.ItemsSource == junk1)
            this.cbo.ItemsSource = junk2;
        else
            this.cbo.ItemsSource = junk1;
    }
}

public class Junk
{
    public string Junk1 { get; set; }
}

NOTE: 这是一个WPF问题。 我听到银星说,这个问题也一样。 我无需知道银灯是否奏效。 我需要一名妇女论坛的答复。

PS。 当项目源改为“Jnk2”时,拖延时间会更长,大概是因为它更大。

它拖延了足够的时间,我认为这可能是由于具有约束力的例外,因为例外需要时间。 是否有办法看到是否有具有约束力的例外?

问题回答

I observe this phenomenon too. I m using Visual Studio 2010 (with ReSharper 6.0) on Windows 7 x64.

It s not noticeable with only four items as in the example above, but if I make it e.g. 50 or more items the freeze gets very noticeable. After the rebinding it will then hang for about 15 seconds before I m allowed to interact with it again.

另一个令人感兴趣的事情是,这只是在瓦斯瓦解时发生的。 如果我独立行事,这确实是 s和快的。

这里是我的简单项目守则:

XAML

<Window x:Class="ComboBoxFreeze.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
  <StackPanel>
    <ComboBox x:Name="cbo" DisplayMemberPath="Junk1"></ComboBox>
    <Button Content="Click Me!" Click="btn_Click"></Button>
  </StackPanel>
</Window>

法典

using System.Collections.ObjectModel;
using System.Windows;

namespace ComboBoxFreeze
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;

            _junk1 = new ObservableCollection<Junk>();
            for (int i = 0; i < 50; i++)
            {
                _junk1.Add(new Junk { Junk1 = "Prop1a-" + i, Junk2 = "Prop1b-" + i });
            }


            _junk2 = new ObservableCollection<Junk>();
            for (int i = 0; i < 50; i++)
            {
                _junk2.Add(new Junk { Junk1 = "Prop2a-" + i, Junk2 = "Prop2b-" + i });
            }
        }

        private readonly ObservableCollection<Junk> _junk1;

        private readonly ObservableCollection<Junk> _junk2;

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            cbo.ItemsSource = _junk1;
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            if (cbo.ItemsSource == _junk1)
            {
                cbo.ItemsSource = _junk2;
            }
            else
            {
                cbo.ItemsSource = _junk1;
            }
        }
    }

    public class Junk
    {
        public string Junk1 { get; set; }
        public string Junk2 { get; set; }
    }
}

如果我找到解决办法或努力解决这一问题,我将再次到会。





相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签