C# 背景色不与属性绑定
我无法将背景颜色绑定到位于代码隐藏中的属性 我的财产:C# 背景色不与属性绑定,c#,xamarin,xamarin.forms,xamarin.android,C#,Xamarin,Xamarin.forms,Xamarin.android,我无法将背景颜色绑定到位于代码隐藏中的属性 我的财产: public Color SelectedColor { get { return selectedColor; } set { pdfViewerControl.AnnotationSettings.FreeText.TextColor = value; selectedColo
public Color SelectedColor
{
get
{
return selectedColor;
}
set
{
pdfViewerControl.AnnotationSettings.FreeText.TextColor = value;
selectedColor = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged();
}
}
我的按钮:
Button colorButton = new Button();
colorButton.CornerRadius = 20;
colorButton.BorderWidth = 2;
colorButton.HeightRequest = 30;
colorButton.WidthRequest = 30;
colorButton.BindingContext = this;
colorButton.SetBinding(Button.BorderColorProperty, new Binding("Value", source: SelectedColor));
colorButton.SetBinding(Button.BackgroundColorProperty, new Binding("BackgroundColor", source: SelectedColor));
我尝试了不同的绑定上下文,但不起作用
代码的两部分在同一页上 如果属性名为
SelectedColor
,则在创建绑定时应将其用作绑定路径
colorButton.SetBinding(Button.BackgroundColorProperty, new Binding("SelectedColor"));
好吧,现在有道理了,我在读这篇文章时误解了这个概念:。非常感谢。