我想在当前完全正常工作的Prism MVVM WPF应用程序中的TabControl的第一个标签页头中显示图像。wpf中的第一个标签页头中的图像TabHeader
完整描述如下:
当用户选择从左侧区域分类列表会显示在右侧区域“更多详细信息”和“相关产品”的项目。此右侧区域包含UserControl内的TabControl。 第一个标签显示“More category Details”,第二个标签显示“相关产品”。数据显示正确。现在我只想在第一个选项卡标题中显示类别缩略图和类别名称。
我尝试的第一个选项卡上使用HeaderTemplate中如下
<TabControl VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" >
<TabItem Name="tabItemCategoryMoreInfo" >
<TabItem.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="viewImage" Height="20" Width="20" Margin="0,0,2,0"
Source="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabControl} }, Path=Content.DataContext.SelectedParent.PictureBinary}"/>
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Content.DataContext.SelectedParent.CategoryName}"
VerticalAlignment="Center" FontSize="14" FontWeight="SemiBold" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Content.DataContext.SelectedParent.PictureBinary}" Value="{x:Null}" >
<Setter TargetName="viewImage" Property="Source" Value="/CatalogModule;component/Images/ItemIcon.png" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</TabItem.HeaderTemplate>
<ContentControl prism:RegionManager.RegionName="CategoryMoreDetailsRegion" />
</TabItem>
<TabItem Header="Products" Name="tabItemCategoryProducts">
<ContentControl prism:RegionManager.RegionName="CategoryProductsRegion" />
</TabItem>
它没有显示产品名称或产品形象。但它只显示默认图像,所以触发器看起来工作。有些人可以帮忙吗?
编辑:
最初我用的TabItem的TabControl的,而不是在图像数据通道:
<Image x:Name="viewImage" Height="20" Width="20" Margin="0,0,2,0"
Source="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem} }, Path=Content.DataContext.SelectedParent.PictureBinary}"/>
最初我用TabItem而不是TabControl,我忘了它的内涵,它没有工作。对不起,我没有解释清楚。我的意思是“dataTrigger正在工作”是因为它无法从数据源中找到正确的图片(因为我的代码不正确),它显示文件夹中的默认图片“ItemIcon.png”。 – Dush 2015-02-23 21:40:18