private void LoadToolbarPanelControl(ToolBarButtonControl toolbarButtonControl) { StackPanel stackPanel = new StackPanel(); stackPanel.Orientation = Orientation.Horizontal; stackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top; #region 动态获取所有的IElementControl var types = this.GetType().Assembly.GetTypes(); var query = from Type t in types where t.GetInterface(typeof(IElementControl).FullName) != null select t; foreach (var type in query) { IElementControl elementControl = this.GetType().Assembly.CreateInstance(type.FullName) as IElementControl; elementControl.InitEvent(); if (toolbarButtonControl.Tag != null && toolbarButtonControl.Tag.ToString() == elementControl.OwnerName) { UserControl userControl = elementControl as UserControl; userControl.Height = 100; userControl.Width = 100; userControl.Margin = new Thickness(10, 10, 10, 10); stackPanel.Children.Add(userControl); } } this.ToolbarPanelGrid.Children.Add(stackPanel); #endregion }
void toolBarButton_MouseEnter(object sender, MouseEventArgs e) { foreach (ToolBarButtonControl t in this.SmallToolbarPanel.Children) { t.TextColor = Brushes.Black; } ToolBarButtonControl toolbarButtonControl = sender as ToolBarButtonControl; RecObject.Fill = toolbarButtonControl.FillColor; toolbarButtonControl.TextColor = Brushes.White; Storyboard storyboard = this.Resources["ST_MouseEnter"] as Storyboard; storyboard.Begin(); this.ToolbarPanelGrid.Children.Clear(); LoadToolbarPanelControl(toolbarButtonControl); }