它似乎在綁定一些數據錯誤,有人可以幫助我,我哪裏出錯了,但我無法弄清楚。將SolidColorBrush綁定到背景,綁定錯誤
真的不需要在這裏顯示太多,這是Binding
,我已經通過刪除背景並在其中添加顏色來測試背景。
編輯:但與綁定沒有顏色被渲染!
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{Binding Color1}" />
</Setter.Value>
</Setter>
這是顏色設置類,我用的SolidColorBrush,因爲這是個什麼背景屬性需要:
public class notificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
private string _icon;
private string _message;
private string _detail;
private SolidColorBrush _color1;
private SolidColorBrush _color2;
public string Icon
{ get { return _icon; } set { _icon = value; OnPropertyChanged("Icon"); }}
public string Message
{ get { return _message; } set { _message = value; OnPropertyChanged("Message"); } }
public string Detail
{ get { return _detail; } set { _detail = value; OnPropertyChanged("Detail"); } }
public SolidColorBrush Color1
{ get { return _color1; } set { _color1 = value; OnPropertyChanged("Color1"); } }
public SolidColorBrush Color2
{ get { return _color2; } set { _color2 = value; OnPropertyChanged("Color2"); } }
public notificationObject newNotification(int type, string message, string detail)
{
//Create new instance of object
notificationObject x = new notificationObject();
switch (type)
{
case 1:
//Fatal
x.Icon = "";
x.Message = message;
x.Detail = detail;
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 170, 60, 18));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 238, 78, 16));
return x;
case 2:
//Fatal
x.Icon = "";
x.Message = message;
x.Detail = detail;
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 170, 60, 18));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 238, 78, 16));
return x;
case 3:
//Unauthorized
x.Icon = "";
x.Message = message;
x.Detail = detail;
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 170, 60, 18));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 238, 78, 16));
return x;
case 4:
//Warning
x.Icon = "";
x.Message = message;
x.Detail = detail;
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 241, 176, 24));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 205, 152, 28));
return x;
case 5:
//Warning
x.Icon = "";
x.Message = message;
x.Detail = detail;
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 41, 161, 213));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 36, 142, 184));
return x;
}
//Can't find error code
x.Icon = "";
x.Message = "Unable to find requested error code!";
x.Detail = "";
x.Color1 = new SolidColorBrush(Color.FromArgb(0, 170, 60, 18));
x.Color2 = new SolidColorBrush(Color.FromArgb(0, 238, 78, 16));
return x;
}
}
而且很明顯,我把我的DataContext這個類的實例,我有其他綁定我綁定到Message
屬性,這工作正常,所以我敢肯定這是與綁定的數據類型。
那麼,你會得到什麼錯誤? – torvin