如何为数据透视项标题添加图像 [英] how to add images for pivot item header
问题描述
正在开发一个简单的应用程序,用于在 wp7 中学习 pivot control
.
Am developing a simple app for learning pivot control
in wp7.
我们可以为枢轴项添加图像而不是标题中的文本(下图中的红色标记区域).
can we add images for pivot item instead of text in header(red mark area in bellow image ).
是否可以添加图片,请给我建议
is it possible to add images, please suggest me
我的 xaml 代码是:
my xaml code is:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION" Name="mainPivot">
<!--Pivot item one-->
<controls:PivotItem Header="item1">
<Grid>
<Image Source="/SchoolList;component/Gallery/child.jpg"/>
</Grid>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="item2">
<Grid>
<Image Source="/SchoolList;component/Gallery/class.jpg"/>
</Grid>
</controls:PivotItem>
</controls:Pivot>
</Grid>
提前致谢
推荐答案
在@toni petrina 的想法下,我使用 data binding
HeaderTemplate 到枢轴控件>.我在我的应用程序中使用枢轴和页眉模板中的图像实现了图像库提供了很好的外观
with the Idea of @toni petrina i added images to the HeaderTemplate
to the pivot control using data binding
. am implemented image gallery in my app using pivot with images in header template gives great look and feel
Xaml 代码是:
<controls:Pivot Title="Photo Gallery" Name="mainPivot" ItemsSource="{Binding PivotImages}">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<Image Name="play" Source="{Binding imgSrc}" Height="80" Width="120" Margin="0,10,0,0"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Image Name="mainImage" Source="{Binding imgSrc}" />
</Grid>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
并且我创建了一个简单的 class
和一个 string 属性
来保存 images source
并准备了一个 List
并在页面加载事件
and i have created a simple class
with one string property
to save the images source
and prepared a List
and assigned to the pivot ItemsSource
on page loaded event
mainPivot.ItemsSource = items; // items is the list with image sources
这篇关于如何为数据透视项标题添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!