【问题标题】:ListPicker Items not being shown in FullScreen ModeListPicker 项目未在全屏模式下显示
【发布时间】:2014-09-04 11:02:43
【问题描述】:

我使用了一个 TOOLKIT ListPicker 。但是这些项目没有以全屏模式显示。单击 ListPicker 时它是一个空白页面,但这些项目是透明的,甚至可以被选中。它似乎是空白页,但项目在那里。

<phone:PhoneApplicationPage
x:Class="Sunder_Gutka.SettingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">

<phone:PhoneApplicationPage.Resources>

    <DataTemplate x:Name="PickerItemTemplate">
        <TextBlock Text="{Binding BackGroundColorArray}" />
    </DataTemplate>

    <DataTemplate x:Name="PickerFullModeItemTemplate" >
        <TextBlock Name="BackgroundColor" 

    Text="{Binding BackGroundColorArray}"                      
                   />
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>



<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <toolkit:ListPicker x:Name="BackgroundColor"  FullModeHeader="Select Background Color:" Header="Background Color:" BorderThickness="0" FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" ItemTemplate="{StaticResource PickerItemTemplate}" Background="#FF09043C" SelectionChanged="BackgroundColor_SelectionChanged" >

        </toolkit:ListPicker>



    </Grid>
</Grid>


    using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace Sunder_Gutka
{
    public partial class SettingPage : PhoneApplicationPage
    {
        String[] BackGroundColorArray = { "Black", "Light Grey", "White[Default]", "Blue", "Green", "Saffron", "Yellow", "Magenta", "Dark Grey", "Red" }; //To be used in LISTPICKER

        public SettingPage()
        {
            InitializeComponent();
            this.BackgroundColor.ItemsSource = BackGroundColorArray; //Item Source  of listpicker

        }
        string SelectedBackgroundColor;

        private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
             SelectedBackgroundColor = BackgroundColor.SelectedItem.ToString();
        }

    }

【问题讨论】:

    标签: c# xaml windows-phone-8 toolkit listpicker


    【解决方案1】:

    更新您的数据模板:

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Name="PickerItemTemplate">
            <TextBlock Text="{Binding}" />
        </DataTemplate>
        <DataTemplate x:Name="PickerFullModeItemTemplate" >
            <TextBlock Name="BackgroundColor" Text="{Binding}"/>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    

    它现在正在工作。我已经实现了。

    【讨论】:

    • 它显然会起作用。但我得到一个全屏的丑陋列表。我试着设计它。在我的另一个项目中,同样的线路运行良好。这可能是什么问题?
    • 你说的很明显是什么意思?你问了一个简单的问题,这是一个答案。现在你正在增加你的查询。问问题时请具体。您可以将列表或集合绑定到绑定,因此这里它不起作用。尝试使用列表或观察集合然后它会完美地工作。如果我的回答对您有所帮助,请标记为已回答以供其他人参考。
    • 我告诉你的是我在页面上得到了列表,我通过调试检查了它,但它没有显示出来
    • 我已在新项目中实施。代码与上面相同,但区别仅在于我发布的答案及其工作。列表项正确显示到列表中。要对其进行样式设置,您需要修改其默认模板或修改您的数据模板。
    【解决方案2】:

    默认情况下,当您以全屏模式显示项目时,您的项目以较小的字体显示。所以你要做的就是把全屏模式ItemTempate的DataTampleate改成following..我这里只增加了FontSize..你可以做任何你喜欢的样式。

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Name="PickerItemTemplate">
            <TextBlock Text="{Binding}" />
        </DataTemplate>
    
        <DataTemplate x:Name="PickerFullModeItemTemplate" >
            <TextBlock Name="BackgroundColor" Text="{Binding}" FontSize="{StaticResource PhoneFontSizeLarge}" />
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    

    模板的样式由您决定。我也希望你知道ListPicker 只有在ListPicker 中有超过 5 个项目时才会进入全屏模式。如果没有,您需要手动设置ExpansionMode="FullScreenOnly" 以使其全屏显示。

    【讨论】:

    • 现在好了。但是字体呢?我尝试使用:FontFamily="/Sunder Gutka;component/Assets/Fonts/AGENCYR.TTF#Agency FB" 但列表没有以这种字体显示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多