microsoft / xaml-designer-extensibility

Extensibility sample code for the Visual Studio XAML Designer
MIT License
67 stars 29 forks source link

Visual Studio's design-time APIs don't provide a way to access the SuggestedAction adorner #32

Closed miniBivlidi closed 3 years ago

miniBivlidi commented 4 years ago

Environment: Microsoft Visual Studio Professional 2019 Preview Version 16.8.0 Preview 3.1

Issue: I need to hide the SuggestedAction adorner programmatically.

I tried to get a DesignerView instance from the Editing Context and set the AdornersVisible property to false.

var view = DesignerView.FromContext(ModelItem.Context);
view.AdornersVisible = false;

I also tried to find the adorner in the Adorners collection:

var view = DesignerView.FromContext(rootDiagram.Context);
foreach(var adorner in view.Adorners) {
     ......
} 

Unfortunately, none of these attempts was successful.

It seems that design time has no public APIs to access the SuggestedAction adorner and show or hide it.

koljaka commented 4 years ago

Could you please provide more details on what you are trying to achieve here? Have you specified SuggestedActionProvider for your control? If yes, at what point do you want to hide SuggestedAction adorner?

miniBivlidi commented 4 years ago

I have a custom control and added my commands to Suggested Actions using a custom SuggestedActionProvider. Here are the scenarios in which I need to close the Suggested Actions popup:

  1. A command in Suggested Actions shows a modal window in a separate process. When I show the window, the Suggested Actions popup remains open. Moreover, it's displayed over my window. I want to close the popup programmatically when my window opens.
  2. Another command in Suggested Actions selects a child visual element from my control and shows its suggested action. I want to close the parent element's Suggestion Actions at this point.
miniBivlidi commented 3 years ago

I created a simple project to illustrate scenarios when it would be great to have access to the Suggested Actions popup. In the attached videos, you can see the following:

  1. The Suggested Actions popup remains open even though an external process window is displayed;
  2. The execution of the command changes selection both in the XAML editor and PropertyGrid, but the Suggested Actions popup does not update its content. We could close and re-open the popup manually if there was a corresponding API.

SuggestedActionsPanel_Issue.zip

thsparks commented 3 years ago

Thanks so much for sending that along. It's a big help.

I think the scenarios you have described are actually bugs on our end with the suggested actions provider. I would be more inclined to fix those bugs (i.e. have the popup close) than expose access to the provider directly, as I'm worried that could lead to some design issues down the road. Are there other scenarios where you need access?

The good news is, the issue you mentioned in scenario 1 has actually been fixed already :) You should be able to see that in 16.9 Preview 3. I can file an issue on our side to address issue 2 as well.

miniBivlidi commented 3 years ago

Thank you for the answer. No, there are no other scenarios that require access to the popup.

thsparks commented 3 years ago

Both issues described in this bug should now be addressed. Please let me know if you see them again. Thanks!

sassy224 commented 3 years ago

@thsparks are they any apis to programmatically close the suggested actions menu? My scenario is I have 2 command actions: EnableXXXCommand and DisableXXXCommand. When click EnableXXXCommand, the menu should close, so that the next time it's open, DisableXXXCommand is shown instead.

The current situation is after click EnableXXXCommand, the menu is still open, so EnableXXXCommand is still there, and still clickable which is not desirable. Any way to close the menu at this point is appreciated.