0

Is there a Xaml ComboBoxItem equivalent for an HTML select value property?

<select>
    <option value=1>Test 1</option>
    <option value=2>Test 2</option>
    <option value=3>Test 3</option>
</select>

Doesn't seem like there's a way to do that with Xaml?

<ComboBox>
    <ComboBoxItem Content="Test 1" />
    <ComboBoxItem Content="Test 2" />
    <ComboBoxItem Content="Test 3" />
</ComboBox>

Obviously, I'd like the user to select and option and then be able to pull the value (ID) for that selection to work with instead of having to do a lookup from the text/content value.

RichC
  • 7,829
  • 21
  • 85
  • 149

2 Answers2

1

You can use Tag:

<ComboBox>
    <ComboBoxItem Content="Test 1" Tag="1"/>
    <ComboBoxItem Content="Test 2" Tag="2"/>
    <ComboBoxItem Content="Test 3" Tag="3"/>
</ComboBox>
Chris Shao
  • 8,231
  • 3
  • 39
  • 37
  • Interesting. I did some reading on that property and it seems to be the "junk drawer" for whatever you want to use it for property. – RichC May 27 '14 at 03:25
  • Do you know how I would assign that programmatically? – RichC May 27 '14 at 22:51
  • Ahh - I think [this is what I'm looking for](http://stackoverflow.com/questions/3797034/confused-with-wpf-combobox-displaymemberpath-selectedvalue-and-selectedvaluepath). – RichC May 27 '14 at 22:58
0

Why don't you use dropdownlist

<dropdownlist > Your options goes here <\dropdownlist>

MK55SDV
  • 137
  • 1
  • 2
  • 7