views:

521

answers:

1

ok, I must be having a brain freeze here...

I have a ComboBox with 6 items and I'm trying to bind the selected item to an integer value. Its not working, I suspect its because the ComboBoxItem's are strings. I don't feel like making a list in code behind just to fill this little box, so is there a way in xaml to tell the comboboxitems that they are holding integer numbers? Something like <x:Int>2</x:Int> maybe?

xaml:

<ComboBox SelectedItem="{Binding SavedPrintTicket.PagesPerSheet}">
    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>4</ComboBoxItem>
    <ComboBoxItem>6</ComboBoxItem>
    <ComboBoxItem>8</ComboBoxItem>
    <ComboBoxItem>16</ComboBoxItem>
</ComboBox>
+7  A: 

Use the System namespace:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

And then your combo-box can contain integers like so:

<ComboBox>
   <sys:Int32>1</sys:Int32>
</ComboBox>
Charlie