windows - 如何在 Windows Phone 8 的透视表头中添加图像和按钮

标签 windows windows-phone-8 windows-phone pivotviewer

请检查下图以供引用有关我的问题的信息。

enter image description here

我正在尝试在 PIVOT 标题中实现带有注销按钮的公司 Logo 。

与上面链接中所示的类似方式,即美国银行 Windows 手机应用程序。

我是 Windows Phone 8 应用程序开发新手。

任何用于实现此概念的解决方案/指南/帮助将不胜感激。

最佳答案

更新1

添加xmlns:Primitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone"在顶部<phone:PhoneApplicationPage ... />


您需要为 Pivot 创建自定义样式因为Pivot的标题需要满足第一列和第三列定义必须为:Width="Auto"的条件。您不能像这样直接分配 UI 元素。

<phone:Pivot>
    <phone:Pivot.Title>
        <!-- XAML Elements -->
    </phone:Pivot.Title>
    <phone:PivotItem>
    .....
</phone:Pivot>

尝试下面的代码。

<phone:PhoneApplicationPage.Resources>
    <Style x:Key="PivotStyle1" TargetType="phone:Pivot">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="phone:Pivot">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <Grid Background="{TemplateBinding Background}" Grid.RowSpan="3"/>

                        <Grid Background="#d60019" Height="50">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBlock
                                HorizontalAlignment="Left"
                                Margin="12,0,0,0"
                                Foreground="White"
                                FontSize="20"
                                VerticalAlignment="Center"
                                Text="Bank of America" 
                                Tap="TextBlock_Tap_1"/>

                            <ContentControl
                                ContentTemplate="{TemplateBinding TitleTemplate}"
                                Content="{TemplateBinding Title}" 
                                Grid.Column="1"
                                HorizontalAlignment="Left"
                                Margin="0,0,0,-7"
                                VerticalAlignment="Center"
                                Style="{StaticResource PivotTitleStyle}"/>

                            <TextBlock
                                Foreground="White"
                                FontSize="20"
                                Margin="0,0,10,0"
                                Grid.Column="2"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Text="sign out" />

                        </Grid>

                        <Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
                        <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>

<Grid x:Name="LayoutRoot">
    <phone:Pivot
    Title=""
    Style="{StaticResource PivotStyle1}">

        <phone:PivotItem
        Header="accounts" />

        <phone:PivotItem
        Header="deals" />

    </phone:Pivot>
</Grid>

关于windows - 如何在 Windows Phone 8 的透视表头中添加图像和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19654905/

相关文章:

c# - Silverlight - 在 C# 中更改数据网格标题的字体大小

c# - 如何倒序显示 LongListSelector 的项目?

windows - 如何在VBS 中使用MsgBox 中的计算机名环境变量?

c++ - Mingw-x64 中的类型错误

windows-phone-8 - 如何加载高分辨率图像Windows Phone任务代理? [内存不足]

uwp - 警报声明给出错误 UWP 应用程序?

c++ - 获取运行可执行文件的文件句柄

windows - 当命令有空格时将命令输出检索到变量

c# - 如何添加mediaelement搜索栏

c# - WP8 定义多个预处理器值