Example #1
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            int         index       = this.ItemContainerGenerator.IndexFromContainer(element);
            SegmentItem segmentItem = element as SegmentItem;

            if (segmentItem == null)
            {
                return;
            }

            if (index == 0)
            {
                segmentItem.IsFirstItem  = true;
                segmentItem.CornerRadius = new CornerRadius(this.CornerRadius.TopLeft, 0, 0, this.CornerRadius.BottomLeft);
            }

            if (index == this.Items.Count - 1)
            {
                segmentItem.IsLastItem   = true;
                segmentItem.CornerRadius = new CornerRadius(0, this.CornerRadius.TopRight, this.CornerRadius.BottomRight, 0);
            }

            if (this.IsAllRound)
            {
                segmentItem.CornerRadius    = this.CornerRadius;
                segmentItem.BorderThickness = new Thickness(0);
                segmentItem.Padding         = new Thickness(20, 5, 20, 5);
            }

            base.PrepareContainerForItemOverride(segmentItem, item);
        }
Example #2
0
        /// <summary>
        /// 设置SegmentItem的位置属性
        /// </summary>
        /// <param name="index"></param>
        private void SetSegmentItem(int index)
        {
            if (index > this.Items.Count || index < 0)
            {
                return;
            }

            SegmentItem segmentItem = this.ItemContainerGenerator.ContainerFromIndex(index) as SegmentItem;

            if (segmentItem == null)
            {
                return;
            }
            segmentItem.IsFirstItem  = index == 0;
            segmentItem.IsLastItem   = index == this.Items.Count - 1;
            segmentItem.IsMiddleItem = index > 0 && index < this.Items.Count - 1;
        }