Data Binding to Return Value in Method

I am new to Xamarin, though I couldn't really figure out the following, perhaps someone can point me to the right direction, but what I am trying to accomplish is to bind the Text value of an Editor tag in XAML to the return value of a Method, so for instance:

inside of DisplayStuff.xaml

    <ScrollView x:Name="scroll">
            Text="{Binding ***NOT SURE ABOUT THIS PART***}"
            x:Name="editText" />

inside of DisplayStuff.xaml.cs

    public string generateStuff()
        return "Hello Test...";

Best Answer


  • rslneorslneo USMember

    Also wondering if there's a way for the Binding in Editor to keep updated with what gets generated in the generateStuff() method, I just have a hello test in there at the moment.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    bind the Text value of an Editor tag in XAML to the return value of a Method

    Doesn't work that way. You bind to properties. Period.

    So you could set a property to the return of the method:
    MyBindedProperty = SomeMethod();

    When the property updates, the UI will update.

  • rslneorslneo USMember

    Ok, that is definitely good to know, I wasn't going about it the right way. Is there a tutorial or reference you could point me to that demonstrates this? It sounds simple, but I am not sure what to do with it in terms of the namespaces in XAML, etc.

  • rslneorslneo USMember

    I learned a lot from the following two videos, the two links pointing to Xamarin docs are very informative but I needed some examples.

    Both on Youtube (Won't allow me to post links yet):

    The Xamarin Show 5 MVVM & Data Binding with Xamarin Forms

    Xamarin Forms Tutorial - Data Binding

Sign In or Register to comment.