locked
How to know the active control within XAML designer? RRS feed

  • Question

  • How to know, during design-time, which control is active / focused by the user in a custom items control, so as to show the rendering for that selected item?

    I'm after functionality similar to TabControl:

    enter image description here

    The difference in my control is that it displays a very simple, sequential workflow, and will show breadcrumbs in place of tabs. Currently, I'm just displaying the first panel content of the control. I need to know when a developer has another panel active in the XAML editor to display content of that panel, accordingly.

    I'm currently after a value that would be available in MeasureOverride, but would be flexible as long as I have anything available in the code-behind.

    I've tried such hacks as

    if (System.ComponentModel.DesignerProperties.IsInDesignTool)
    {
        foreach (var panel in this.Panels)
        {
            panel.GotFocus += focusHandler;
        }
    }

    and using System.Windows.Input.FocusManager.GetFocusedElement() but haven't met with any luck thus far.

    Thursday, May 14, 2015 1:33 PM

Answers

  • Hi,

    I have seen that you have solved this issue at Telerik Forums, I will quote this thread here: http://www.telerik.com/forums/how-to-know-the-active-control-within-xaml-designer, it will be very beneficial for other community members who have similar questions. At currently, I will close this thread, if you have any difficulty in future, welcome to our forum.

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 5, 2015 8:15 AM
    Moderator

All replies

  • It isn't running in the designer.

    What you're attempting cannot work.

    If you just need to see what happens with a given chunk of data in both then you could perhaps use design time data.

    Or

    You can test in your page constructor:

    if (DesignerProperties.GetIsInDesignMode(this) 
    {
      DataContext = new DesignerViewModel();
    }


    Hope that helps.

    Technet articles: Uneventful MVVM; All my Technet Articles

    Thursday, May 14, 2015 6:48 PM
    Moderator
  • It's not running in the usual debugging sense, but it does execute some code as it shows you the UI in the designer.  A quick example to prove that point would just be:

    protected override Size MeasureOverride(Size availableSize)
    {
        throw new NotImplementedException();
    }
    Also, while Microsoft may be able to do some tricks with Internally accessible properties, methods, or interfaces (I've run into that problem before), there are existing control developers, such as Telerik, that have created controls similar to the functionality I'm after.  Thus, I imagine it must somehow be possible, just not very apparent how.

    Thursday, May 14, 2015 9:10 PM
  • Hi,

    I have seen that you have solved this issue at Telerik Forums, I will quote this thread here: http://www.telerik.com/forums/how-to-know-the-active-control-within-xaml-designer, it will be very beneficial for other community members who have similar questions. At currently, I will close this thread, if you have any difficulty in future, welcome to our forum.

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 5, 2015 8:15 AM
    Moderator