【发布时间】:2016-02-15 17:54:40
【问题描述】:
我试图通过下面的代码控制背景颜色,但颜色并没有像我想要的那样变黑。
我在我的列表中将我的公共颜色加载为透明,当它发现我想让它变黑但它似乎不起作用时。有什么线索我哪里出错了吗?
XAML:
<Label BackgroundColor="{Binding thebackgroundColor}" />
代码:
public class pubClass
{
public Color thebackgroundColor { get; set; }
}
async void loadOurItem ()
{
ourList.Add (new pubClass ()
{
thebackgroundColor = Color.Transparent
});
}
protected override void OnAppearing()
{
loadOurItem ();
var theClass = new pubClass ();
if (theClass.thebackgroundColor != null) {
theClass.thebackgroundColor = Color.Black;
}
}
}
更新:
private void NotifyPropertyChanged(theClass.thebackgroundColor)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(theClass.thebackgroundColor = Color.Black));
}
}
【问题讨论】:
-
pubClass 需要实现 INotifyPropertyChanged
-
检查我更新的代码,类似的东西?并将其从 OnAppearing 中删除?
-
还有更多。见developer.xamarin.com/guides/xamarin-forms/user-interface/…。此外,您发布的代码未显示您为页面设置 BindingContext 的位置。最后,您似乎从多个文件中发布了 sn-ps,这使您的代码难以阅读。请清楚说明每段代码的来源。
标签: c# xamarin xamarin.forms