繁体   English   中英

wp8设置动态数据透视表项目的标题大小

[英]wp8 Set header's size of dynamic pivot item

我是Windows Phone开发的初学者,我创建了一个数据透视应用程序,数据透视的项目是动态填充的,但是我无法调整每个标题的字体大小,而且我也不知道为什么,这是xaml界面:

<phone:Pivot  VerticalAlignment="Top"  Name="pivotMainList">
    <phone:PivotItem   Name="titleToday" Margin="12,4,12,0">
        <phone:PivotItem.Header>
           <TextBlock Text="MainPage" FontSize="40"/>
        </phone:PivotItem.Header>
        <Grid Height="357">
           <ListBox ... // some code

这是背后的代码:

for (int i = 0; i <= 20; i++)
{
    var textBlock = new TextBlock { Text = "Pivot " + i, FontSize = 32 };
    PivotItem myNewPivotItem = new PivotItem { Header = textBlock, Name = "piv_" + i };
    Grid myNewGrid = new Grid();
    //... i fill the grid here

    //add pivot to main list
    pivotMainList.Items.Add(myNewPivotItem);
}

它给出了一个奇怪的异常:

HappyConf.DLL!HappyConf.App.Application_UnhandledException(对象发送者,System.Windows.ApplicationUnhandledExceptionEventArgs e)

更改字体的一种方法是创建自定义标题模板资源,然后将数据透视表的标题模板属性绑定到该资源。

这是一个例子:

此代码应在“应用程序资源”部分的App.xaml文件中。

XAML

<DataTemplate x:Key="SmallPanoramaTitle">
        <ContentPresenter>
            <TextBlock Text="{Binding}" FontSize="50" Margin="0,0,0,0" />
        </ContentPresenter>
    </DataTemplate>

现在查看后面的代码。 C#

myNewPivotItem.HeaderTemplate = Resource["SmallPanoramaTitle"] as HeaderTemplate;

如果您没有在C#中应用DataTemplate“ SmallPanoramaTitle”,则可以按如下所示在XAML中应用它:

<phone:Pivot Title"Pivot" SelectionChanged="Pivot_SelectionChanged" HeaderTemplate="{StaticResource SmallPanoramaTitle}">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM