0
我有關於使用選項卡進行數據綁定的問題。 我有以下XAML代碼:將選項卡綁定到xaml模型中的observablecollection
<Window x:Class="SuperAtomsController.GUI.windowAnalog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="windowAnalog" Height="900" Width="1400"
DataContext="{Binding RelativeSource={RelativeSource self}}">
<Grid>
<TabControl Height="459" HorizontalAlignment="Left" Margin="188,278,0,0" Name="tabControl1" ItemsSource="{Binding Path=model.sequences}" VerticalAlignment="Top" Width="883">
</TabControl>
</Grid>
</Window>
而後面的代碼:
public partial class windowAnalog : Window
{
public Data model;
public windowAnalog(Data model)
{
this.model = model;
InitializeComponent();
}
}
但有了這個沒有出現在TabControl的(model.sequences是類型ObservableCollection<>
的)。如果刪除xaml中的itemssource,並在InitializeComponent();
之後的c#代碼tabControl1.ItemsSource = model.sequences;
中添加以下代碼,它將正常工作。我錯過了什麼?