Xamarin Forms data binding from xaml












1















I have an <Entry> in xaml, and I want to get that value the user types.



<Entry x:name="enteredInput>


The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.



Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.










share|improve this question

























  • in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

    – Jason
    Nov 28 '18 at 4:04
















1















I have an <Entry> in xaml, and I want to get that value the user types.



<Entry x:name="enteredInput>


The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.



Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.










share|improve this question

























  • in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

    – Jason
    Nov 28 '18 at 4:04














1












1








1








I have an <Entry> in xaml, and I want to get that value the user types.



<Entry x:name="enteredInput>


The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.



Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.










share|improve this question
















I have an <Entry> in xaml, and I want to get that value the user types.



<Entry x:name="enteredInput>


The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.



Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.







xamarin.forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 6:24









Himanshu Dwivedi

3,88731633




3,88731633










asked Nov 28 '18 at 4:02









Jordan DeVaneyJordan DeVaney

82




82













  • in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

    – Jason
    Nov 28 '18 at 4:04



















  • in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

    – Jason
    Nov 28 '18 at 4:04

















in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

– Jason
Nov 28 '18 at 4:04





in your code behind, just pass the value of enteredInput.Text to your 2nd page and assign it to a Label

– Jason
Nov 28 '18 at 4:04












1 Answer
1






active

oldest

votes


















4














In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.



public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}


From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,



Navigation.PushAsync(new MainPage(enteredInput.Text);





share|improve this answer
























  • Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

    – Jordan DeVaney
    Nov 28 '18 at 6:05











  • One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

    – Abdul Gani
    Nov 28 '18 at 6:11











  • public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

    – Abdul Gani
    Nov 28 '18 at 6:12













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511933%2fxamarin-forms-data-binding-from-xaml%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.



public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}


From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,



Navigation.PushAsync(new MainPage(enteredInput.Text);





share|improve this answer
























  • Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

    – Jordan DeVaney
    Nov 28 '18 at 6:05











  • One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

    – Abdul Gani
    Nov 28 '18 at 6:11











  • public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

    – Abdul Gani
    Nov 28 '18 at 6:12


















4














In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.



public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}


From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,



Navigation.PushAsync(new MainPage(enteredInput.Text);





share|improve this answer
























  • Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

    – Jordan DeVaney
    Nov 28 '18 at 6:05











  • One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

    – Abdul Gani
    Nov 28 '18 at 6:11











  • public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

    – Abdul Gani
    Nov 28 '18 at 6:12
















4












4








4







In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.



public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}


From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,



Navigation.PushAsync(new MainPage(enteredInput.Text);





share|improve this answer













In your second page, add another constructor with string parameter.
For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.



public StartingPage(string entryTextFromStartingPage)
{
InitializeComponent();
lblEntryTextDisplay.Text = entryTextFromStartingPage;
}


From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,



Navigation.PushAsync(new MainPage(enteredInput.Text);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 4:48









Abdul GaniAbdul Gani

42416




42416













  • Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

    – Jordan DeVaney
    Nov 28 '18 at 6:05











  • One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

    – Abdul Gani
    Nov 28 '18 at 6:11











  • public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

    – Abdul Gani
    Nov 28 '18 at 6:12





















  • Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

    – Jordan DeVaney
    Nov 28 '18 at 6:05











  • One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

    – Abdul Gani
    Nov 28 '18 at 6:11











  • public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

    – Abdul Gani
    Nov 28 '18 at 6:12



















Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

– Jordan DeVaney
Nov 28 '18 at 6:05





Thank you this works. It's one of those this that makes you go duh...I should of though about overloading the constructor. Do you think it would be more maintainable using the binding class, if you were to bind more values?

– Jordan DeVaney
Nov 28 '18 at 6:05













One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

– Abdul Gani
Nov 28 '18 at 6:11





One more alternative is using Singleton pattern for assigning and accessing global variables. You can access in code behind as well as viewmodel classes. But you have to clear them once you have used it. Sample below,

– Abdul Gani
Nov 28 '18 at 6:11













public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

– Abdul Gani
Nov 28 '18 at 6:12







public sealed class SingletonGlobal { private static SingletonGlobal instance = null; private static readonly object padlock = new object(); public static SingletonGlobal Instance { get { lock (padlock) { if (instance == null) { instance = new ApplicationCache(); } return instance; } } } public string FirstName { get; set; } }

– Abdul Gani
Nov 28 '18 at 6:12






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511933%2fxamarin-forms-data-binding-from-xaml%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks