2

Xamarin Forms フレームワークを使用してモバイル アプリケーションを開発しています (現時点では Android のみを対象としています)。MVVMLight ツールキットを使用して、MVVM パターンを利用するようにアプリケーションを構築しました。データ管理には BreezeSharp を使用しています (Web クライアント用に実装された Breeze フレンドリー サーバーが既にあるため)。

私たちが対処している問題は、Breeze エンティティのプロパティにバインドされている Xamarin Forms Entry コントロールに入力すると、アプリケーションがクラッシュすることです。

Xaml ビューでのエントリ コントロール:

<Entry Text="{Binding SelectedCustomerAddress.AddressLine1}" />

ViewModel のプロパティ (Set() は MVVMLight ViewModelBase から取得):

public CustomerAddress SelectedCustomerAddress
{
    get { return this.selectedCustomerAddress; }
    set { this.Set(() => this.SelectedCustomerAddress, ref this.selectedCustomerAddress, value);}
}

Breeze CLR タイプのプロパティ:

public string AddressLine1
{
    get { return this.GetValue<string>(); }
    set { this.SetValue(value); }
}

入力フィールドに数文字しか入力しないと、アプリケーションがスタック トレースでクラッシュします。

11-10 11:51:02.896 F/        ( 4924): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/mono/mono/metadata/sgen-stw.c:68, condition `info->stack_start >= info->stack_start_limit && info->stack_start < info->stack_end' not met
11-10 11:51:02.900 E/mono-rt ( 4924): Stacktrace:
11-10 11:51:02.900 E/mono-rt ( 4924): 
11-10 11:51:02.904 E/mono-rt ( 4924):   at <unknown> <0xffffffff>
11-10 11:51:02.908 E/mono-rt ( 4924):   at (wrapper managed-to-native) object.MemberwiseClone (object) <IL 0x0002d, 0xffffffff>
11-10 11:51:02.912 E/mono-rt ( 4924):   at System.Delegate.Clone () <IL 0x00001, 0x00027>
11-10 11:51:02.916 E/mono-rt ( 4924):   at System.MulticastDelegate.CombineImpl (System.Delegate) <IL 0x000be, 0x0037c>
11-10 11:51:02.916 E/mono-rt ( 4924):   at System.Delegate.Combine (System.Delegate,System.Delegate) <IL 0x00062, 0x001f8>
11-10 11:51:02.920 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.add_EntityPropertyChanged (System.ComponentModel.PropertyChangedEventHandler) <IL 0x0000b, 0x00057>
11-10 11:51:02.924 E/mono-rt ( 4924):   at Breeze.Sharp.BaseEntity.System.ComponentModel.INotifyPropertyChanged.add_PropertyChanged (System.ComponentModel.PropertyChangedEventHandler) [0x00000] in c:\GitHub\breeze.sharp\Breeze.Sharp\BaseEntity.cs:74
11-10 11:51:02.928 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00130, 0x0077f>
11-10 11:51:02.928 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x000f3>
11-10 11:51:02.932 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression/BindingExpressionPart.<PropertyChanged>b__12 () <IL 0x00007, 0x0002f>
11-10 11:51:02.932 E/mono-rt ( 4924):   at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
11-10 11:51:02.932 E/mono-rt ( 4924):   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-18/src/generated/Java.Lang.IRunnable.cs:71
11-10 11:51:02.932 E/mono-rt ( 4924):   at (wrapper dynamic-method) object.39beb2b5-65b4-431f-a21a-3e626049fa1f (intptr,intptr) <IL 0x00011, 0x0001b>
11-10 11:51:02.932 E/mono-rt ( 4924):   at (wrapper native-to-managed) object.39beb2b5-65b4-431f-a21a-3e626049fa1f (intptr,intptr) <IL 0x00022, 0xffffffff>
11-10 11:51:02.936 E/mono-rt ( 4924):   at <unknown> <0xffffffff>
11-10 11:51:02.936 E/mono-rt ( 4924):   at (wrapper managed-to-native) object.wrapper_native_0xb60a0eb0 (intptr,intptr,intptr,Android.Runtime.JValue[]) <IL 0x00120, 0xffffffff>
11-10 11:51:02.936 E/mono-rt ( 4924):   at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00040] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:504
11-10 11:51:02.940 E/mono-rt ( 4924):   at Android.App.Activity.RunOnUiThread (Java.Lang.IRunnable) [0x0002d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-18/src/generated/Android.App.Activity.cs:4130
11-10 11:51:02.940 E/mono-rt ( 4924):   at Android.App.Activity.RunOnUiThread (System.Action) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Android.App/Activity.cs:23
11-10 11:51:02.940 E/mono-rt ( 4924):   at Xamarin.Forms.Forms/AndroidPlatformServices.BeginInvokeOnMainThread (System.Action) <IL 0x0000b, 0x00053>
11-10 11:51:02.940 E/mono-rt ( 4924):   at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action) <IL 0x00006, 0x00038>
11-10 11:51:02.940 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression/BindingExpressionPart.PropertyChanged (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00087, 0x00313>
11-10 11:51:02.944 E/mono-rt ( 4924):   at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00027, 0x00042>
11-10 11:51:02.944 E/mono-rt ( 4924):   at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00027, 0x00042>
11-10 11:51:02.944 E/mono-rt ( 4924):   at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00027, 0x00042>

..... (2500 lines)

11-10 11:51:03.564 E/mono-rt ( 4924):   at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00059, 0xffffffff>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.OnPropertyChangedCore (System.ComponentModel.PropertyChangedEventArgs) [0x0000b] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:1315
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect/<>c__DisplayClass4b.<OnPropertyChanged>b__4a () [0x00000] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:1306
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.QueueEvent (System.Action) [0x0003e] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:1362
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.OnPropertyChanged (System.ComponentModel.PropertyChangedEventArgs) [0x0003f] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:1305
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.SetValueWithEvents<T> (T,object,System.Action`3<T, object, object>) [0x00042] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:563
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.SetDpValue (Breeze.Sharp.DataProperty,object) [0x00000] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:529
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.SetValue (Breeze.Sharp.StructuralProperty,object) [0x00052] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:522
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.EntityAspect.SetValue (string,object) [0x00031] in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityAspect.cs:507
11-10 11:51:03.564 E/mono-rt ( 4924):   at Breeze.Sharp.BaseEntity.SetValue (object,string) [0x00000] in c:\GitHub\breeze.sharp\Breeze.Sharp\BaseEntity.cs:37
11-10 11:51:03.564 E/mono-rt ( 4924):   at Client.Common.Model.Proxy.CustomerAddress.set_AddressLine2 (string) [0x00001] in c:\Projects\Client\source\Client.Common\Model\Proxy\CustomerAddress.cs:26
11-10 11:51:03.564 E/mono-rt ( 4924):   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 0xffffffff>
11-10 11:51:03.564 E/mono-rt ( 4924):   at <unknown> <0xffffffff>
11-10 11:51:03.564 E/mono-rt ( 4924):   at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <IL 0x00030, 0xffffffff>
11-10 11:51:03.564 E/mono-rt ( 4924):   at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x0004a, 0x0016f>
11-10 11:51:03.564 E/mono-rt ( 4924):   at System.Reflection.MethodBase.Invoke (object,object[]) <IL 0x00006, 0x0004b>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x002f4, 0x00fd3>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x000f3>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.Binding.Apply (bool) <IL 0x00027, 0x000db>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x00090, 0x00295>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x00213, 0x007b7>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Xamarin.Forms.Platform.Android.EntryRenderer.Android.Text.ITextWatcher.OnTextChanged (Java.Lang.ICharSequence,int,int,int) <IL 0x00014, 0x00087>
11-10 11:51:03.564 E/mono-rt ( 4924):   at Android.Text.ITextWatcherInvoker.n_OnTextChanged_Ljava_lang_CharSequence_III (intptr,intptr,intptr,int,int,int) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-18/src/generated/Android.Text.ITextWatcher.cs:149
11-10 11:51:03.564 E/mono-rt ( 4924):   at (wrapper dynamic-method) object.369fe85e-8bc0-4aec-88da-b1540ec93f9c (intptr,intptr,intptr,int,int,int) <IL 0x00029, 0x0003f>
11-10 11:51:03.564 E/mono-rt ( 4924):   at (wrapper native-to-managed) object.369fe85e-8bc0-4aec-88da-b1540ec93f9c (intptr,intptr,intptr,int,int,int) <IL 0x00028, 0xffffffff>
11-10 11:51:03.564 E/mono-rt ( 4924): 
11-10 11:51:03.564 E/mono-rt ( 4924): =================================================================
11-10 11:51:03.564 E/mono-rt ( 4924): Got a SIGSEGV while executing native code. This usually indicates
11-10 11:51:03.564 E/mono-rt ( 4924): a fatal error in the mono runtime or one of the native libraries 
11-10 11:51:03.564 E/mono-rt ( 4924): used by your application.
11-10 11:51:03.564 E/mono-rt ( 4924): =================================================================
11-10 11:51:03.564 E/mono-rt ( 4924): 
11-10 11:51:03.564 F/libc    ( 4924): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 4924 (r.nimbus.mobile)
The program 'Mono' has exited with code 0 (0x0).

私には多くのイベントが発生し、イベント スタックがオーバーフローするように見えます。

非 Breeze プロパティにバインドされている場合、エントリは正常に機能します。切り離されたエンティティにバインドされている場合も正常に機能しています。

Breeze EntityAspect.cs コードを掘り下げた後、すべてがこの関数に来ることがわかりました。

internal void OnPropertyChanged(PropertyChangedEventArgs pcArgs)
    {
      if (this.IsDetached || !this.EntityGroup.ChangeNotificationEnabled)
        return;
      pcArgs = pcArgs ?? EntityAspect.AllPropertiesChangedEventArgs;
      this.QueueEvent((Action) (() =>
      {
        this.OnPropertyChangedCore(pcArgs);
        this.OnEntityChangedCore(EntityAction.PropertyChange, (EventArgs) pcArgs);
      }));
    }

そこで、以下を使用して Breeze でのイベントの発生を無効にしました。

this.EntityManager.ChangeNotificationEnabled = false;

これにより、エントリのバインドに関する問題が解決されたようですが、これが他の問題への扉を開くかどうかはわかりません。

このアプローチの結果は何ですか?

これらの EntityPropertyChanged および PropertyChanged イベントは、Breeze コードで使用されていますか、それとも私たちのコードがそれらにアタッチするためだけに意図されていますか?

または、この問題に対する他のアプローチがありますか?

UPDATE : 結果は次のとおりです。UI に複数の要素が同じプロパティにバインドされている場合、そのプロパティを 1 つの場所で更新すると、他の場所では変更が表示されません。

例: ListView から要素を選択し、選択した要素をいくつかの入力フィールド (ListView の外部) にバインドします。その入力フィールドを介して要素を更新すると、変更は ListView に表示されません (ListView には通知されないため)。

Breeze PropertyChanged メカニズム (EntityPropertyChanged および ForceEntityPropertyChanged) を有効にすると、これはそのまま使用できますが、前述のように、アプリケーションのクラッシュに問題があります。

基本エンティティ (Breeze BaseEntity から継承したもの) に OnPropertyChanged メソッドと RaisePropertyChanged メソッドを実装することになりました。この手法は、ObservableObject の MVVMLight 実装に似ています。

このコードは正常に動作します (アプリケーションがクラッシュすることはありません):

public bool IsImportant
{
    get { return this.GetValue<bool>(); }
    set
    {
        this.SetValue(value); 
        this.OnPropertyChanged();
    }
}

また、必要なときはいつでも RaisePropertyChanged を呼び出すことができます。

this.SelectedNote.RaisePropertyChanged("IsImportant");
4

2 に答える 2

0

文字を変更するたびにではなく、ユーザーがテキストの編集を終了した後にのみバインディングを起動するように変更する方法があると思います。アプリケーションで達成しようとしていることは、それで十分でしょうか? WPF/Silverlight XAML には、バインディングに UpdateSourceTrigger というプロパティがあり、変更がプッシュされるポイントを指示するように設定できます。Xamarin に連絡して、同等のプロパティがあるかどうかを確認中です。

于 2014-11-18T18:31:10.937 に答える