WPF:如何让ComboBoxItems持有XAML整数 [英] wpf: how to make ComboBoxItems hold integers in xaml

查看:250
本文介绍了WPF:如何让ComboBoxItems持有XAML整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我必须在这里有一个脑冻...

我有6项的组合框,我想选择的项目绑定到一个整数值。它不工作,我怀疑其因为ComboBoxItem的是字符串。我不觉得像在code列清单的后面正好填补了这个小盒子,所以有在XAML的方式来告诉他们持有整数的comboboxitems?类似< X为:int> 2'; / X:诠释> 也许

XAML:

 <组合框的SelectedItem ={结合SavedPrintTicket.PagesPerSheet}>
    &所述; ComboBoxItem→1&下; / ComboBoxItem>
    &所述; ComboBoxItem→2&下; / ComboBoxItem>
    &所述; ComboBoxItem→4&下; / ComboBoxItem>
    &所述; ComboBoxItem→6&下;​​ / ComboBoxItem>
    &所述; ComboBoxItem→8&下; / ComboBoxItem>
    &所述; ComboBoxItem> 16&下; / ComboBoxItem>
< /组合框>


解决方案

使用System命名空间:

 的xmlns:SYS =CLR的命名空间:系统;装配= mscorlib程序

和那么你的组合框可以包含像这样的整数:

 <&组合框GT;
   < SYS:的Int32> 1 LT; / SYS:&的Int32 GT;
< /组合框>

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>

解决方案

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>

这篇关于WPF:如何让ComboBoxItems持有XAML整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆