簡體   English   中英

Xamarin形成帶有ListView和復選框的Labs綁定問題

[英]xamarin forms labs binding issue with listview and checkbox

我在使用xamarin表單實驗室( Xamarin-forms-labs )復選框控件時遇到綁定問題。 我有一個listview指向一個聯系人數據源(這是一個可觀察的集合)。 在列表視圖中,我有一個自定義視圖單元格“ InviteItemCell”(請參見下面的代碼)。

綁定似乎不能同時起作用,即,在讀取數據源並指示選擇了哪些聯系人時,它可以正確綁定,但是,通過通過UI選中復選框來選擇聯系人時,底層的聯系人對象屬性不會更改。

這是列表視圖的定義:

var stack = new StackLayout ();
list.ItemsSource = App.Service.Contacts;
list.ItemTemplate = new DataTemplate (typeof(InviteItemCell));

這是自定義視單元:

public class InviteItemCell : ViewCell
    {
        public InviteItemCell ()
        {
            var chkInvite = new CheckBox ()
            { 
                TextColor = Color.White
            };

            chkInvite.SetBinding (CheckBox.DefaultTextProperty, "FullName");
            chkInvite.SetBinding (CheckBox.CheckedProperty, "Selected");

            var layout = new StackLayout 
            {
                Padding = new Thickness(20, 0, 0, 0),
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Children = {chkInvite}
            };

            View = layout;
        }

        protected override void OnBindingContextChanged ()
        {
            View.BindingContext = BindingContext;
            base.OnBindingContextChanged ();
        }
    }

嘗試這個:

chkInvite.SetBinding (CheckBox.DefaultTextProperty, "FullName", BindingMode.TwoWay);
chkInvite.SetBinding (CheckBox.CheckedProperty, "Selected", BindingMode.TwoWay);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM