使用最新版本创建BindableProperty(不折旧)

时间:2016-05-27 15:05:14

标签: c# xamarin xamarin.forms

我想更新我的折旧代码,这里是:

public static readonly BindableProperty CompletedProperty = BindableProperty.CreateAttached<EntryCompletedBehavior, Command>(
               bindable => EntryCompletedBehavior.GetCompleted(bindable), /* staticgetter */
               null, /* default value */
               BindingMode.OneWay, /* defaultBindingMode */
               null, /* validateValue */
               (b, o, n) => EntryCompletedBehavior.OnCompletedChanged(b, o, n), /* PropertyChanged */
               null, /* PropertyChanging */
               null); /* CoerceValue */

但我不确定在PropertyName,returnType,declaringType和PropertyChanged中放入什么。我在这里找到了这段代码http://pause.coffee/blog/...,目前以下代码的工作原理是:

public static readonly BindableProperty CompletedProperty = BindableProperty.CreateAttached(
               "Completed", /* string PropertyName */
               typeof(Command), /* Type returnType */
               typeof(Command), /* Type declaringType */

               null, /* default value */
               BindingMode.OneWay,
               null,
               (b, o, n) => EntryCompletedBehavior.OnCompletedChanged(b, o, n),
               null,
               null);

2 个答案:

答案 0 :(得分:1)

感谢Bill Reiss; - )

以下代码正在运行:

public static readonly BindableProperty CompletedProperty = BindableProperty.CreateAttached(
                "Completed", /* string PropertyName */
                typeof(Command), /* Type returnType */
                typeof(Entry), /* Type declaringType */
                null, /* default value */
                BindingMode.OneWay, /* defaultBindingMode */
                propertyChanged: (bindable, oldValue, newValue) => {
                    EntryCompletedBehavior.OnCompletedChanged(bindable, (Command)oldValue, (Command)newValue);
                });

答案 1 :(得分:0)

这是一个GitHub链接,指向Charles Petzold更新他的样本以使用非泛型BindableProperty,如果你看它之前和之后应该帮助你。

https://github.com/xamarin/xamarin-forms-book-preview-2/commit/1786d2062eeee856b6031a0e48378d58b7c9e222