zoukankan      html  css  js  c++  java
  • MultiSelectComboBox(二)

    1. MainWindow.xaml

    <Window x:Class="MultiSelectDemo.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ViewModel="clr-namespace:MultiSelectDemo"
            xmlns:control="clr-namespace:MultiSelectComboBox;assembly=MultiSelectComboBox"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <ViewModel:ViewModel x:Key="ViewModel"/>
        </Window.Resources>
        <Grid DataContext="{Binding Source={StaticResource ViewModel}}">
            <control:MultiSelectComboBox Width="100" Height="30" ItemsSource="{Binding Items}"
                                         DefaultText="input jjj"
                                         SelectedItems="{Binding SelectedItems,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                         />
        </Grid>
    </Window>

    2. MainWindowViewModel.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;

    namespace MultiSelectDemo
    {
        public class MainWindowViewModel: NotificationObject
        {

            private Dictionary<string, object> _items;
            private Dictionary<string, object> _selectedItems;

            public Dictionary<string, object> Items
            {
                get
                {
                    return _items;
                }
                set
                {
                    _items = value;
                    NotifyPropertyChanged("Items");
                }
            }

            public Dictionary<string, object> SelectedItems
            {
                get
                {
                    return _selectedItems;
                }
                set
                {
                    _selectedItems = value;
                    NotifyPropertyChanged("SelectedItems");
                }
            }

            public MainWindowViewModel()
            {
                Items = new Dictionary<string, object>();
                Items.Add("Chennai", "MAS");
                Items.Add("Trichy", "TPJ");
                Items.Add("Bangalore", "SBC");
                Items.Add("Coimbatore", "CBE");

                SelectedItems = new Dictionary<string, object>();
                SelectedItems.Add("Chennai", "MAS");
                SelectedItems.Add("Trichy", "TPJ");
            }

            private void Submit()
            {
                foreach (KeyValuePair<string, object> s in SelectedItems)
                    MessageBox.Show(s.Key);
            }

        }

    }

  • 相关阅读:
    使用Aspose.Cell控件实现Excel高难度报表的生成(三)
    使用Aspose.Cell控件实现Excel高难度报表的生成(二)
    使用Aspose.Cell控件实现Excel高难度报表的生成(一)
    利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
    新中新身份证阅读器不显示图片
    spring security 3 自定义认证,授权示例
    Spring Security教程
    Spring Security3实现,权限动态获取
    mybatis 做 insert操作的时候返回插入的那条数据的id
    如何在spring中获取request对象
  • 原文地址:https://www.cnblogs.com/zisezhixin/p/4106907.html
Copyright © 2011-2022 走看看