Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf: how to make ComboBoxItems hold integers in xaml

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>
like image 757
Shaboboo Avatar asked Aug 27 '09 20:08

Shaboboo


1 Answers

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>
like image 88
Charlie Avatar answered Sep 27 '22 20:09

Charlie