Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

XLabs Binding

$
0
0

Hello,

I am using the XLabs library for forms and all look good. But I have a simple question.
If I have a simple binding from a string in the view model to a label and I set the view model string var to a text all looks good.
BUT if I set the view model var in a function that is called by a command from the XAML the binding did NOT work !!!???

XAML:

<Label Text="{Binding Data}"></Label>

ViewModel class:

using XLabs.Forms.Mvvm;
public class DataViewModel : ViewModel
    {
.....

Property:

private string data;
public string Data
{
    get
    {
        return data;
    }
    set
    {
        data = value;
        SetProperty(ref data, value);
    }
}
.....

Constructor:

public DataViewModel ()
 {  
        // this WORKS !!!       
    this.Data = "Hello";
 }

With command (the command itself successfully calls the update method):

private Command getDataCommand;
public Command GetDataCommand 
{
    get
    {
        return getDataCommand ?? (getDataCommand = new Command(async () => await GetData(),
                                                                    () => true)); 
    }
}

...

private async Task GetData()
{
  // does NOT work !!!!!
  this.Data = "Hello";
}

The IoC of XLabs are set, also the ViewFactory stuff:

ViewFactory.Register< DataViewModelPage, DataViewModel > ();
DataViewModelPage dataViewModelPage = (DataViewModelPage)ViewFactory.CreatePage< DataViewModel, DataViewModelPage> ();

Any idea why the binding works when the data is set inside the constructor, BUT NOT from a command ?

Thanx

Marco


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>