【问题标题】:wpf: how to make ComboBoxItems hold integers in xamlwpf:如何使 ComboBoxItems 在 xaml 中保存整数
【发布时间】:2010-11-23 12:43:42
【问题描述】:

好吧,我一定是脑子进水了……

我有一个包含 6 个项目的 ComboBox,我正在尝试将所选项目绑定到一个整数值。它不起作用,我怀疑它是因为 ComboBoxItem 是字符串。我不想在后面的代码中列出一个列表来填充这个小框,那么 xaml 中有没有办法告诉组合框项它们持有整数?可能是<x:Int>2</x:Int> 之类的?

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>

【问题讨论】:

    标签: wpf binding combobox selecteditem


    【解决方案1】:

    使用系统命名空间:

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

    然后您的组合框可以包含如下整数:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多