/// <summary>
        /// 每次Open回显数据不太好,先这么处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PART_Popup_Opened(object sender, EventArgs e)
        {
            if (!this.mPopupIsFirstOpen)
            {
                return;
            }

            this.mPopupIsFirstOpen = false;

            if (this.ItemsSource == null || this.SelectedObjList == null)
            {
                return;
            }

            foreach (var obj in this.SelectedObjList)
            {
                foreach (var item in this.ItemsSource)
                {
                    if (item == obj)
                    {
                        CheckComboBoxItem checkComboBoxItem = this.ItemContainerGenerator.ContainerFromItem(item) as CheckComboBoxItem;
                        if (checkComboBoxItem != null)
                        {
                            checkComboBoxItem.IsSelected = true;
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 行选中
        /// </summary>
        /// <param name="item"></param>
        internal void NotifyCheckComboBoxItemClicked(CheckComboBoxItem item)
        {
            item.SetValue(CheckComboBoxItem.IsSelectedProperty, !item.IsSelected);
            string itemContent = Convert.ToString(item.Content);

            if (item.IsSelected)
            {
                if (!this.SelectedStrList.Contains(item.Content))
                {
                    this.SelectedStrList.Add(itemContent);
                }
                if (!this.SelectedObjList.Contains(item.DataContext))
                {
                    this.SelectedObjList.Add(item.DataContext);
                }
            }
            else
            {
                if (this.SelectedStrList.Contains(itemContent))
                {
                    this.SelectedStrList.Remove(itemContent);
                }
                if (this.SelectedObjList.Contains(item.DataContext))
                {
                    this.SelectedObjList.Remove(item.DataContext);
                }
            }

            this.SetCheckComboBoxValueAndContent();
        }
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            if (!(item is CheckComboBoxItem))
            {
                CheckComboBoxItem checkComboBoxItem = element as CheckComboBoxItem;
                if (checkComboBoxItem != null && !string.IsNullOrEmpty(this.DisplayMemberPath))
                {
                    Binding binding = new Binding(this.DisplayMemberPath);
                    checkComboBoxItem.SetBinding(CheckComboBoxItem.ContentProperty, binding);
                }
            }

            base.PrepareContainerForItemOverride(element, item);
        }
Beispiel #4
0
        internal void NotifyCheckComboBoxItemClicked(CheckComboBoxItem item)
        {
            item.SetValue(CheckComboBoxItem.IsSelectedProperty, !item.IsSelected);
            string itemContent = Convert.ToString(item.Content);

            if (item.IsSelected)
            {
                if (!this.SelectedStrList.Contains(item.Content))
                {
                    this.SelectedStrList.Add(itemContent);
                }
                if (!this.SelectedObjList.Contains(item.DataContext))
                {
                    this.SelectedObjList.Add(item.DataContext);
                }
            }
            else
            {
                if (this.SelectedStrList.Contains(itemContent))
                {
                    this.SelectedStrList.Remove(itemContent);
                }
                if (this.SelectedObjList.Contains(item.DataContext))
                {
                    this.SelectedObjList.Remove(item.DataContext);
                }
            }

            if (this.SelectedStrList.Count > this.MaxShowNumber)
            {
                this.Content = this.SelectedStrList.Count + " Selected";
            }
            else
            {
                this.Content = this.SelectedStrList.Aggregate("", (current, p) => current + (p + ", ")).TrimEnd(new char[] { ' ' }).TrimEnd(new char[] { ',' });
            }
            this.Value = this.SelectedStrList.Aggregate("", (current, p) => current + (p + ",")).TrimEnd(new char[] { ',' });
        }