private void CreateToolBarButtons()
 {
     try
     {
         PanelToolButton.Children.Clear();
         CToolButtonItem toolItem;
         ToggleButton    toggleBtn;
         for (int i = 0; i < _mListPanels.Count; i++)
         {
             PanelItem item = _mListPanels[i];
             if (!item.CanClose)
             {
                 continue;
             }
             toolItem              = new CToolButtonItem();
             toolItem.Name         = "TB" + item.Name;
             toolItem.Display      = item.Title;
             toolItem.Tip          = item.Title;
             toolItem.Icon         = item.Icon;
             toggleBtn             = new ToggleButton();
             toggleBtn.Click      += PanelToggleButton_Click;
             toggleBtn.DataContext = toolItem;
             toggleBtn.IsChecked   = item.IsVisible;
             toggleBtn.SetResourceReference(StyleProperty, "ToolBarToggleBtnStyle");
             PanelToolButton.Children.Add(toggleBtn);
         }
     }
     catch (Exception ex)
     {
         UMPApp.ShowExceptionMessage(ex.Message);
     }
 }
        void PanelToggleButton_Click(object sender, RoutedEventArgs e)
        {
            var toggleBtn = e.Source as ToggleButton;

            if (toggleBtn != null)
            {
                CToolButtonItem item = toggleBtn.DataContext as CToolButtonItem;
                if (item != null)
                {
                    PanelItem panelItem = _mListPanels.FirstOrDefault(p => string.Format("TB{0}", p.Name) == item.Name);
                    if (panelItem == null)
                    {
                        return;
                    }
                    panelItem.IsVisible = toggleBtn.IsChecked == true;
                }
                SetPanelVisible();
            }
        }