【问题标题】:How to display values in WPF combobox already displaying in textbox above?如何在上面的文本框中已经显示的 WPF 组合框中显示值?
【发布时间】:2014-12-17 07:36:37
【问题描述】:

我正在开发一个基于WPFC#MVVM 的项目。它基本上是一个通过 telnet 的网络设备可配置应用程序。问题是我有一个文本框,我在其中显示一些值。我想从文本框中获取这些值并将它们显示在组合框中。请参阅随附的屏幕截图,让大家更清楚。

<ComboBox
    Grid.Column="1"
    Grid.Row="0"
    Margin="0,4"
    Text="{Binding ApGroupsManagementApMac}">
</ComboBox>



public string ApGroupsManagementApMac
{

    // Retreive value from Configuration Library
    get
    {
        //Console.WriteLine("get WpaWpa2RadiusKey");
        return this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac;
    }

    // Set value in Configuration Library
    set
    {
        if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac, value))
        {
            //Console.WriteLine("set WpaWpa2RadiusKey");
            this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac = value;

            // ValidateWLAN1RadiusKey(value);

            this.OnPropertyChanged("ApGroupsManagementApMac");
        }
    }
}

 string _apGroupsManagementApMac;

    public string ConfigLibraryApGroupsManagementApMac
    {
        get
        {
            return _apGroupsManagementApMac;
        }
        set
        {
            if (String.Equals(_apGroupsManagementApMac, value))
            {
                return;
            }
            _apGroupsManagementApMac = value;
            OnPropertyChanged("ConfigLibraryApGroupsManagementApMac");
        }
    }

还有一件事是我只希望组合框中的这些值从f8 开始并以0 结束。任何帮助都将不胜感激。

【问题讨论】:

  • 您能从此处的配置中复制/粘贴您的 ApGroupsManagementApMac 吗?
  • @cYounes 代码已添加!

标签: c# wpf mvvm combobox


【解决方案1】:

您应该根据来自配置库的值创建一个集合,然后将此集合绑定到组合框的 ItemsSource。

编辑

您应该创建一个属性来存储配置库中的选项(为简单起见,在本示例中它只是一个字符串 ObservableCollection):

 public ObservableCollection<string> Collection
        {
            get;
            set;
        }

然后用选项填充集合。只需为此创建一个方法(我不知道您的配置库如何)。最后,您必须将集合绑定到 ComboBox 的 ItemsSource:

<ComboBox
    Grid.Column="1"
    Grid.Row="0"
    Margin="0,4"
    ItemsSource="{Binding Collection}">
</ComboBox> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多