如何为枢轴项目标题添加图像 [英] how to add images for pivot item header

查看:24
本文介绍了如何为枢轴项目标题添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发一个简单的应用程序,用于在 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 bindingHeaderTemplate到pivot控件>.我在我的应用程序中使用带有标题模板中图像的枢轴实现了图像库,外观和感觉都很棒

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 并在页面加载事件上分配给枢轴 ItemsSource

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆