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);
            }

        }

    }

  • 相关阅读:
    MySQL优化点
    MySQL中lock tables和unlock tables浅析
    在深度计算框架MindSpore中如何对不持续的计算进行处理——对数据集进行一定epoch数量的训练后,进行其他工作处理,再返回来接着进行一定epoch数量的训练——单步计算
    Attributes should be specified via @SpringBootApplication
    base-package的路径不对,导致@Autowire提示trainingRepository错误。
    测试框架之-断言与预期结果 AssertJ
    无效的目标版本8 和 Unsupported major.minor version 52
    UML类图中箭头和线条的含义和用法
    苏宁乔新亮:世界上最好的研发管理十条经验
    4-8 路由实战
  • 原文地址:https://www.cnblogs.com/zisezhixin/p/4106907.html
Copyright © 2011-2022 走看看