【发布时间】:2021-03-05 04:40:05
【问题描述】:
我正在通过 .net5 制作 WPF 程序。
这是我的代码:
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
}
}
}
这是一个继承自它的子类。
public class NormalWhite:ThemeBase
{
public NormalWhite() {
PrimaryBackground = new SolidColorBrush(Colors.Red);
IsBlur=false;
}
}
最后,我在一个名为Global.cs的类中设置了一个静态变量:
public class Global
{
public static Themes.ThemeBase Theme=new NormalWhite();
}
这是 XAML 中的代码:
<Border Background="{Binding Source=x:Static local:Global.Theme,Path=PrimaryBackground}">
程序运行后,Binding Failure报此错误:
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
为什么我不能绑定它?谢谢。
【问题讨论】: