1
有沒有辦法讓null?如果我這樣做,它將它作爲0.該屬性在業務類和SQL表中可爲空。我使用了一個帶有ClearSelectionButton的Combobox,所以也許已經有一種方法可以在View中修復它。設置爲空而不是0 - int
我在查看組合框
<telerik:RadComboBox x:Name="CommandButton" ItemsSource="{Binding Path=ColorList}"
SelectedValue="{Binding Path=Model.Color, Converter={StaticResource VCShortIntToInt}, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
DisplayMemberPath="Text" SelectedValuePath="number" ClearSelectionButtonVisibility="Visible" ClearSelectionButtonContent="empty" />
我在企業級
public static PropertyInfo<short?> ColorProperty = RegisterProperty<short?>(c=>c.Color);
public short? Color
{
get { return GetProperty<short?>(ColorProperty); }
set { SetProperty<short?>(ColorProperty, value); }
}
轉換
public class VCShortIntToInt : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Int32 result = 0;
if (value != null && value.GetType() == typeof(Int16))
{
result = System.Convert.ToInt32(value);
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Int16 result = 0;
if (value != null && value.GetType() == typeof(Int32))
{
result = System.Convert.ToInt16(value);
}
return result;
}
}