简体   繁体   English

在Xamarin.Forms中绑定BarBackgroundColorProperty

[英]Binding BarBackgroundColorProperty in Xamarin.Forms

I'm relatively new to C# and the idea of data binding (that is, I'm not sure I completely understand it). 我对C#和数据绑定的想法还比较陌生(也就是说,我不确定我是否完全理解它)。 I am looking to try to bind NavigationPage's BarBackgroundColorProperty for sake of being able to change my root page's bar background color multiple times for a theme feature I'm trying to implement. 我希望尝试绑定NavigationPage的BarBackgroundColorProperty,以便能够针对我正在尝试实现的主题功能多次更改根页的栏背景颜色。 I've searched around for examples of binding this property and haven't had much luck. 我搜索了绑定该属性的示例,但运气不高。 Could someone point me in the right direction? 有人可以指出我正确的方向吗? If anything is unclear, please let me know. 如果有任何不清楚的地方,请告诉我。 Thanks guys! 多谢你们!

Assuming you have an instance of NavigationPage called myBindingPage and a view model that extends INotifyPropertyChanged called myViewModel that has a property called BarBgColor , you should be able to set up a binding like this: 假设你已经NavigationPage的一个实例调用myBindingPage和扩展视图模型INotifyPropertyChanged的所谓myViewModel有一个叫做财产BarBgColor ,你应该能够建立这样的结合:

myBindingPage.SetBinding(NavigationPage.BarBackgroundColorProperty, new Binding("BarBgColor"));

NB I haven't actually tried this, but the API doc does list BarBackgroundColor as a bindable property. 注意:我实际上没有尝试过,但是API文档确实将BarBackgroundColor列为可绑定的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM