Hi,
I want to set a string in another class say App.Xaml.cs
public string MyValue = "somevalue";
How can i bind the text of a label to that MyValue item? I'm not sure how the Databinding source works or how I need to wire it up.
I've tried this which didnt work...
<Label Text = {Binding MyValue, Source={x:Static local:App.MyValue}} />
I've got a static piece of text that I want to display on multiple pages so thought to put it in one place and then try and bind to that so that when I need to change it i can change it in one place.
First , we need to make MyValue
to be static
in App .
public static string MyValue = "somevalue";
Then modify the binding in xaml
<Label Text ="{x:Static local:App.MyValue}" />
Refer to
Answers
I would define it as a resource in your App.xaml file and use it via the StaticResource markup extension.
First , we need to make
MyValue
to bestatic
in App .Then modify the binding in xaml
Refer to
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/xaml-markup-extensions#the-xstatic-markup-extension
perfect - thanks!