简体   繁体   中英

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

I am working on a project based on WPF , C# and MVVM . Its basically a networking device configurable application via telnet. The issue is that I have a textbox in which I am displaying some values. I want to take those values from the textbox and display them in a combo box. See the attached screenshot which makes it more clear for all of you.

<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");
        }
    }

在此处输入图片说明

One more thing is that I just want those values in the combo box which starts from f8 and ends at 0 . Any help would be greatly appreciable.

You should create a collection from the values comes from the Config Library then bind this collection to the ItemsSource of the Combobox.

Edit

You should create a property which stores the options from the Config Library (for the sake of simplicity it just a string ObservableCollection in this example):

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

Then fill the collection with the options. Just create a method for that (I do not know how your config library looks like). Finally, you have to bind the collection to the ItemsSource of the ComboBox:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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