我有一个带有自定义BindableProperty的自定义视图:
public string Valore {
get { return (string)GetValue(ValoreProperty); }
set { SetValue(ValoreProperty, value); }
}
public static readonly BindableProperty ValoreProperty =
BindableProperty.Create(
propertyName: nameof(Valore),
returnType: typeof(string),
declaringType: typeof(VolosTimePickerView),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: ValorePropertyChanged,
propertyChanging: ValorePropertyChanging
);
在我的XAML中,由于Valore
的值是可空的Int
,我必须使用这样的转换器:
<view:VolosTimePickerView Grid.Row="0" Grid.Column="1"
Valore="{Binding OrariSelezionati.ViaggioInizioMattina, Converter={StaticResource NullableConverter}}" />
如果不在XAML端使用Converter={StaticResource NullableConverter
,而是直接在属性后面的代码中,我怎么能做同样的事情呢?
谢谢!
答案 0 :(得分:0)
您的Valore
是string
。尝试将其转换为Nullable<int> Valore
。看看会发生什么。
并尝试在ViewModel
内绑定Valore的值。所以你会得到
Nullable<int> _Valore;
public Nullable<int> Valore {get; set;}