Let’s say that I have a global variable defined in App.xaml.cs as follows:
public static MyClass GlobalInstance = new MyClass()
And then in MainPage.xaml I would like to bind to a property of this class like follows:
<TextBlock Text="{Binding App.GlobalInstance.Property1}" VerticalAlignment="Top" Height="31" HorizontalAlignment="Left" Width="80">
Is there something I am missing here? For some reason it does not appear to be properly bound.
Any advice here would be greatly appreciated.
Thanks!
You need to assign your App to DataContext of the page
First way is do this in page constructor:
And your binding will be
The second way is to make a reference to App class in page resources
Also, edit your field implementation to something like this: