2017-07-21 16 views
0

私たちのシステムにはBindablePropertiesがいくつかあります。彼らは主に仕事をしていますが、私は以前この問題に遭遇していません。私はUWPでテストしていますが、他のプラットフォームでも問題はおそらく同じです。Xamarinフォーム - BindablePropertyが動作しない

あなたは私が話している正確に何を見るためにここにこのコードをダウンロード見ることができる程度 ここhttps://[email protected]/ChristianFindlay/xamarin-forms-scratch.git

である私のコード:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:local="clr-namespace:TestXamarinForms" 
      x:Class="TestXamarinForms.BindablePropertyPage"> 
    <ContentPage.Content> 
     <StackLayout> 
      <local:ExtendedEntry Test="1" /> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

I:これはXAMLで

public class ExtendedEntry : Entry 
{ 
    public static readonly BindableProperty TestProperty = 
     BindableProperty.Create<ExtendedEntry, int> 
     (
     p => p.Test, 
     0, 
     BindingMode.TwoWay, 
     propertyChanging: TestChanging 
    ); 

    public int Test 
    { 
     get 
     { 
      return (int)GetValue(TestProperty); 
     } 
     set 
     { 
      SetValue(TestProperty, value); 
     } 
    } 

    private static void TestChanging(BindableObject bindable, int oldValue, int newValue) 
    { 
     var ctrl = (ExtendedEntry)bindable; 
     ctrl.Test = newValue; 
    } 
} 

Testのセッターで1がSetValueに渡されていることが分かります。しかし、次の行では、ウォッチウィンドウのプロパティのGetValueと値0を調べます.BindablePropertyは固定されていません。いくつかの異なるCreateオーバーロードでBindingPropertyをインスタンス化しようとしましたが、何も動作しないようです。私は間違って何をしていますか?

答えて

0

あなたが使用しているBindableProperty.Createのメソッドは廃止されましたので、変更することをお勧めします。また、おそらくpropertyChanging:の代わりにpropertyChanged:を使用しているはずです。たとえば、

public static readonly BindableProperty TestProperty = BindableProperty.Create(nameof(Test), typeof(int), typeof(ExtendedEntry), 0, BindingMode.TwoWay, propertyChanged: TestChanging); 

public int Test 
{ 
    get { return (int)GetValue(TestProperty); } 
    set { SetValue(TestProperty, value); } 
} 

private static void TestChanging(BindableObject bindable, object oldValue, object newValue) 
{ 
    var ctrl = (ExtendedEntry)bindable; 
    ctrl.Test = (int)newValue; 
} 
関連する問題