using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


using System.ComponentModel.Composition;
using TfsWorkbench.Core.Interfaces;

namespace TfsWorkbenchPlugin100
{
    [Export(typeof(IWorkbenchPlugin))]
    internal class PluginInterface : IWorkbenchPlugin
    {
        private IEnumerable<CommandBinding> commandBinding;
        private MenuItem menuItem;
        private UIElement uiElement;

        public PluginInterface()
        {
            menuItem = new MenuItem();
            menuItem.Name = "MyMenuItem";
            menuItem.Header = "MyPluginMenuItem";
            menuItem.RenderSize = new Size(100, 100);

            uiElement = new MyControl1();
            //uiElement.RenderSize = new Size(100, 100);

            CommandBinding[] bind = new CommandBinding[1];
            bind[0] = new CommandBinding();
            commandBinding = bind;
        }

        public IEnumerable<CommandBinding> CommandBindings
        {
            get { return commandBinding; }
        }

        public UIElement ControlElement
        {
            get { return uiElement; }
        }

        public string DisplayName
        {
            get { return "MyFirstTFSWorkbenchPlugin"; }
        }

        public int DisplayPriority
        {
            get { return 5; }
        }

        public MenuItem MenuItem
        {
            get { return menuItem; }
        }
    }

    [Export(typeof(IDisplayMode))]
    public class MyPluginControl : UserControl, IDisplayMode
    {

        //public MyPluginControl()
        // {
        //    
        //}

        public IDataProvider DataProvider
        {
            get
            {
                return (IDataProvider) new object();
            }
            set
            {
                
            }
        }

        public int DisplayPriority
        {
            get { return 5; }
        }

        public MenuItem MenuControl
        {
            get
            {
                MenuItem menuItem = new MenuItem();
                menuItem.Name = "MyDisplayMenuItem";
                menuItem.Header = "MyPluginDisplayMenuItem";
                menuItem.RenderSize = new Size(100, 100);
                return menuItem;
            }
        }

        public IProjectData ProjectData
        {
            get
            {
                return (IProjectData)new object();
            }
            set
            {
                
            }
        }

        public void Highlight(IWorkbenchItem workbenchItem)
        {
            
        }

        public bool IsActive
        {
            get { return (base.Visibility == Visibility.Visible); }
        }

        public bool IsHighlightProvider
        {
            get { return false; }
        }

        public string Title
        {
            get { return "MyPluginDisplayMode"; }
        }
    }
    /// <summary>
    /// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
    ///
    /// Step 1a) Using this custom control in a XAML file that exists in the current project.
    /// Add this XmlNamespace attribute to the root element of the markup file where it is 
    /// to be used:
    ///
    ///     xmlns:MyNamespace="clr-namespace:TfsWorkbenchPlugin100"
    ///
    ///
    /// Step 1b) Using this custom control in a XAML file that exists in a different project.
    /// Add this XmlNamespace attribute to the root element of the markup file where it is 
    /// to be used:
    ///
    ///     xmlns:MyNamespace="clr-namespace:TfsWorkbenchPlugin100;assembly=TfsWorkbenchPlugin100"
    ///
    /// You will also need to add a project reference from the project where the XAML file lives
    /// to this project and Rebuild to avoid compilation errors:
    ///
    ///     Right click on the target project in the Solution Explorer and
    ///     "Add Reference"->"Projects"->[Select this project]
    ///
    ///
    /// Step 2)
    /// Go ahead and use your control in the XAML file.
    ///
    ///     <MyNamespace:CustomControl1/>
    ///
    /// </summary>
    public class CustomControl1 : Control
    {
        static CustomControl1()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
        }
    }

}

Last edited Jan 24, 2011 at 9:47 PM by fixitchris, version 1