2017-06-01 10 views
0

これはアプリケーションの例です。エントリとラベルを持ち、エントリ番号を書き、ラベルに同じ番号を書き込みます。ModelView xamarinを作成する

私はMVMSモデルを推奨しますが、私は何をする必要があるのか​​分かりません。

ModelViewを作成することはわかりません。私のコードで

私が持っている:

モデルペルソナ、atributeのint型の年齢whith人である; `名前空間HolaMVVM.Models { クラスペルソナ { プライベートint型_edad。

public Persona() 
    { 
     _edad = 0; 
    } 
    public int Edad 
    { 
     get { return _edad; } 
     set 
     { 
      _edad = value; 
     } 
    } 
} 

ビューMainView.xaml

<StackLayout> 
    <Entry 
     Text="{Binding Edad, Mode=TwoWay}" 
     VerticalOptions="Center" 
     HorizontalOptions="Center"/> 
    <Label Text="{Binding Edad}" 
     VerticalOptions="Center" 
     HorizontalOptions="Center" /> 
</StackLayout> 

とMainView.xaml.cs

public partial class MainView : ContentPage 
{ 
    public MainView() 
    { 
     InitializeComponent(); 
     BindingContext = new MainViewModel(); 
    } 
} 

しかし、私が見るに結合する人のatributesを知らない

class MainViewModel : BindableObject 
{ 
    private Persona persona; 

    public MainViewModel() 
    { 
     persona = new Persona(); 
    } 
} 

TANK君は!!!

答えて

1

私はIntroduction to MVVM

に見てみるとPropertyChanged.Fody

あなたのペルソナを使用するように示唆してあなたのViewModelに(Fodyと...)INotifyPropertyChangedの

を実装する必要がありますが、 "public Persona persona {get;set;}"

を持っている必要があります

あなたのXAMLには、{Binding persona.Edad}

のようなものをバインドできます

これらは「基本」です。その後、@ jamesmontemagnoビデオをご覧ください。

関連する問題