0

嗨,我的页面中有一个组合框控件,组合框的数据是使用视图模型中的 IEnumerable 集合生成的。现在我想在组合框项目的最后一个添加一个静态字符串。这该怎么做?我附上了我的组合框的屏幕截图,它有 4 个值现在我想添加一个字符串示例

项目底部的“自定义尺寸” 。我还附上了我的视图模型代码。在此处输入图像描述

    PartsDomainContext context;
    private IEnumerable<CategoryHierarchy> Categoryhierarchies;
    private IEnumerable<CategoryHierarchy> _SizeCategoryhierarchies;
    private CategoryHierarchy categoryhierarchy;
    private CategoryHierarchy _Sizecategoryhierarchy;
    private ProductCategory productcategory;


    public IEnumerable<CategoryHierarchy> SizeCategoryHierarchies
    {
        get
        {
            return _SizeCategoryhierarchies;
        }
        set
        {
            _SizeCategoryhierarchies = value;

        }
    }


    public CategoryHierarchy SizeCategoryHierarchy
    {

        get { return _Sizecategoryhierarchy; }

        set
        {

            if (_Sizecategoryhierarchy == null)
            {

                _Sizecategoryhierarchy = value;
                OnPropertyChanged("SizeCategoryHierarchy");

                ActiveData.Instance.size = _Sizecategoryhierarchy.Category.CategoryName.ToString();
                ActiveData.Instance.Description1 = _Sizecategoryhierarchy.Category.Description1;
                ActiveData.Instance.Description2 = _Sizecategoryhierarchy.Category.Description2;
                ActiveData.Instance.ShortDescription1 = _Sizecategoryhierarchy.Category.ShortDescription1;
                ActiveData.Instance.Notes = _Sizecategoryhierarchy.Category.Notes;

            }
            else
            {
                try
                {
                    _Sizecategoryhierarchy = value;
                    OnPropertyChanged("SizeCategoryHierarchy");

                    ActiveData.Instance.size = _Sizecategoryhierarchy.Category.ToString();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
            }




        }


    }



    public Wizard1ViewModel()
    {
        GetSize();
    }


    public void GetSize(int parentcategory)
    {
        context = new PartsDomainContext();
        IsBusy = true;
        context.Load(context.GetCategoryByHierarchyQuery(1), e =>
        {
            if (!e.HasError)
            {

                SizeCategoryHierarchies = e.Entities.Where(c =>       c.ParentCategory.Equals(parentcategory));

                OnPropertyChanged("SizeCategoryHierarchies");

                IsBusy = false;

            }
        }, null);
    }


//Xaml 

        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="0*" />
                <RowDefinition Height="300*" />
            </Grid.RowDefinitions>


                    <ComboBox Name="poolsize" ItemsSource="{Binding SizeCategoryHierarchies, Mode=TwoWay}" DisplayMemberPath="Category.CategoryName" SelectedValuePath="Category.CategoryName" SelectedItem="{Binding SizeCategoryHierarchy, Mode=TwoWay}" HorizontalAlignment="Left" Margin="132,0,0,82" FontSize="16" VerticalAlignment="Bottom"  Width="216" RenderTransformOrigin="0.505,2.967" DropDownOpened="poolsize_DropDownOpened_1"/>




        </Grid>
4

1 回答 1

2

由于 IEnumerable 不提供 Add 方法,但您可以在您的 INumerable 上使用 Concat ,您可以在以下链接中找到详细答案How can I add an item to a IEnumerable<T> collection? .

问候,

于 2013-01-16T12:46:03.083 回答