我有一個名爲ProductEditView的UserControl,我將其添加到我的MainWindow(shell)的區域中。我有殼區一個TabControl顯示ProductEditView像下面prism - 無法爲TabItem的HeaderTemplate設置綁定
<TabControl Name="tabEditProduct"
prism:RegionManager.RegionName="TabContent"
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel LastChildFill="True" >
<Button Width="16" Height="16" Command="{Binding Path=CloseTabCommand}"
DockPanel.Dock="Right" BorderThickness="0" Padding="0"
BorderBrush="Transparent" Background="Transparent">
<Image Source="Images/close-icon.png" Width="14" Height="14"
HorizontalAlignment="Stretch" Margin="0"/>
</Button>
<TextBlock Text="{Binding ProductName}"
DockPanel.Dock="Left" Margin="0,0,10,0" />
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
在的TabItem的HeaderTemplate中我試圖顯示從使用綁定的產品對象的文本。不幸的是綁定不起作用,但我可以將靜態文本顯示爲標題。 是否可以像上面那樣使用綁定來顯示標籤項的標題文本?
爲了完整起見,我也將視圖粘貼到編輯產品,該產品作爲TabItem在TabControl區域中加載。對此的綁定工作良好。這裏是ProductEditView
<UserControl x:Class="TextExisting.CoreModule.ProductEditView"
....
<Grid HorizontalAlignment="Center" DataContext="{Binding Path=Product}" Grid.Row="0" Grid.Column="0">
....
<TextBlock Text="Id" Grid.Row="0" Grid.Column="0"/>
<TextBox Grid.Row="0" Grid.Column="1"
Text="{Binding Path=Id, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
<TextBlock Text="Product Name" Grid.Row="1" Grid.Column="0"/>
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding Path=ProductName, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
....
</Grid>
<Button Command="{Binding SaveProductCommand}" Content="Save Product" HorizontalAlignment="Center"/>
</UserControl>
你的鏈接被打破,這也正是爲什麼鏈接只有答案沒有對堆棧溢出(當你發佈你的答案雖然也許沒有這麼不受歡迎)歡迎的原因。 – Sheridan 2015-02-23 13:52:25
這裏是鏈接和解決方案爲我工作 http://blog.vivekmehta.com/2011/06/referencing-viewmodel-datacontext-in-prism/ – dev27 2017-09-06 00:37:12