组合框 windows phone 8.1 无下拉列表

combobox windows phone 8.1 no dropdown

我在 XAML 中为 StackPanel 中的 Windows Phone 8.1 添加了一个 ComboBox。在 运行 上,模拟器中的应用程序未显示下拉功能。如果我将 StackPanel 限制为一个高度,例如“70”,仅显示前 2 个项目。如果我说 Height = "Auto" 那么所有项目都会立即显示。

如何启用下拉功能?

Header:

    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"

组合框..

<StackPanel Grid.Row="4" Width="350" HorizontalAlignment="Left">
            <TextBlock x:Name="PlayerListPanel" TextWrapping="Wrap" Text="Select a Player" VerticalAlignment="Center" Margin="2,0,0,0"  HorizontalAlignment="Left"/>
            <ComboBox Name="StartPlayerComboBox" BorderThickness="1" >
                <ComboBoxItem Tag="PLAYER1">Player 1</ComboBoxItem>
                <ComboBoxItem Tag="PLAYER2">Player 2</ComboBoxItem>
                <ComboBoxItem Tag="PLAYER3">Player 3</ComboBoxItem>
                <ComboBoxItem Tag="Dummy1">1</ComboBoxItem>
                <ComboBoxItem Tag="Dummy2">2</ComboBoxItem>
                <ComboBoxItem Tag="Dummy3">3</ComboBoxItem>
            </ComboBox>
        </StackPanel>

您应该为 combobox 提供足够的高度才能正常打开。如果限制高度,combobox 不能超出该高度。所以它只会显示一些项目。 Height = "Auto" 表示它可以根据需要取任何高度。因此 combobox 将达到正确打开所需的高度。

Combobox Windows Phone/Windows RunTime Environment 的行为与其 Silverlight/WPF 对应物不同。这里我们没有 Popup 来显示要选择的项目列表。因此下拉列表需要足够的 space 来显示选项。

最好将高度保留为自动,或将最小宽度保留为任何宽度要求。

试试 LISTPICKER 控件..它的功能类似于 ComboBox,具有自动调整高度和宽度..

<toolkit:ListPicker>
<toolkit:ListPickerItem Content="A+" />
<toolkit:ListPickerItem Content="B+" />
<toolkit:ListPickerItem Content="O+" />
</toolkit:ListPicker>

使用此在 Xaml 页面中包含以下命名空间..ADD windows phone toolkit(click it)

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;
assembly=Microsoft.Phone.Controls.Toolkit"

如果需要更多信息...返回...

尽管如此,这是一个老问题,除了他们已经说过的;一种将项目选为默认项的方法,您需要 "mark it" 如下:

<ComboBoxItem IsSelected="True">Item 1</ComboBoxItem>

然后,单击它后,将显示所有其他组合框项目(如果您定义了它们):

<ComboBox x:Name="myComboBox" VerticalAlignment="Top" Width="350" FontFamily="open sans" FontSize="20" Height="Auto" Foreground="DarkGray" BorderBrush="Black">
            <ComboBoxItem IsSelected="True">Item 1</ComboBoxItem>
            <ComboBoxItem>Item 2</ComboBoxItem>
            <ComboBoxItem>Item 3</ComboBoxItem>
            <ComboBoxItem>Item 4</ComboBoxItem>
        </ComboBox>

希望对大家有所帮助。问候