【问题标题】:ItemsSource in combobox组合框中的 ItemsSource
【发布时间】:2012-06-27 12:12:59
【问题描述】:

一个简单的 xaml:

<ComboBox
    Height="23" Name="status"
    IsReadOnly="False"
    ItemsSource="?"
    Width="120">
</ComboBox>

你需要写到 С# 的内容,将项目粘贴在此处的下拉列表中

【问题讨论】:

标签: c# wpf


【解决方案1】:

您的 ItemsSource 是一个简单的绑定到 [something] 的集合,它将填充组合列表,这是一个快速示例:

public class MyDataSource
{
    public IEnumerable<string> ComboItems 
    {
        get
        {
            return new string[] { "Test 1", "Test 2" };
        }
    }
}

<ComboBox
    Height="23" Name="status"
    IsReadOnly="False"
    ItemsSource="{Binding Path=ComboItems}"
    Width="120">
</ComboBox>

这不是一个完整的示例,但它为您提供了思路。

另外值得注意的是,您不必使用ItemsSource 属性,这也是可以接受的:

<ComboBox
    Height="23" Name="status"
    IsReadOnly="False"
    Width="120">
    <ComboBox.Items>
        <ComboBoxItem>Test 1</ComboBoxItem>
        <ComboBoxItem>Test 2</ComboBoxItem>
    </ComboBox.Items>
</ComboBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多