Reputation: 4059
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:
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.
Upvotes: 3
Views: 263
Reputation: 5574
There are two possible ways you can approach this:
You best shot at this is to review the WPF Designer Extensibility documenation, and also have a look at how DesignTime support for the TabControl is implemented.
In design time, the Designer has some mechanism to prevent the user from interacting directly with the controls. This is why you have difficulty trying to determine which element has focus.
You can teach the Designer how to provide custom adorners over your control so that user may interact with them via the adorners.
For your reference, the TabControl extensibility modules can be found in:
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\Design
- System.Windows.Controls.Design.dll
- System.Windows.Controls.VisualStudio.Design.dll
- System.Windows.Controls.Expression.Design.dll
The key idea appears to be:
SelectedTabItemPolicy
lists the types of control (in this case - it is the TabItem
) where selection can appearTabItemAdornerProvider
then calls SetDesignTimeIsSelected
on the selected TabItemThis in turn calls:
item.get_Context().get_Services().Publish(service);
which appears to take a dictionary of values. There are a lot of rabbit holes to explore here.
You can actually respond to changes in the property sheet. e.g. When SelectedIndex
changes, you can make the different pages visible.
Changelog Updated with links to WPF Designer documentation.
Upvotes: 1