/// <summary> /// MainWindow加载事件 /// </summary> private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var canvas = (Canvas)this.GetTemplateChild("FuncShowCanvas");//找到功能演示面板 //加载启动文档,设置好宽高后并将之显示在演示区域 canvasContent = new Pages.CanvasContentsMFrmLoad(); canvasContent.Width = canvas.Width; canvasContent.Height = canvas.Height; canvas.Children.Add(canvasContent); }
/// <summary> /// 功能按钮点击事件 /// </summary> private void RadioButton_Click(object sender, RoutedEventArgs e) { var listBox = (ListBox)this.GetTemplateChild("FunctionList"); //找到列表框 listBox.Items.Clear(); //清空所有项 //若点击的项是Home if ((sender as RadioButton).Name == "Home") { listBox.Visibility = Visibility.Hidden; CheckedItemName = "Home"; //找到功能演示面板 var canvas = (Canvas)this.GetTemplateChild("FuncShowCanvas"); //将宽高重设回默认宽高 canvas.Width = 500; canvas.Height = 500; //清空所有容器Canvas的对象。 canvas.Children.Clear(); ///加载启动文档,设置好文档的宽高,最后添加到容器Canvas中 canvasContent = new Pages.CanvasContentsMFrmLoad(); canvasContent.Width = canvas.Width; canvasContent.Height = canvas.Height; canvas.Children.Add(canvasContent); return; } //加载XML文档 XmlDocument doc = new XmlDocument(); doc.Load("Data/FuncListItem.xml"); //获得此文档Root节点的所有子节点 var root = doc.SelectSingleNode("Root"); var childs = root.ChildNodes; var funcName = (sender as RadioButton).Name;//获得点击的功能按钮值 //判断点击的是哪个功能项 switch (funcName) { #region Case:Circle case "Circle": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[0].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[0].ChildNodes.Item(i).InnerText; item.Name = "Circle" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:Square case "Square": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[1].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[1].ChildNodes.Item(i).InnerText; item.Name = "Square" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:StraitLine case "StraitLine": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[2].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[2].ChildNodes.Item(i).InnerText; item.Name = "StraitLine" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:Polygon case "Polygon": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[3].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[3].ChildNodes.Item(i).InnerText; item.Name = "Polygon" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:Character case "Character": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[4].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[4].ChildNodes.Item(i).InnerText; item.Name = "Character" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:Transform case "Transform": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[5].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[5].ChildNodes.Item(i).InnerText; item.Name = "Transform" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion #region Case:Setting case "Setting": listBox.Visibility = Visibility.Visible; for (int i = 0; i < childs[6].ChildNodes.Count; i++) { ListBoxItem item = new ListBoxItem(); item.Style = FindResource("ListItemStyle") as Style; item.Content = childs[6].ChildNodes.Item(i).InnerText; item.Name = "Setting" + i.ToString(); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ListBoxItemPreviewMouseLeftButtonDown); listBox.Items.Add(item); } break; #endregion default: break; } }