예제 #1
0
        //Iterate to add TreeViewItem onto TreeView
        private List <string> getAllSelectedLayersNames_FromParentItem(TreeViewItem parent)
        {
            List <string> layerNameList = new List <string>();

            foreach (TreeViewItem item in parent.Items)
            {
                if (item.Items == null || item.Items.Count == 0)
                {
                    CheckBoxWithImageText panel = item.Header as CheckBoxWithImageText;
                    if (panel.isSelected_CheckBox.IsChecked == true)
                    {
                        //get the layer name from Textbox's taged object
                        layerNameList.Add(panel.Title.Tag as string);
                    }
                }
                else
                {
                    List <string> layerNameList1 = getAllSelectedLayersNames_FromParentItem(item);
                    layerNameList.AddRange(layerNameList1);
                }
            }
            return(layerNameList);
        }
예제 #2
0
        public void addLayers(ObservableCollection <WMSLayer> layerObject)
        {
            TreeViewItem rootTreeNode = new TreeViewItem();

            CheckBoxWithImageText area1 = new CheckBoxWithImageText();

            area1.Title.Text       = "All layers [" + layerObject.Count + "]";
            area1.Title.FontSize   = 15;
            area1.Title.FontWeight = FontWeights.Bold;
            area1.Image1.Source    = new BitmapImage(new Uri("/GeoSearch;component/images/resourceTypes/Layers-icon.png", UriKind.Relative));


            area1.isSelected_CheckBox.Checked += new RoutedEventHandler((sender, e) =>
            {
                foreach (TreeViewItem item in rootTreeNode.Items)
                {
                    CheckBoxWithImageText panel         = item.Header as CheckBoxWithImageText;
                    panel.isSelected_CheckBox.IsChecked = true;
                    // .Children[0] as CheckBox).IsChecked = true;
                }
            });
            area1.isSelected_CheckBox.Unchecked += new RoutedEventHandler((sender, e) =>
            {
                foreach (TreeViewItem item in rootTreeNode.Items)
                {
                    CheckBoxWithImageText panel         = item.Header as CheckBoxWithImageText;
                    panel.isSelected_CheckBox.IsChecked = false;
                    //((item.Header as StackPanel).Children[0] as CheckBox).IsChecked = false;
                }
            });

            //we customs the TreeviewItem: add checkbox and image icon before title text content,
            //then we use our TreeViewItem UserControl as the Header Object of TreeViewItem.
            rootTreeNode.Header     = area1;
            rootTreeNode.IsExpanded = true;

            foreach (WMSLayer layer in layerObject)
            {
                TreeViewItem          layerTreeNode = new TreeViewItem();
                CheckBoxWithImageText area2         = new CheckBoxWithImageText();
                //we show the layer's title in tree view as tree node
                area2.Title.Text = layer.title + " (Name: " + layer.name + ")";
                //and the true layer is taged as the object
                area2.Title.Tag      = layer.name;
                layerTreeNode.Header = area2;
                rootTreeNode.Items.Add(layerTreeNode);
            }
            this.Layers_Treeview.Items.Add(rootTreeNode);


            //ObservableCollection<Layer> layers = getLayersNamesFromWMSCapabilitiesDocument1();
            //foreach (Layer layer in layers)
            //{
            //    TreeViewItem layerTreeNode = new TreeViewItem();
            //    layerTreeNode.ItemContainerStyle = this.Resources["LayersItemStyle"] as Style;
            //    //layerTreeNode.Items.Add("");
            //    layerTreeNode.Visibility = System.Windows.Visibility.Visible;
            //    layerTreeNode.Width = 200;
            //    layerTreeNode.Tag = "";
            //    //layerTreeNode.Header = layer.name;

            //    //layerTreeNode.DataContext = layer;
            //    rootTreeNode.Items.Add(layerTreeNode);
            //}

            //this.Layers_Treeview.Items.Add(rootTreeNode);
        }