2017-03-25 2 views
0

Ich bin eine neue Xamarin Form. Ich habe ein einfaches Xamarin-Formular-Projekt mit mvvmcross (Hallo Welt sehr einfach für Anfang) erstellt, aber wenn ich Binding-Befehl implementiert, und nicht den Text der Beschriftung ändern. Mein Xaml-Code und ViewModel unten.Xamarin Forms + Mvvmcross Bindungsbefehl funktioniert nicht

<?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:vm="clr-namespace:MvvmCross.ViewModels;assembly=MvvmCross" 
     x:Class="MvvmCross.Views.HelloView"> 
<StackLayout> 
    <StackLayout.BindingContext> 
     <vm:HelloViewModel /> 
    </StackLayout.BindingContext> 
    <Entry HorizontalOptions="Fill" VerticalOptions="Center" Text="{Binding Name, Mode=TwoWay }"/> 
    <Button Text="Hello" HorizontalOptions="Center" VerticalOptions="Center" Command="{Binding HelloCommand}" /> 
    <Label HorizontalOptions="Fill" VerticalOptions="Center" FontSize="15" Text="{Binding Hello, Mode=TwoWay}" /> 
</StackLayout> 

using MvvmCross.Core.ViewModels; 
using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Input; 

namespace MvvmCross.ViewModels 
{ 
    public class HelloViewModel: Core.ViewModels.MvxViewModel 
    { 
    private string _name; 
    public HelloViewModel() 
    { 
     Hello = "Your name"; 
    } 
    public string Name 
    { 
     get { return _name; } 
     set { _name = value; RaisePropertyChanged(() => Name); } 
    } 
    private string _hello; 

    public string Hello 
    { 
     get { return _hello; } 
     set { _hello = value; RaisePropertyChanged(() => Hello); } 
    } 

    private ICommand _helloCommand; 

    public ICommand HelloCommand 
    { 
     get { _helloCommand = _helloCommand ?? new MvxCommand(ShowHello); return _helloCommand; } 
    } 

    private void ShowHello() 
    { 
     // not change label text so sadly 
     Hello = Name.ToString(); 
     Debug.WriteLine(Hello); 
    } 
} 

}

Dank für alle

+0

Funktionieren die Texteigenschaften zu geben? Oder ist es nur der Befehl, der fehlschlägt? – Cheesebaron

+0

Text Eigenschaften funktionieren, aber in ui beim Ausführen nicht funktionieren. – kevindang

+0

Mir scheint, dass der BindingContext dann nicht korrekt ist. – Cheesebaron

Antwort

-1

helfen gesetzt u die Binding?

In Ihrem HelloView.xaml.cs:

public HelloView() { 
    BindingContext = new HelloViewModel(); 
} 

ich auf mobilen bin, wirklich hart ..

+0

Ich glaube, ich habe mit Xaml-Code festgelegt – kevindang

Verwandte Themen