透视项目datatemplate

时间:2012-10-04 16:03:14

标签: windows-phone-7 xaml datatemplate

我想使用this tutorial之后的绑定来填充我的数据透视表。除了1个事实之外,它的效果非常好。我的内容并没有填补它的最大潜力。

正常:

normal button filling

XAML:

<controls:Pivot Title="MY APPLICATION">
    <!--Pivot item one-->
    <controls:PivotItem Header="item1">
        <Button Content="test" />
    </controls:PivotItem>

    <!--Pivot item two-->
    <controls:PivotItem Header="item2">
        <Grid/>
    </controls:PivotItem>
</controls:Pivot>

有约束力:

binding button filling

XAML:

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="TheShopApp.UI.ViewModels.TestPivotItemViewModel">
        <Button Content="Test" />
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

<controls:Pivot Title="{Binding Path=ApplicationName}" ItemsSource="{Binding Path=PivotItems}">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <Grid x:Name="grid">
                <TextBlock TextWrapping="Wrap"
                    Text="{Binding PivotTitle}"
                    d:LayoutOverrides="Width, Height" />
            </Grid>
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <helpers:DataTemplateSelector Content="{Binding}" />
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>

所以现在我的问题是:如何让我的绑定内容看起来像普通内容?我发现this question有点相同,但我无法弄清楚它是如何实现的。

1 个答案:

答案 0 :(得分:4)

我需要将以下XAML添加到templateselector:HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"

<强> XAML:

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="TheShopApp.UI.ViewModels.TestPivotItemViewModel">
        <Button Content="Test" />
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

<controls:Pivot Title="{Binding Path=ApplicationName}" ItemsSource="{Binding Path=PivotItems}">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <Grid x:Name="grid">
                <TextBlock TextWrapping="Wrap"
                    Text="{Binding PivotTitle}"
                    d:LayoutOverrides="Width, Height" />
            </Grid>
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <helpers:DataTemplateSelector HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Content="{Binding}" />
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>