繁体   English   中英

如何在上面的文本框中已显示的WPF组合框中显示值?

[英]How to display values in WPF combobox already displaying in textbox above?

我正在基于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结尾。 任何帮助将是非常可观的。

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

编辑

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM