WP8 Listpicker不会进入完整模式

时间:2015-10-26 15:13:12

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

我正在开发一款Windows phone 8.1 silverlight app。

我需要创建一个ListPicker并在全屏模式下打开它,但总是得到错误,因为不检测listpicker元素上的ExpansionMode。

我的代码XML:

<phone:PhoneApplicationPage
    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"
    x:Class="FlyGolf_V1.Views.event_detail"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">


    <Grid>
        <ScrollViewer>
            <Grid x:Name="scheduleGrid" Grid.Row="1" Background="#f3f3f4">
                <Grid.RowDefinitions>
                    <RowDefinition Height="60" />
                    <RowDefinition Height="130" />
                    <RowDefinition Height="80" />
                    <RowDefinition Height="100" />
                    <RowDefinition Height="80" />
                    <RowDefinition Height="100" />
                    <RowDefinition Height="80" />
                    <RowDefinition Height="340" />
                    <RowDefinition Height="340" />
                </Grid.RowDefinitions>

                <!-- SAVE DATA -->


                <!-- EVENT GERAL INFO -->
                <StackPanel x:Name="datePanel" Height="220" Grid.Row="0" Grid.Column="0" 
                            Margin="0,0,0,20" Background="#18a689">
                    <TextBlock x:Name="txtDate"  HorizontalAlignment="Center" Margin="0,0,0,0" 
                               TextWrapping="Wrap" Text="Date" VerticalAlignment="Top" 
                               FontSize="25" FontWeight="Bold" />
                </StackPanel>

                <Grid Grid.Row="1" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="250" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="130" />
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Column="0" Grid.Row ="0">
                        <Ellipse  x:Name="ellipseStatus" Width="80" Height="80" 
                                  Margin="10,25,10,0" Fill="Green"/>
                    </StackPanel>
                    <StackPanel Grid.Column="1">
                        <TextBlock x:Name="txtType" Margin="0,5,0,0" TextWrapping="Wrap" 
                                   Text="Type" VerticalAlignment="Top" FontSize="20" 
                                   FontWeight="Bold" Foreground="#576A6C"/>
                        <TextBlock x:Name="txtDurationHeader" Margin="0,2,0,0" TextWrapping="Wrap" 
                                   Text="Duration" VerticalAlignment="Top" FontSize="18" Foreground="#576A6C"/>
                        <TextBlock x:Name="txtDescription" Margin="0,0,5,0" TextWrapping="Wrap" 
                                   Text="Description" VerticalAlignment="Top" FontSize="18" Foreground="#576A6C"/>
                    </StackPanel>
                    <Grid Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel x:Name="spStatusComplete" Grid.Row="0" 
                                    Height="40" Margin="0,10,0,0">
                            <TextBlock x:Name="txtStatusComplete" Margin="0,5,10,0" HorizontalAlignment="Center" TextWrapping="Wrap" 
                                       Text="status" VerticalAlignment="Top" FontSize="20"/>
                        </StackPanel>

                        <StackPanel x:Name="spStatusAccepted" Grid.Row="1" 
                                    Height="40" Margin="0,-10,0,0">
                            <TextBlock x:Name="txtStatusAccepted" Margin="0,5,10,0" HorizontalAlignment="Center" TextWrapping="Wrap" 
                                       Text="status" VerticalAlignment="Top" FontSize="20"/>
                        </StackPanel>
                    </Grid>
                </Grid>

                <!-- INITIAL DATE / TIME INFO -->
                <StackPanel x:Name="initialDateTimePanel" Height="220" Grid.Row="2" Grid.Column="0" 
                            Margin="0,20,0,20" Background="#18a689">
                    <TextBlock x:Name="lblinitialDateTime"  HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap" 
                               Text="Initial Date / Initial Time" VerticalAlignment="Top" 
                               FontSize="25" FontWeight="Bold" />
                </StackPanel>

                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <toolkit:DatePicker x:Name="dpInitialDate" Grid.Column="0" Foreground="#676a6c" BorderBrush="#676a6c" 
                                        HorizontalAlignment="Center" VerticalAlignment="Center" />

                    <toolkit:TimePicker x:Name="tpInitialTime" Grid.Column="1" Foreground="#676a6c" BorderBrush="#676a6c" 
                                        HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>

                <!-- FINAL DATE / TIME INFO -->
                <StackPanel x:Name="finalDateTimePanel" Height="220" Grid.Row="4" Grid.Column="0" 
                            Margin="0,20,0,20" Background="#18a689">
                    <TextBlock x:Name="lblfinalDateTime" HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap" 
                               Text="Final Date / Final Time" VerticalAlignment="Top" 
                               FontSize="25" FontWeight="Bold" />
                </StackPanel>

                <Grid Grid.Row="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="41*" />
                        <ColumnDefinition Width="79*"/>
                        <ColumnDefinition Width="120*" />
                    </Grid.ColumnDefinitions>

                    <toolkit:DatePicker x:Name="dpFinalTime" Grid.Column="0" Foreground="#676a6c" BorderBrush="#676a6c" 
                                        HorizontalAlignment="Center" VerticalAlignment="Center" 
                                        Grid.ColumnSpan="2" Margin="37,14" />

                    <toolkit:TimePicker x:Name="tpFinalTime" Grid.Column="2" Foreground="#676a6c" BorderBrush="#676a6c" 
                                        HorizontalAlignment="Center" VerticalAlignment="Center" Margin="53,14,52,14" />
                </Grid>

                <!-- DURATION / ACTIVITY TYPE INFO -->
                <StackPanel Grid.Row="6" x:Name="durationPanel" Height="220" Grid.Column="0" 
                            Margin="0,20,0,20" Background="#18a689">
                    <TextBlock x:Name="lblDuration"  HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap" 
                               Text="Duration / Activity Type" VerticalAlignment="Top" 
                               FontSize="25" FontWeight="Bold" />
                </StackPanel>

                <Grid Grid.Row="7">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="70" />
                        <RowDefinition Height="200" />
                        <RowDefinition Height="300" />
                    </Grid.RowDefinitions>

                    <TextBox x:Name="txtDuration" TextAlignment="Center" Grid.Row="0" Foreground="#676a6c" BorderBrush="#676a6c" 
                             HorizontalAlignment="Center" TextWrapping="Wrap" Text="Duration" 
                             VerticalAlignment="Center" Width="250" 
                             GotFocus="TextBox_GotFocus" LostFocus="txtDuration_LostFocus"/>

                    <ScrollViewer Grid.Row="1">
                        <toolkit:ListPicker x:Name="lpActivityType" ExpansionMode="FullScreenOnly" 
                                            Foreground="#676a6c" BorderBrush="#676a6c" Grid.Column="1" 
                                            HorizontalAlignment="Center" VerticalAlignment="Center">
                        </toolkit:ListPicker>
                    </ScrollViewer>

                    <TextBox x:Name="txtComments" Grid.Row="2" AcceptsReturn="True" Margin="5" Height="200" 
                             Foreground="#676a6c" BorderBrush="#676a6c" VerticalScrollBarVisibility="Visible" 
                             TextWrapping="Wrap" VerticalAlignment="Center" Text="Comments" 
                             LostFocus="txtComments_LostFocus" GotFocus="txtComments_GotFocus" />
                </Grid>

            </Grid>
        </ScrollViewer>
    </Grid>
</phone:PhoneApplicationPage>

我的构造函数页面函数:

public event_detail()
{
    InitializeComponent();

    String[] listProjects = {
                                "1º Projecto Drive", 
                                "2º Projecto Drive 2º Projecto Drive",
                                "3º Projecto Drive",
                                "4º Projecto Drive",
                                "5º Projecto Drive",
                                "6º Projecto Drive",
                                "7º Projecto Drive",
                                "8º Projecto Drive",
                                "9º Projecto Drive",
                                "10º Projecto Drive",
                                "11º Projecto Drive",
                            };
    foreach (var item in listProjects)
    {
        this.lpActivityType.Items.Add(item);
    }
}   

这些是错误:

  

错误1在“ListPicker”类型中找不到属性“ExpansionMode”。 E:... \ event_detail.xaml 123 69 FlyGolf_V1   错误2无法识别或无法访问成员“ExpansionMode”。 E:... \ event_detail.xaml 123 69 FlyGolf_V1

1 个答案:

答案 0 :(得分:0)

您需要添加toolkit:ListPicker

ItemTemplate="{StaticResource ListPickerItemTemplate}"

FullModeItemTemplate="{StaticResource ListPickerFullModeItemTemplate}"

如下所示

<toolkit:ListPicker x:Name="lpActivityType" ExpansionMode="FullScreenOnly" Foreground="#676a6c" 
                    BorderBrush="#676a6c" Grid.Column="1" HorizontalAlignment="Center" 
                    VerticalAlignment="Center" Width="320" Height="Auto"
                    ItemTemplate="{StaticResource ListPickerItemTemplate}"
                    FullModeItemTemplate="{StaticResource ListPickerFullModeItemTemplate}">
</toolkit:ListPicker>

这也是如下

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Name="ListPickerItemTemplate">
        <StackPanel Orientation="Horizontal" Background="White">
            <TextBlock Text="{Binding}" Margin="0,0,0,0" 
                   FontWeight="Normal" Foreground="Black" FontSize="18" />
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Name="ListPickerFullModeItemTemplate">
        <StackPanel Orientation="Horizontal">
            <Grid Margin="0,0,0,0">
                <TextBlock Margin="0,2,0,0" Text="{Binding}"
                       FontSize="22" TextWrapping="Wrap" Height="Auto"  />
            </Grid>
        </StackPanel>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources

shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">之后和<Grid>之前

并添加.cs文件

lpActivityType.ItemsSource = listProjects.ToList();