using DataLoader.CS; using DataLoader.Model; using System; using System.Linq; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using CefSharp.Callback; using System.Windows.Media; namespace DataLoader { public partial class ResWin : Window { private TreeItem items = new TreeItem(); private List dirs; private CheckBox cbLast; public ResWin() { InitializeComponent(); } private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // } private void Window_Loaded(object sender, RoutedEventArgs e) { dirs = DBHelper.GetDirList(); if (null == dirs || 0 == dirs.Count) return; FindTreeItems(dirs, items, 0); this.tvResTree.ItemsSource = items.Child; //SetCheckedBox(); } private void FindTreeItems(List list, TreeItem ti, int pid) { if (ti.Child == null) ti.Child = new ObservableCollection(); foreach (SysDir dir in list) { if (pid == dir.pid) { TreeItem item = new TreeItem(); item.ID = dir.id; item.Name = dir.name; item.FullName = dir.fullName; item.IsExpanded = true; item.IsChecked = CommonProp.dirId == dir.id; ti.Child.Add(item); FindTreeItems(list, item, dir.id); } } } private void SetCheckedBox() { if (CommonProp.dirId == 0) return; foreach (var item in this.tvResTree.Items) { TreeViewItem tvItem = this.tvResTree.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; if (null == tvItem) continue; //((System.Windows.Controls.Panel)tvItem.VisualParent).Children for (int i = 0, c = VisualTreeHelper.GetChildrenCount(tvItem); i < c; i++) { DependencyObject child = VisualTreeHelper.GetChild(this.tvResTree, i); if (child is CheckBox) { CheckBox cb = child as CheckBox; if (cb.IsChecked == true) { this.cbLast = cb; return; } } } } } private void CheckBox_Click(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; if (cb.IsChecked == true) { if (null != this.cbLast) this.cbLast.IsChecked = false; this.cbLast = cb; } else { this.cbLast = null; } } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { SysDir dir = null; if (this.cbLast != null) { CommonProp.dirId = int.Parse(this.cbLast.Tag.ToString()); dir = (from d in dirs where d.id == CommonProp.dirId select d).First(); } this.Hide(); CommonProp.Owner.SetRes(null == dir ? null : dir.code, null == dir ? null : dir.fullName); e.Cancel = true; } } }