【问题标题】:xamarin forms labs binding issue with listview and checkboxxamarin 使用 listview 和复选框形成实验室绑定问题
【发布时间】:2014-12-16 12:26:17
【问题描述】:

我遇到了 xamarin forms lab (Xamarin-forms-labs) 复选框控件的绑定问题。我有一个列表视图 指向一个联系人数据源(这是一个可观察的集合)。在列表视图中我有 自定义视图单元格“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 ();
        }
    }

【问题讨论】:

    标签: android xamarin xamarin.forms


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 2016-09-22
      • 2018-01-17
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多