[英]How to bind SwitchCell text color to view model in Xamarin.Forms
我試圖將SwitchCell文本顏色綁定到視圖模型,但SwitchCell.TextColor可綁定屬性不存在。 如何綁定switchCell的文本顏色?
有一些代碼:
var channelStatusSwitch = new SwitchCell {Text = AppResources.ChannelStatusSwitchText};
channelStatusSwitch.SetBinding(SwitchCell.OnProperty, new Binding("IsChannelRunning", BindingMode.TwoWay));
channelStatusSwitch.SetBinding(/*text color poperty*/, new Binding("IsChannelRunning", BindingMode.OneWay,new BoolToColorConverter()));
SwitchCell僅公開2個可綁定屬性On和Text 。 如果需要文本顏色屬性,則需要創建自定義控件。
SwitchCell是一個帶有標簽和開/關開關的Cell 。
你去,你可以在你的共享或PCL項目中創建一個自定義控件,你不需要平台特定的自定義渲染來實現它。
你可以在XAML本身或后面的代碼中創建一個從Cell繼承的CustomSwitchCell並添加一個Label和Switch。 然后公開TextColor屬性並使用它來設置Label的字體顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.