這是一個好奇心的問題,我沒有這種昂貴的佈局的實際用途。Tabcontrol - 選擇更改加載/卸載
我有下面的XAML
<Window x:Class="WpfApplication16.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen">
<TabControl ItemsSource="{Binding Items}">
<TabControl.ContentTemplate>
<DataTemplate>
<ScrollViewer>
<ContentPresenter Content="{Binding View}" />
</ScrollViewer>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Window>
背後
public class Item
{
public FrameworkElement View { get { return m_view; } }
public Item()
{
for (int i = 0; i < 3000; ++i)
{
m_view.Items.Add(new TextBox());
}
}
ItemsControl m_view = new ItemsControl();
}
public partial class MainWindow : Window
{
public List<Item> Items { get; private set; }
public MainWindow()
{
Items = new List<Item>();
for (int i = 0; i < 10; ++i)
{
Items.Add(new Item());
}
DataContext = this;
InitializeComponent();
}
}
所以之前被初始化窗口中的所有文本框已經構建了下面的代碼,其中共有30,000,但他們的避風港尚未裝入。當選擇被改變時,例如當初始選擇發生時,它們僅被加載/卸載。由於文本框的數量龐大,我希望第一次爲每個項目更改標籤,但爲什麼在Ive選擇每個標籤之後,再次通過它們在加載/卸載之間仍需要很長時間?
沒有約束力,我認爲它不是一個佈局問題,因爲當我調整窗口的大小時,它的更新速度比改變標籤之間的速度要快得多。我不認爲它是一個內存問題(因爲內存使用量在選擇標籤之間增長,所以內存使用量不斷增加),然後在所有10個選擇完畢後保持不變,然後再次運行。
另外我故意不使用可視化。