简体   繁体   English

如何在全屏页面中显示ComboBox的所有项目?

[英]How show all items of ComboBox in fullscreen page?

I am creating ComboBox for windows phone 8.1 on a Universal Apps project, but I would like show always all items on fullscreen page. 我正在为Universal Apps项目创建Windows Phone 8.1的ComboBox,但我想在全屏页面上显示所有项目。 On windows phone 8 I do 在Windows Phone 8上我做

ListPicker.ExpansionMode = ExpansionMode.FullScreenOnly;

but, in ComboBox for windows phone 8.1 I don't found option. 但是,在ComboBox for Windows phone 8.1中我找不到选项。

How can I solve this problem? 我怎么解决这个问题?

Thanks! 谢谢!

The ComboBox Control in WP8.1 will decide to show items in FullScreen or DropDown List. WP8.1中的ComboBox控件将决定在FullScreen或DropDown列表中显示项目。 When your items count > 5 , it will show in FullScreen. 当您的商品数量> 5时 ,它将显示在FullScreen中。 OtherWise, it will show in DropDown List. OtherWise,它将显示在DropDown列表中。 We can't change it by code. 我们无法通过代码更改它。

Late answer but hope it helps others. 迟到的答案,但希望它能帮助别人。

By default the combobox will show longlist only if the count of items has exceeded 5 items. 默认情况下,只有当项目数超过5项时,组合框才会显示长列表。 If you need to show the fullscreen for combobox you can attach a listpicker flyout to a button in place of combobox. 如果您需要显示组合框的全屏,可以将listpicker弹出按钮附加到按钮以代替组合框。 That would be the ideal solution I guess. 那我认为这是理想的解决方案。 And it almost satisfies all the implementations of longlist 它几乎满足了longlist的所有实现

If (you have 3 items in combobox) then { Also add 3 items in combobox whith content " " } 如果(你在组合框中有3个项目)那么{还在组合框中添加3项内容“”}

Add this handler: 添加此处理程序:

private void DoSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ComboBox cb = (sender as ComboBox);
    if (cb.SelectedIndex > -1)
    {
        string s = (cb.SelectedValue as ComboBoxItem).Content as string; 
        if (s == " ")
        {
            cb.SelectedIndex = cb.GetLastIndex();
        }
    }
    cb.SetLastIndex(cb.SelectedIndex);
}

public static class Extensions
{
    private static Dictionary<ComboBox, int> _lastIndex = new Dictionary<ComboBox, int>();
    public static int GetLastIndex(this ComboBox me)
    {
        return _lastIndex.ContainsKey(me) ? _lastIndex[me] : -1;
    }
    public static void SetLastIndex(this ComboBox me, int NewValue)
    {
        if (_lastIndex.ContainsKey(me))
            _lastIndex[me] = NewValue;
        else
            _lastIndex.Add(me,NewValue);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM