2017-04-08 5 views
1

저는 Ed Snider의 Mastering Xamarin.Forms를 통해 작업 해 왔습니다. 71 페이지에서는 EntryCell을 상속하는 DatePickerEmtryCell 클래스를 작성하도록 지시합니다. 다음 DateTime BindableProperty를 추가하는 것으로 표시되지만이 메서드는 더 이상 사용되지 않으며 오류가 발생합니다.Xamarin.Forms 사용자 지정 DateTime BindableProperty BindingPropertyChangedDelegate

public static readonly BindableProperty DateProperty = BindableProperty.Create<DatePickerEntryCell, DateTime>(p => 
    p.Date, 
    DateTime.Now, 
    propertyChanged: new BindableProperty.BindingPropertyChangedDelegate<DateTime>(DatePropertyChanged)); 

나는 다음과 바른 길에 오전 생각하지만, 나는 그것을 완료하는 방법을 잘 모르겠습니다 완전히 붙어 오전 :

public static readonly BindableProperty DateProperty = 
    BindableProperty.Create(nameof(Date), typeof(DateTime), typeof(DatePickerEntryCell), default(DateTime), 
     BindingMode.TwoWay, null, new BindableProperty.BindingPropertyChangedDelegate(

내가 그것을이

될 것이라고 생각
new BindableProperty.BindingPropertyChangedDelegate(DatePickerEntryCell.DatePropertyChanged), null, null);  

하지만이 시도는 무수히 많은 다른 순열과 함께 올바르지 않습니다. 나는 약간의 지시를 좋아할 것이다.

건배 DateProperty 이후

답변

2

정적이다 propertyChanged 대표도 정적이어야한다. 형식이 BindingPropertyChangedDelegate이므로 당신은이 방법을 시도 할 수 있습니다 :

public static readonly BindableProperty DateProperty = BindableProperty.Create(
     propertyName: nameof(Date), 
     returnType: typeof(DateTime), 
     declaringType: typeof(DatePickerEntryCell), 
     defaultValue: default(DateTime), 
     defaultBindingMode: BindingMode.TwoWay, 
     validateValue: null, 
     propertyChanged: OnDatePropertyChanged); 

이제 대리자에서, 당신은 당신의 DatePickerEntryCell 요소를 나타내는 BindableObject에 액세스 할 수 있어야합니다. 또한 이전 값/새 값에 액세스 할 수 있습니다. 델리게이트에서 컨트롤을 가져 오는 방법은 다음과 같습니다.

public static void OnDatePropertyChanged(BindableObject bindable, object oldValue, object newValue) 
{ 
    var control = bindable as DatePickerEntryCell; 
    if (control != null){ 
     // do something with this control... 
    } 
} 

희망이 있습니다.

+0

고맙습니다. – user1667474

관련 문제