示例#1
0
        private void GameTypesButton_drop(object sender, DragEventArgs e)
        {
            Button parent = (Button)sender;

            if (e.Data.GetData(typeof(Map)) != null)
            {
                Map        data           = (Map)e.Data.GetData(typeof(Map));
                StackPanel sp             = (StackPanel)parent.Parent;
                ListView   specificMapsLV = (ListView)sp.GetChildObjects().OfType <ListView>().First(lv => lv.Name == "specificMaps_lb");
                ObservableCollection <Map> specificMaps = (ObservableCollection <Map>)specificMapsLV.ItemsSource;

                if (specificMaps == null)
                {
                    specificMaps = new ObservableCollection <Map>();
                }

                Debug.WriteLine(specificMaps.Count);
                specificMapsLV.ItemsSource = specificMaps;

                if (specificMaps.Any(map => map.Name == data.Name))
                {
                    Debug.WriteLine("Apparently " + data.Name + " already exists");
                }
                else
                {
                    Debug.WriteLine("Apparently " + data.Name + " is now added");
                    specificMaps.Add(data);
                }
            }
        }