I have implement these codes, but this seems doesn't work when I tried to change the variable (TitleBarHeight) value. Please check:
Variables.cs:
namespace MyApp.Classes
{
public class Variables : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private static double _TitleBarHeight = 40;
public static double TitleBarHeight
{
get { return _TitleBarHeight; }
set
{
_TitleBarHeight = value;
PropertyChanged(); //this line can't be added because it's non-static.
}
}
}
}
MainPage.cs:
...
Classes.Variables.TitleBarHeight = coreTitleBar.Height;
...
MainPage.xaml:
<Page
x:Class="MyApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:var="using:MyApp.Classes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBlock Text="{x:Bind var:Variables.TitleBarHeight, Mode=OneWay}"/>
</Grid>
</Page>
In this case, I need to use static variable. Are there any mistakes?