Windows Phone在AppBarButton上以全屏模式打开ListPicker

时间:2014-01-10 18:35:17

标签: windows-phone-8 windows-phone listpicker appbar

我想在ApplicationBarButton上以全屏模式打开ListPicker。 ListPicker应该作为新弹出窗口打开,不应该在页面中显示。

这是我的尝试:

    private void OnAppBarButtonClick(object sender, EventArgs e)
    {
        ListPicker listPicker = new ListPicker();
        listPicker.ExpansionMode = ExpansionMode.FullScreenOnly;
        this.ContentPanel.Children.Add(listPicker);

        ListPickerItem item1 = new ListPickerItem() { Content = "Item1" };
        ListPickerItem item2 = new ListPickerItem() { Content = "Item2" };
        ListPickerItem item3 = new ListPickerItem() { Content = "Item3" };
        listPicker.Items.Add(item1);
        listPicker.Items.Add(item2);
        listPicker.Items.Add(item3);

        listPicker.Open();
    }

2 个答案:

答案 0 :(得分:4)

您可以通过在xaml中定义ListPicker,将ExpansionMode设置为FullScreenOnly并使其折叠来实现此目的。

<Grid x:Name="Content"/>
    <!-- other controls -->
    <toolkit:ListPicker x:Name="Picker" ExpansionMode="FullScreenOnly"
                        Visibility="Collapsed"
                        FullModeHeader="SELECT"
                        ItemsSource="{Binding MyItems}"
                        SelectionChanged="OnPickerSelectionChanged">
        <toolkit:ListPicker.FullModeItemTemplate>
            <DataTemplate>
                <TextBlock Margin="0,20" Text="{Binding Name}"/>
            </DataTemplate>
        </toolkit:ListPicker.FullModeItemTemplate>
    </toolkit:ListPicker>
</Grid>

然后在您的代码中,打开选择器。

Picker.Open();

此示例假定您有一个DataContext,其MyItems属性是具有Name属性的项的集合。

答案 1 :(得分:0)

此代码适用于我,无需任何基本代码,

<toolkit:ListPicker Header="State"
                    x:Name="State" 
                    ExpansionMode="FullScreenOnly">
    <toolkit:ListPicker.FullModeItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" 
                       Margin="0 24 24 24"
                       TextWrapping="Wrap" 
                       Style="{StaticResource PhoneTextTitle2Style}" />
        </DataTemplate>
    </toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>

使用列表初始化State.ItemsSource。