I am making a WPF program by .net5 .
Here is my code:
public class ThemeBase:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string name)=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
SolidColorBrush _PrimaryBackground;
public SolidColorBrush PrimaryBackground
{
get => _PrimaryBackground;
set { _PrimaryBackground = value;OnPropertyChanged("PrimaryBackground"); }
}
Boolean _IsBlur;
public Boolean IsBlur
{
get => _IsBlur;
set {
//some logic
}
}
}
And here is a subclass that inherits from it.
public class NormalWhite:ThemeBase
{
public NormalWhite() {
PrimaryBackground = new SolidColorBrush(Colors.Red);
IsBlur=false;
}
}
Finally, I set a static variable in a class named Global.cs
:
public class Global
{
public static Themes.ThemeBase Theme=new NormalWhite();
}
Here is the code in XAML:
<Border Background="{Binding Source=x:Static local:Global.Theme,Path=PrimaryBackground}">
After the program ran, the Binding Failure reports this error:
Severity Count Data Context Binding Path Target Target Type Description File Line Project
Error 1 String PrimaryBackground Border.Background Brush PrimaryBackground property not found on object of type String. \MainPage.xaml 23 Sample
Why I can't bind it? Thank you.