How to remove the control's properties from Properties window

Answered How to remove the control's properties from Properties window

  • Dienstag, 17. April 2012 07:31
     
     

    I create a toolwindow(MyToolWindow), there are many controls in this window and every control has itself properties, I add these properties to Properties Window by below code:
    public override void OnToolWindowCreated()
    {
    ArrayList listObjects = new ArrayList();
    listObjects.Add(this);
    SelectList(listObjects);
    }
    public void SelectList(ArrayList list)
    {
    selContainer = new SelectionContainer(true, false);
    selContainer.SelectableObjects = list;
    selContainer.SelectedObjects = list;
    UpdateSelection();
    }
    public void UpdateSelection()
    {
    ITrackSelection track = TrackSelection;
    if (track != null)
    track.OnSelectChange((ISelectionContainer)selContainer);
    }
    private ITrackSelection TrackSelection
    {
    get
    {
    if (trackSel == null)
    trackSel =
    GetService(typeof(STrackSelection)) as ITrackSelection;
    return trackSel;
    }
    }

    by above code, when I click controls in MyToolWindow, the related properties will show.

    But now, I want to remove these properties from Properties window, I want that:   I click 'MyToolwindow',  the text in Properties window does not change, it is same as the text before I click it.

    Please help me!

Alle Antworten

  • Donnerstag, 19. April 2012 09:31
    Moderator
     
     

    Hi andrea,

    Thank you for your question. 

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

  • Freitag, 20. April 2012 19:18
    Moderator
     
     Vorgeschlagene Antwort

    I don't quite understand what exactly you are attempting to do here? The content of the properties toolwindow is control via selection state. When you click on the toolwindow, VS display the properties you've set up for the toolwindow.

    Do you want to list the toolwindow's properties here, or are you looking to change up the selection state based on which control in your toolwindow is currently selected?

    Right now, it sounds like you are populating the properties dialog with the properties of your toolwindow. When you change focus to a different toolwindow, the selection state will automatically change and you should see the properties of that different toolwindow.

    Sincerely,


    Ed Dore

  • Donnerstag, 26. April 2012 08:21
     
     

    hi ED Dore,

    I have implement  to   change up the selection state based on which control in my toolwindow is currently selected( called it: 'Add to properties window function').  For example, I click the control 'A' , then the properties window show 'properties for A'.  and I click the control 'B',  the properties window will  show 'properties for B'.

    My question is: now, I want to remove 'Properties for B'(Undo the above function).   For example,I click the control 'A' , then the properties window show 'properties for A'.  and I click the control 'B',  the properties window still   show 'properties for A'.  because I Undo  add B to properties window.  I try to set 'selectedObjects' to null for B. but if I click 'B', it show a blank properties. 

    so how can I undo add B to properties window?

  • Montag, 30. April 2012 20:16
    Moderator
     
     Beantwortet Enthält Code

    Hi Andrea,

    I'm still not following your example, but I suspect the issue may have to do with your code not pushing an empty selection contact with you first call TrackSelection.OnSelectChange(). I seem to recall this being a requirement per some comments around the ToolWindow Reference Sample. The following is a simple example that I threw together with VS 2010. Note that when the TrackSelection property is first set, we call OnSelectChange with SelectableObjects and SelectedObjects set to null.

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.Shell;
     
    namespace Microsoft.CTS.TWWPPackage
    {
        [Guid("72b981a7-91ef-431a-8e4e-b35a7514c746")]
        public class MyToolWindow : ToolWindowPane
        {
            public MyToolWindow() : base(null)
            {
                this.Caption = Resources.ToolWindowTitle;
                this.BitmapResourceID = 301;
                this.BitmapIndex = 1;
                base.Content = new MyControl();
            }
     
            public override void OnToolWindowCreated()
            {
                base.OnToolWindowCreated();
                MyControl ctrl = base.Content as MyControl;
                ctrl.TrackSelection = (ITrackSelection)GetService(typeof(STrackSelection));
            }
        }
    }
    using System;
    using System.Collections;
    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 Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.Shell;
    using VsConstants = Microsoft.VisualStudio.VSConstants;
    using ErrorHandler = Microsoft.VisualStudio.ErrorHandler;
     
    namespace Microsoft.CTS.TWWPPackage
    {
        /// <summary>
        /// Interaction logic for MyControl.xaml
        /// </summary>
        public partial class MyControl : UserControl
        {
            private ITrackSelection trackSelection;
            private SelectionContainer selectionContainer = new SelectionContainer();
     
            public MyControl()
            {
                InitializeComponent();
                this.GotFocus += new RoutedEventHandler(OnGotFocus);
            }
     
            void OnGotFocus(object sender, RoutedEventArgs e)
            {
                Control ctrl = e.OriginalSource as Control;
     
                if (ctrl != null)
                {
                    if (ctrl.IsDescendantOf(this))
                    {
                        ArrayList controlProperties = new ArrayList();
                        controlProperties.Add(ctrl);
                        selectionContainer.SelectableObjects = controlProperties;
                        selectionContainer.SelectedObjects = controlProperties;
                        TrackSelection.OnSelectChange(selectionContainer);
                    }
                }
            }
     
            internal ITrackSelection TrackSelection
            {
                get { return trackSelection; }
                set 
                {
                    if (value == null)
                        throw new ArgumentNullException("TrackSelection initalization failed!!!");
     
                    // Init with empty selection to ensure update notifications work
                    trackSelection = value;
                    selectionContainer.SelectableObjects = null;
                    selectionContainer.SelectedObjects = null;
                    trackSelection.OnSelectChange(selectionContainer);
                }
            }
         }
    }

    Hopefully, this will get you pointed in the right direction.

    Sincerely,


    Ed Dore