示例#1
0
        private ToolbarItemDefinition GetItem(string CommandName, string toolBarName)
        {
            ToolBar toolBar = string.IsNullOrEmpty(toolBarName) ? GetToolBar() : GetToolBar(toolBarName);

            var item = toolBar.Items.OfType <ImageButtonBase>().Where(element => element.Command.Name == CommandName).FirstOrDefault();

            var def = new ToolbarItemDefinition()
            {
                CommandBinding   = item.CommandBindings[0],
                DisabledIconPath = item.DisabledImageSource.ToString(),
                EnabledIconPath  = item.EnabledImageSource.ToString(),
                Tooltip          = item.ToolTip.ToString()
            };

            return(def);
        }
示例#2
0
 public void Add(string toolBarName, ToolbarItemDefinition def)
 {
     iseWindow.Dispatcher.Invoke(new Action <string, ToolbarItemDefinition>(this.AddItem), toolBarName, def);
 }
示例#3
0
        private void AddItem(string toolBarName, ToolbarItemDefinition def)
        {
            ToolBar toolBar = string.IsNullOrEmpty(toolBarName) ? GetToolBar() : GetToolBar(toolBarName);

            ImageButtonBase item = null;

            if (def.IsTogglable)
            {
                var button = new ImageToggleButton();

                button.EnabledImageSource = new BitmapImage(new Uri(def.EnabledIconPath));
                if (def.DisabledIconPath != null)
                {
                    button.DisabledImageSource = new BitmapImage(new Uri(def.DisabledIconPath));
                }
                if (def.CommandBinding != null)
                {
                    button.CommandBindings.Add(def.CommandBinding);
                }
                if (def.CommandParameter != null)
                {
                    button.SetCommandParameter(def.CommandParameter);
                }
                button.Command = def.Command;
                button.ToolTip = def.Tooltip;

                item = button;
            }
            else
            {
                var button = new ImageButton();

                button.EnabledImageSource = new BitmapImage(new Uri(def.EnabledIconPath));
                if (def.DisabledIconPath != null)
                {
                    button.DisabledImageSource = new BitmapImage(new Uri(def.DisabledIconPath));
                }
                button.CommandBindings.Add(def.CommandBinding);
                button.Command = def.Command;
                if (def.CommandParameter != null)
                {
                    button.SetCommandParameter(def.CommandParameter);
                }
                if (!string.IsNullOrEmpty(def.Tooltip))
                {
                    button.ToolTip = def.Tooltip;
                }

                item = button;
            }

            if (!string.IsNullOrEmpty(def.ReferenceItemName))
            {
                var index = 0;

                var referenceItem = toolBar.Items.OfType <ImageButtonBase>().Where(element => element.Command.Name == def.ReferenceItemName).FirstOrDefault() as ImageButtonBase;
                index = toolBar.Items.IndexOf(referenceItem);

                if (def.Position == ToolbarItemPosition.After)
                {
                    toolBar.Items.Insert(index + 1, item);
                }
                else if (def.Position == ToolbarItemPosition.Before)
                {
                    if (index == 0)
                    {
                        toolBar.Items.Insert(0, item);
                    }
                    else
                    {
                        toolBar.Items.Insert(index - 1, item);
                    }
                }
            }
            else
            {
                if (def.Position == ToolbarItemPosition.Top)
                {
                    toolBar.Items.Insert(0, item);
                }
                else
                {
                    toolBar.Items.Add(item);
                }
            }
        }