MainWindow中:
1 <Window.Resources> 2 <Style TargetType="TabItem"> 3 <Setter Property="Header" Value="{Binding DataContext.Title}" /> 4 </Style> 5 </Window.Resources> 6 <StackPanel> 7 <Button Content="Creat ViewA Page" /> 8 <Button Content="Creat ViewB Page" /> 9 <TabControl prism:RegionManager.RegionName="ContentRegion" /> 10 </StackPanel>
主要是设置一个 “TabItem” 的样式 设置其Header 属性绑定为所属的ViewModel的 Title 属性。
ViewModel中:
1 public class ViewAViewModel : BindableBase 2 { 3 private string _message; 4 public string Message 5 { 6 get { return _message; } 7 set { SetProperty(ref _message, value); } 8 } 9 10 private string title; 11 public string Title 12 { 13 get { return title; } 14 set { SetProperty(ref title, value); } 15 } 16 17 public ViewAViewModel() 18 { 19 Message = "View A from your Prism Module"; 20 Title = "ViewA"; 21 } 22 }