wpf ComboBox 绑定 以及绑定项过多加载过慢问题

<Window x:Class="wpfDemo.DataBind.ComboxBinding"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ComboxBinding" Height="300" Width="300">
    <Grid>
        <ComboBox Height="23" Margin="12,12,0,0" Name="cmbLitter" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="12,83,0,0" Name="cmbMore" VerticalAlignment="Top" Width="120" />
       
        <ComboBox x:Name="cmbMoreLarge" Margin="12,0,0,90" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="120">
            <ComboBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel></VirtualizingStackPanel>
                </ItemsPanelTemplate>
            </ComboBox.ItemsPanel>
        </ComboBox>
        <Label Height="23" Margin="138,12,60,0" Name="label1" VerticalAlignment="Top">20Item</Label>
        <Label Height="23" Margin="138,83,60,0" Name="label2" VerticalAlignment="Top">2000Item</Label>
        <Label Height="23" Margin="138,0,60,90" Name="label3" VerticalAlignment="Bottom">2000Item</Label>
    </Grid>
</Window>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace wpfDemo.DataBind
{
    /// <summary>
    /// ComboxBinding.xaml 的交互逻辑
    /// </summary>
    public partial class ComboxBinding : Window
    {
        public ComboxBinding()
        {
            InitializeComponent();
            bind();
        }

        private void bind()
        {
            this.cmbLitter.ItemsSource = getSource(20);
            this.cmbLitter.DisplayMemberPath = "Name";
            this.cmbLitter.SelectedValuePath = "Id";
            this.cmbLitter.SelectedIndex = 0;

 

 

            this.cmbMore.ItemsSource = getSource(2000);
            this.cmbMore.DisplayMemberPath = "Name";
            this.cmbMore.SelectedValuePath = "Id";
            this.cmbMore.SelectedIndex = 0;

            this.cmbMoreLarge.ItemsSource = getSource(2000);
            this.cmbMoreLarge.DisplayMemberPath = "Name";
            this.cmbMoreLarge.SelectedValuePath = "Id";
            this.cmbMoreLarge.SelectedIndex = 0;

        }

        private List<User> getSource(int length)
        {
            List<User> list = new List<User>();
            for (int i = 0; i < length; i++)
            {
                User u = new User();
                u.Id = i;
                u.Name = "admin" + i;
                list.Add(u);
            }
            return list;
        }


    }


}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值