Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF/C# - ´binding list<string> to combobox

I want my combobox item names and values to be taken from my List of course I don't want my view model to hold combobox items list.

I got a list a,b,c,d

public List<String> ComboList { get; set; }

...

ComboList = new List<String>();
ComboList.Add("A");
ComboList.Add("B");
ComboList.Add("C");
ComboList.Add("D");

and my ComboBox

<ComboBox Margin="29,40,0,526" Width="212" Height="35" Grid.Row="1" ItemsSource="{Binding Path=ComboList, Mode=OneTime}" SelectedValuePath="Key" DisplayMemberPath="Value"></ComboBox>

but it gives me a empty ComboBox ...

enter image description here

like image 777
David Avatar asked Aug 13 '26 18:08

David


1 Answers

Remove the SelectedValuePath and DisplayMemberPath attributes. They are wrong.

like image 129
scottheckel Avatar answered Aug 15 '26 09:08

scottheckel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!