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

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

问题描述

Am正在开发一个用于在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代码是:

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

并且我用一个string property创建了一个简单的class来保存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天全站免登陆