Непоследовательное отображение выпадающего списка ComboBox в Silverlight 4

У меня есть приложение Silverlight 4 с ComboBox в нижней части формы. В выпадающем списке может быть от 30 до 100 элементов.

Когда я впервые открываю ComboBox, в нем нет SelectedItem, выпадающий список открывается вверх и делает видимыми около 23 записей; это поведение будет продолжаться каждый раз, когда я снова открываю выпадающий список, до тех пор, пока я не выберу элемент. Как только я выбираю элемент, каждый раз, когда я открываю ComboBox после этого, он всегда открывает выпадающий список вниз и делает видимыми только 3 элемента.

Я предполагаю, что выпадающий список ограничен 3 элементами, потому что это нижний предел окна, когда оно максимизировано на моем экране.

Как заставить его отображать больше элементов, даже если элемент был выбран ранее?

Вот пример Silverlight приложения, которое демонстрирует поведение, как в браузере, так и вне его.

MainPage.xaml:

<UserControl x:Class="ComboBox_Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="650" d:DesignWidth="1024">

    <Grid x:Name="LayoutRoot" Background="LightSteelBlue" Loaded="MainPage_OnLoaded">
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" MinHeight="25" MaxHeight="25" />
            <RowDefinition Height="35*" MinHeight="200" />
            <RowDefinition Height="10*" MinHeight="70" MaxHeight="70" />
            <RowDefinition Height="30*" MinHeight="230" MaxHeight="230" />
            <RowDefinition Height="*" MinHeight="10" MaxHeight="30" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="12" />
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="12" />
        </Grid.ColumnDefinitions>
        <TextBlock Name="lblData" Text="Data:" Grid.Row="1" Grid.Column="1" />
        <TextBox x:Name="txtData" Grid.Row="1" Grid.Column="2" VerticalScrollBarVisibility="Auto"
                HorizontalScrollBarVisibility="Auto" />
        <StackPanel x:Name="AccessPanel" Orientation="Vertical" HorizontalAlignment="Left" Margin="5"
                Grid.Row="3" Grid.Column="2" Visibility="Visible">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="75" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackPanel x:Name="CreationPanel" Orientation="Vertical" Grid.Row="1">
                    <Grid x:Name="CreationRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="40" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel x:Name="TypesPanel" Orientation="Horizontal" Grid.Row="1" Grid.Column="1"
                                        Margin="0 5 0 5">
                            <Grid x:Name="TypesRoot">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="220" />
                                    <ColumnDefinition Width="220" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="Types" FontFamily="Arial" FontSize="12" FontWeight="Bold"
                                                        Grid.Row="0" Grid.Column="0" />
                                <ComboBox x:Name="cboTypes" Width="220" Height="30" Grid.Row="1" Grid.Column="0"
                                                        IsEnabled="True"
                                                        SelectionChanged="cboTypes_SelectionChanged">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Name, Mode=OneWay}" />
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>
                            </Grid>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>

MainPage.xaml.cs:

using System;
using System.Windows;
using System.Windows.Controls;

namespace ComboBox_Test
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void UpdateDataText(DataTypeDesc oData)
        {
            txtData.Text = String.Format("{0}\n\t{1}", oData.Name, oData.Desc);
        }

        private void MainPage_OnLoaded(object sender, RoutedEventArgs e)
        {
            object[] aDataTypeDescs = new object[] 
            {
                  new DataTypeDesc() {Name = "Boolean", Desc = "A Boolean value"}
                , new DataTypeDesc() {Name = "Byte",    Desc = "An 8-bit unsigned integer"}
                , new DataTypeDesc() {Name = "Char",    Desc = "A Unicode character"}
                , new DataTypeDesc() {Name = "Double",  Desc = "A double-precision floating-point number"}
                , new DataTypeDesc() {Name = "float",   Desc = "A single-precision floating-point number"}
                , new DataTypeDesc() {Name = "Int16",   Desc = "A 16-bit signed integer"}
                , new DataTypeDesc() {Name = "Int32",   Desc = "A 32-bit signed integer"}
                , new DataTypeDesc() {Name = "Int64",   Desc = "A 64-bit signed integer"}
                , new DataTypeDesc() {Name = "SByte",   Desc = "An 8-bit signed integer"}
                , new DataTypeDesc() {Name = "UInt16",  Desc = "A 16-bit unsigned integer"}
                , new DataTypeDesc() {Name = "UInt32",  Desc = "A 32-bit unsigned integer"}
                , new DataTypeDesc() {Name = "UInt64",  Desc = "A 64-bit unsigned integer"}
                , new DataTypeDesc() {Name = "A",       Desc = "The letter A in the alphabet"}
                , new DataTypeDesc() {Name = "B",       Desc = "The letter B in the alphabet"}
                , new DataTypeDesc() {Name = "C",       Desc = "The letter C in the alphabet"}
                , new DataTypeDesc() {Name = "D",       Desc = "The letter D in the alphabet"}
                , new DataTypeDesc() {Name = "E",       Desc = "The letter E in the alphabet"}
                , new DataTypeDesc() {Name = "F",       Desc = "The letter F in the alphabet"}
                , new DataTypeDesc() {Name = "G",       Desc = "The letter G in the alphabet"}
                , new DataTypeDesc() {Name = "H",       Desc = "The letter H in the alphabet"}
                , new DataTypeDesc() {Name = "I",       Desc = "The letter I in the alphabet"}
                , new DataTypeDesc() {Name = "J",       Desc = "The letter J in the alphabet"}
                , new DataTypeDesc() {Name = "K",       Desc = "The letter K in the alphabet"}
                , new DataTypeDesc() {Name = "L",       Desc = "The letter L in the alphabet"}
                , new DataTypeDesc() {Name = "M",       Desc = "The letter M in the alphabet"}
                , new DataTypeDesc() {Name = "N",       Desc = "The letter N in the alphabet"}
                , new DataTypeDesc() {Name = "O",       Desc = "The letter O in the alphabet"}
                , new DataTypeDesc() {Name = "P",       Desc = "The letter P in the alphabet"}
                , new DataTypeDesc() {Name = "Q",       Desc = "The letter Q in the alphabet"}
                , new DataTypeDesc() {Name = "R",       Desc = "The letter R in the alphabet"}
                , new DataTypeDesc() {Name = "S",       Desc = "The letter S in the alphabet"}
                , new DataTypeDesc() {Name = "T",       Desc = "The letter T in the alphabet"}
                , new DataTypeDesc() {Name = "U",       Desc = "The letter U in the alphabet"}
                , new DataTypeDesc() {Name = "V",       Desc = "The letter V in the alphabet"}
                , new DataTypeDesc() {Name = "W",       Desc = "The letter W in the alphabet"}
                , new DataTypeDesc() {Name = "X",       Desc = "The letter X in the alphabet"}
                , new DataTypeDesc() {Name = "Y",       Desc = "The letter Y in the alphabet"}
                , new DataTypeDesc() {Name = "Z",       Desc = "The letter Z in the alphabet"}
            };

            cboTypes.ItemsSource = aDataTypeDescs;
        }

        private void cboTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataTypeDesc oDesc = (DataTypeDesc)(cboTypes.SelectedItem);
            if (oDesc != null)
                UpdateDataText(oDesc);
        }

    }
}

DataTypeDesc.cs:

using System;

namespace ComboBox_Test
{
    public class DataTypeDesc
    {
        public String Name { get; set; }
        public String Desc { get; set; }
    }
}
6
задан Luke Woodward 20 October 2012 в 22:16
поделиться