可能重複:
Why do these tabs seem to share the same textbox?BindingExpression路徑錯誤
我的頭和Text屬性都在MyHomeworkModel類。 我將我的視圖的datacontext設置爲MyHomeworkViewModel類。 但是,在我看來,我將新添加的選項卡標題和文本框文本綁定到MyHomeworkModel中的這兩個屬性。
然後我得到BindingExpression路徑錯誤,每當我試圖添加第二個標籤,它只是抱怨我綁定到文本,沒有抱怨綁定到標題。
我仍然得到第二個選項卡,除了我的所有文本框(在不同的選項卡中)具有相同的文本。
下面是我的XAML:
<TabControl HorizontalAlignment="Left" Height="330" VerticalAlignment="Top" Width="764" Margin="10,10,0,0" ItemsSource="{Binding AllTabs}" SelectedItem="{Binding SelectedTab}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="Content">
<Setter.Value>
<Grid>
<TextBox Text="{Binding Text}" FontSize="16" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</TextBox>
</Grid>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="20"/>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
什麼?將視圖模型或代碼發佈到後面。另外,這裏有一個概念上的問題:一個'TabControl'是一個'ItemsControl',因此它應該綁定到某個'List',而不是單個字符串屬性或其他。 –