Пример #1
0
        private SegmentItem GetSegmentItem(object data)
        {
            SegmentItem item = null;

            if (data is SegmentItem)
            {
                item = (SegmentItem)data;
            }
            else
            {
                item = new SegmentItem();
                var view = (View)this.ItemTemplate.CreateContent();
                if (view is SegmentItem)
                {
                    item = (SegmentItem)view;
                }
                else
                {
                    item.Content = view;
                }
                item.BindingContext = data;
            }

            item.HorizontalOptions = LayoutOptions.FillAndExpand;
            item.VerticalOptions   = LayoutOptions.FillAndExpand;

            item.Content.HorizontalOptions = LayoutOptions.Center;
            item.Content.VerticalOptions   = LayoutOptions.Center;

            TapBinder.SetCmd(item, this.SelectedCmd);
            TapBinder.SetParam(item, item);

            return(item);
        }
Пример #2
0
        public Segment()
        {
            this.Container = new Grid()
            {
                ColumnSpacing = 0
            };
            this.Content = this.Container;

            this.SelectedCmd = new Command((o) => {
                var item = (SegmentItem)o;

                if (this.IsMutliSelectable)
                {
                    if (this.SelectedItems.Contains(item.Value))
                    {
                        this.SelectedItems.Remove(item.Value);
                        item.BackgroundColor = Color.Transparent;
                        item.IsSelected      = false;
                        //item.ControlTemplate = null;
                    }
                    else
                    {
                        this.SelectedItems.Add(item.Value);
                        item.BackgroundColor = this.SelectedItemBackgroundColor;
                        item.IsSelected      = true;
                        //item.ControlTemplate = this.SelectedItemControlTemplate;
                    }
                }
                else
                {
                    if (this.SelectedSegment != null)
                    {
                        this.SelectedSegment.BackgroundColor = Color.Transparent;
                        this.SelectedSegment.IsSelected      = false;
                        //item.ControlTemplate = null;
                    }
                    this.SelectedItem    = item.Value;
                    this.SelectedSegment = item;
                    item.BackgroundColor = this.SelectedItemBackgroundColor;
                    item.IsSelected      = true;
                    //item.ControlTemplate = this.SelectedItemControlTemplate;
                }
            });

            new NotifyCollectionWrapper(this.Items,
                                        add: (datas, idx) => this.Add(datas, idx),
                                        remove: (datas, idx) => this.Remove(datas, idx),
                                        reset: () => this.Reset(),
                                        finished: () => { });
        }