我正在尝试将组合框绑定到我的ViewModel上的属性。目标类型为 short? 我想要 null 是一种选择。基本上,我希望组合框中第一项的值为 {x:Null} .
short?
null
{x:Null}
<ComboBox Grid.Row="9" Grid.Column="1" SelectedValue="{Binding Priority}"> <clr:Int16></clr:Int16> <clr:Int16>1</clr:Int16> <clr:Int16>2</clr:Int16> <clr:Int16>3</clr:Int16> <clr:Int16>4</clr:Int16> <clr:Int16>5</clr:Int16> <clr:Int16>6</clr:Int16> <clr:Int16>7</clr:Int16> <clr:Int16>8</clr:Int16> <clr:Int16>9</clr:Int16> <clr:Int16>10</clr:Int16> </ComboBox>
有什么建议吗?
如果您使用的是XAML 2009/.NET 4,那么可以使用新的语法来创建使用XAML的泛型。
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/presentation" <Nullable x:TypeArguments="clr:Int16" />
这个 article 在XAML中有其他更复杂的仿制药场景。