开发者

how can i set header templete in pivot item at run time

开发者 https://www.devze.com 2023-03-24 00:48 出处:网络
actually i want to set image on header of every pivot item .....at run开发者_开发百科 time using a resource

actually i want to set image on header of every pivot item .....at run开发者_开发百科 time using a resource

     <UserControl x:Class="WindowsPhoneApplication7.heder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="18" d:DesignWidth="24" Loaded="UserControl_Loaded">

<UserControl.Resources>
    <DataTemplate x:Key="heder_image">
        <Image Source="/WindowsPhoneApplication7;component/Images/appbar.feature.settings.rest.png"></Image>
    </DataTemplate>
</UserControl.Resources>

it is a resource now my pivot item are in another cs file

     heder dis =new  heder();
   pivotItem[i] = new PivotItem();
   pivotItem[i].Header = (DataTemplate)dis.Resources["heder_image"];

but the header templte r not set ......image r not display


What you're doing wrong here, is that you're setting the Header of a PivotItem to a template, instead of using the Pivot.HeaderTemplate. That way it wouldn't be necessary to generate the items in C# either, but instead databind (via. the Pivot.ItemsSource property) them, and do all the styling in XAML as you're meant to do.

And when that is said, using a image for a Pivot Header, should really be discouraged, as it goes against the platforms default look&feel, and thus against the platforms UI and UX guidelines.


Check if the image's Build Action is set to Content (see properties of the file in VS2010 explorer). If the image is in the same project as the XAML page, use "/Images/appbar.feature.settings.rest.png" instead of "/WindowsPhoneApplication7;component...".

Use this XAML snippet and set your header in XAML:

<controls:Pivot ItemsSource="{Binding MyObjects}" HeaderTemplate="{StaticResource heder_image}">
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>
0

精彩评论

暂无评论...
验证码 换一张
取 消