[W8.1] [C#] ComboBox问题 [英] [W8.1][C#] Problems with ComboBox

查看:69
本文介绍了[W8.1] [C#] ComboBox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ComboBox有问题。

I have a problem with the ComboBox.

           <ComboBox 
                    x:Uid="ExpenseCategorySelection"
                    x:Name="ExpenseCategorySelectionComboBox" SelectionChanged="ExpenseCategorySelectionComboBox_SelectionChanged"
                    Grid.Row ="1" Grid.Column="0" Margin="0,0,5,0"  ItemsSource="{Binding ExpenseCategories}"
                    >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Margin="0,0,5,0" Text="{Binding Type}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

如果ItemsSource包含的项目超过5个,则在TextBlock中不再显示ItemsSource的第一项。第二个和下面的项目显示得很好。它只是第一个未显示的项目。

If the ItemsSource contains more than 5 Items, the first item of the ItemsSource is not displayed any more any more in the TextBlock. The second and the following items are display just fine. It is only the first item that is not shown.

有任何建议如何解决这个问题?

Any suggestions how to solve ths problem?

推荐答案

Hello
JumpingJack_2

请检查本指南发布
为该主题添加适当的标签。

Please have check this guide post to add a proper tag for the thread.

>>如果ItemsSource包含的项目超过5个,则不会显示ItemsSource的第一项...

根据你的描述和你的代码,我还做了一个测试来显示一个组合框,但是,当我点击组合框时,它可以显示绑定列表中的所有项目。以下是整个代码:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <ComboBox 
                    x:Uid="ExpenseCategorySelection"
                  x:Name="ExpenseCategorySelectionComboBox"
                    Grid.Row ="1" Grid.Column="0" Margin="0,0,5,0"  ItemsSource="{Binding}"
            VerticalAlignment="Center" 
            HorizontalAlignment="Center"
            >
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Margin="0,0,5,0" Text="{Binding Type}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>

代码背后:

public class Entity
    {
        public string Type { get; set; }
    }
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public List<Entity> entities = new List<Entity>();
        public MainPage()
        {
            this.InitializeComponent();
            entities = new List<Entity>() {
                new Entity() { Type="asdasdsdsa1111111"  },
                new Entity() { Type = "asdasdsdsa122222222" },
                new Entity(){ Type="asdasdsdsa33333333"  },
                new Entity() { Type="asdasdsdsa444444"  },
                new Entity() { Type="asdasdsdsa5555555"  },
                new Entity() { Type="asdasdsdsa6666666"  },
                new Entity() { Type = "asdasdsdsa777" },
                new Entity() { Type="asdasdsdsa8888888"  },
                new Entity() { Type="asdasdsdsa999999"  },
                new Entity() { ype="asdasdsdsa10101010"  },
                new Entity() { Type="asdasdsdsa111111"  }
            };
          this.ExpenseCategorySelectionComboBox.ItemsSource = entities;
        }
}

我的测试项目是使用VS2015构建的UWP项目。所以,请尝试使用上面的代码,如果这不适合您,我建议您可以与我们分享您的项目,我们将帮助您进行测试。

问候。


这篇关于[W8.1] [C#] ComboBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆