2012-05-08 7 views
5

私はアンドロイドでそれを開始するクロスプラットフォームのアプリケーションを開発しています。私はあなたのMVVMCrossプロジェクトを見つけました。私はそれに取り込もうとしています。今、私は全く新しいので、WebService-ResultsをListViewにバインドする方法がわかりません。 私はそれをしようとしている方法の例として、XAMLのここで少しは:私はツールチップが属性が宣言されていないと言う最後の2行をホバリングしていた場合AndroidでのMVVMCrossのバインディング

xmlns:mobsales="http://schemas.android.com/apk/res/MobSales.DroidUI" 
... 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="5dp" 
mobsales:MvxItemTemplate="@layout/listitem_customer" 
mobsales:MvxBind="{'ItemSource':{'Path':'Customer'}}" /> 
... 

まさにこの

<cirrious.mvvmcross.binding.android.views.MvxBindableListView 
     android:id="@+id/autocomplete" 
     android:layout_below="@id/txtfield" 
     android:layout_centerHorizontal="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     mobsales:MvxItemTemplate="@layout/listitem_customer" 
     mobsales:MvxBind="{'ItemSource':{'Path':'Customers'}}" /> 

のように見えます。私は本当にあなたがどのようにこれを行うか分からない。アドバイスをいただけますか?私は私のUIプロジェクトの値、いくつかのXMLを書く必要があると思いますよね?

別の質問:AutoCompleteTextViewsはどのように使用できますか?最初に私自身のMvXBindablesを書く必要がありますか?何かアドバイス? :-)

+0

質問ごとに質問してください - これはに役立ちます他の人のための問題と答えを探し出す。 – Stuart

+1

私は質問を分割しました。新しい部分はすでにそこにありますhttp://stackoverflow.com/questions/10511853/constructor-in-viewmodel – Martin

答えて

5

これらの属性をバインドするには、実行したように見える名前空間を含める必要があります。 https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross.Binding/ResourcesToCopy/MvxBindingAttributes.xml - -

はまた、あなたのUIプロジェクトにMvxBindingAttributes.xmlファイルをインクルードする必要があり、あなたは、たとえば、このファイルに「AndroidResource」

のビルドアクションを設定するAndroidのサンプルプロジェクトのいずれかを見なければなりません - 追加バインディングに関するご質問の後半部分についてhttps://github.com/slodge/MvvmCross


、バインディング・フレームワークは自動的に一方向のバインド任意のMonodroidビュー/ウィジェット上の既存のパブリックプロパティに(ViewModelにからは表示する)をする必要があります。

Publicプロパティのタイプが正しくない場合(たとえば、ビューではなくAndroidの列挙型など)、IMvxValueConverterを使用して変換を行うことができます。

2ウェイバインディングを行いたい場合、またはバインドしたいもののpublicプロパティがない場合は、カスタムバインディングを簡単に実行できます。この例では、カスタムIsFavorite 2ウェイバインドを参照してくださいthe conference sample

このコードは、すべてのAndroidボタンに新しいバインド可能な擬似プロパティ "IsFavorite"を追加します。

...これはのようなコードを使用してSetup.csに初期化される:

protected override void FillTargetFactories(MvvmCross.Binding.Interfaces.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry) 
    { 
     base.FillTargetFactories(registry); 

     registry.RegisterFactory(
        new MvxCustomBindingFactory<Button>(
         "IsFavorite", 
         (button) => new FavoritesButtonBinding(button))); 
    } 

...とバインディングコードは次のとおりです。

public class FavoritesButtonBinding 
    : MvxBaseAndroidTargetBinding 
{ 
    private readonly Button _button; 
    private bool _currentValue; 

    public FavoritesButtonBinding(Button button) 
    { 
     _button = button; 
     _button.Click += ButtonOnClick; 
    } 

    private void ButtonOnClick(object sender, EventArgs eventArgs) 
    { 
     _currentValue = !_currentValue; 
     SetButtonBackground(); 
     FireValueChanged(_currentValue); 
    } 

    public override void SetValue(object value) 
    { 
     var boolValue = (bool)value; 
     _currentValue = boolValue; 
     SetButtonBackground(); 
    } 

    private void SetButtonBackground() 
    { 
     if (_currentValue) 
     { 
      _button.SetBackgroundResource(Resource.Drawable.star_gold_selector); 
     } 
     else 
     { 
      _button.SetBackgroundResource(Resource.Drawable.star_grey_selector); 
     } 
    } 

    protected override void Dispose(bool isDisposing) 
    { 
     if (isDisposing) 
     { 
      _button.Click -= ButtonOnClick; 
     } 
     base.Dispose(isDisposing); 
    } 

    public override Type TargetType 
    { 
     get { return typeof(bool); } 
    } 

    public override MvxBindingMode DefaultMode 
    { 
     get { return MvxBindingMode.TwoWay; } 
    } 
} 
+0

この返答いただきありがとうございます!あなたは私をたくさん助けました! – Martin

+0

クール - これ以上またはhttp://jabbr.net/#/rooms/mvvmcrossで質問してください:) – Stuart

関連する問題