[英]Xamarin custom BindableProperty with Converter
我有一個帶有自定義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
的值是可為null的Int
,所以我必須使用這樣的轉換器:
<view:VolosTimePickerView Grid.Row="0" Grid.Column="1"
Valore="{Binding OrariSelezionati.ViaggioInizioMattina, Converter={StaticResource NullableConverter}}" />
如何在XAML端不使用Converter={StaticResource NullableConverter
,而直接在該屬性后面的代碼中做同樣的事情?
謝謝!
您的Valore
是一個string
。 嘗試將其轉換為Nullable<int> Valore
。 走着瞧吧。
並嘗試將Valore的值也綁定到ViewModel
。 所以你會得到
Nullable<int> _Valore;
public Nullable<int> Valore {get; set;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.