2011-08-23 73 views
6

我將數據對象的ObservableCollection綁定到我的標籤控件項目源。我已經正確地計算出如何綁定生成的tabitem內的控件,但我無法弄清楚如何更改使用Observable集合內的屬性生成的tabitem的標題屬性。對不起,如果我寫錯了。這裏是我的TabItem的數據模板XAML:WPF Databinding TabItem標題

<DataTemplate x:Key="TabItemTemplate"> 
     <TreeView Height="461" VerticalAlignment="Top" 
      Width="625" ItemTemplateSelector="{StaticResource TreeviewDataSelector}" ItemsSource="{Binding}" /> 
</DataTemplate> 

回答

20

爲您的TabItems一個Style那臺Header屬性和樣式應用到TabControl.ItemContainerStyle

<TabControl> 
    <TabControl.ItemContainerStyle> 
     <Style TargetType="TabItem"> 
      <Setter Property="Header" Value="{Binding PathToYourProperty}"/> 
     </Style> 
    </TabControl.ItemContainerStyle> 
</TabControl> 
10

設置的DisplayMemberPath上的TabControl到財產的名稱。

<TabControl ItemsSource="{Binding items}" DisplayMemberPath="headerPropertyName"> 
+0

我不得不使用Caliburn和慣例綁定:'