winforms icon indicating copy to clipboard operation
winforms copied to clipboard

BindingNavigator no longer appears in the Toolbox (and does not have a designer)

Open pedautreppe opened this issue 3 years ago • 10 comments

Environment

Problem identified on Visual Studio

  • Version 17.4.1
  • Version 16.11.19

.NET version

.NET 5 .NET 6 .NET 7

Did this work in a previous version of Visual Studio and/or previous .NET release?

Was working on .NET 4.x

Issue description

When creating a new form, you cannot choose to add a BindingNavigator : he is not available in the Toolbox. If you add it manually in the Designer file, it works correctly, but you do not benefit of the designer calling the "AddStandardItems" to automatically add the first buttons.

I don't know if this is related, but when investigating in the source code, the BindingNavigator refers to the BindingNavigatorDesigner class (in System.Design 4.0.0.0), but there is no Type Forwarding to the new System.Windows.Forms.Design dll and anyway, the designer does not exist in that new DLL.

I also tried to create a class inheriting from BindingNavigator (see below).

[Designer(typeof(MediaBindingNavigatorDesigner))]
public class MediaBindingNavigator : BindingNavigator
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    public MediaBindingNavigator() { }
    public MediaBindingNavigator(BindingSource bindingSource) : base(bindingSource) { }
    [EditorBrowsable(EditorBrowsableState.Never)]
    public MediaBindingNavigator(IContainer container) : base(container) { }
    public MediaBindingNavigator(bool addStandardItems) : base(addStandardItems: addStandardItems) { }
}

I tried to create my own custom designer to be able to at least call the AddStandardItems methods, but for some reason I don't understand, this designer is not used at design time.

I have the following warning displaying (see full log in the diags below) [22:07:40.7412379] [ACQ]: warn: Microsoft.DotNet.DesignTools.TypeRouting.TypeRoutingService[0] [22:07:40.7412379] [ACQ]: Falling back to 'Microsoft.DotNet.DesignTools.Designers.ControlDesigner' for 'ACQ.MediaBindingNavigatorDesigner'

Steps to reproduce

  • Create a new .NET Windows Forms app
  • Open the newly created Form1
  • Open the Toolbox --> The BindingNavigator is not present

When going to the "Choose Items", you can see that the BindingNavigator is correctly selected. Deselect it and open the "Choose Items" windows --> Still checked

Diagnostics

[22:07:40.7372505] Sending request: Controls/GetAncestors
[22:07:40.7382394] Controls/GetAncestors took 00:00:00.0013195.
[22:07:40.7392394] Sending request: Transactions/Open
[22:07:40.7402385] Transactions/Open took 00:00:00.0010285.
[22:07:40.7402385] Notifying 1 'Undo/UndoUnitCreated' handlers
[22:07:40.7402385] 'Undo/UndoUnitCreated' notification received: Creating components in tool 'MediaBindingNavigator'.62aa060d-3693-42d5-9986-819f26c5b264
[22:07:40.7402385] Notifying 1 'Transactions/Opening' handlers
[22:07:40.7402385] Notifying 1 'Transactions/Opened' handlers
[22:07:40.7402385] Sending request: DesignerHosts/CreateComponent
[22:07:40.7412379] [ACQ]: warn: Microsoft.DotNet.DesignTools.TypeRouting.TypeRoutingService[0]
[22:07:40.7412379] [ACQ]:       Falling back to 'Microsoft.DotNet.DesignTools.Designers.ControlDesigner' for 'ACQ.MediaBindingNavigatorDesigner'
[22:07:40.7538628] DesignerHosts/CreateComponent took 00:00:00.0136782.
[22:07:40.7538628] Notifying 1 'Components/Added' handlers
[22:07:40.7548765] Sending request: Objects/GetAttributes [137]
[22:07:40.7579094] Objects/GetAttributes took 00:00:00.0027005.
[22:07:40.7579094] Added designer component: 'mediaBindingNavigator2'
[22:07:40.7579094] Notifying 1 'Components/Changing' handlers
[22:07:40.7579094] 'Components/Changing' notification received: mediaBindingNavigator2.Text
[22:07:40.7579094] Sending request: Objects/GetProperties
[22:07:40.7913385] Objects/GetProperties took 00:00:00.0329720.
[22:07:40.7923383] Notifying 1 'Components/Changed' handlers
[22:07:40.7923383] 'Components/Changed' notification received: mediaBindingNavigator2.Text
[22:07:40.7923383] Notifying 1 'Components/Changing' handlers
[22:07:40.7923383] 'Components/Changing' notification received: Form1.Controls
[22:07:40.7933519] Notifying 1 'Components/Changing' handlers
[22:07:40.7933519] 'Components/Changing' notification received: mediaBindingNavigator2.Size
[22:07:40.7933519] Notifying 1 'Components/Changed' handlers
[22:07:40.7933519] 'Components/Changed' notification received: mediaBindingNavigator2.Size
[22:07:40.7943368] Notifying 1 'Components/Changing' handlers
[22:07:40.7943368] 'Components/Changing' notification received: mediaBindingNavigator2.Location
[22:07:40.7943368] Notifying 1 'Components/Changed' handlers
[22:07:40.7943368] 'Components/Changed' notification received: mediaBindingNavigator2.Location
[22:07:40.7943368] Notifying 1 'Components/Changed' handlers
[22:07:40.7943368] 'Components/Changed' notification received: Form1.Controls
[22:07:40.7953366] Notifying 1 'Components/Changing' handlers
[22:07:40.7953366] 'Components/Changing' notification received: mediaBindingNavigator2.Text
[22:07:40.7953366] Notifying 1 'Components/Changed' handlers
[22:07:40.7953366] 'Components/Changed' notification received: mediaBindingNavigator2.Text
[22:07:40.7963361] Sending request: Transactions/Close: Cancel = False
[22:07:40.7973221] Transactions/Close took 00:00:00.0009933.
[22:07:40.7973221] Notifying 1 'Transactions/Closing' handlers
[22:07:40.7973221] Notifying 1 'Undo/UndoUnitAdded' handlers
[22:07:40.7973221] 'Undo/UndoUnitAdded' notification received: 62aa060d-3693-42d5-9986-819f26c5b264
[22:07:40.7973221] Notifying 1 'Transactions/Closed' handlers
[22:07:40.8003341] Updating selection in server process.
[22:07:40.8003341] Sending request: Selection/UpdateSelection
[22:07:40.8003341] [ACQ]: info: Microsoft.DotNet.DesignTools.Host.RemoteSelectionService[0]
[22:07:40.8003341] [ACQ]:       Attempting to update selection: 1 components, Replace
[22:07:40.8043510] [ACQ]: info: Microsoft.DotNet.DesignTools.Host.RemoteSelectionService[0]
[22:07:40.8043510] [ACQ]:       Made change: True
[22:07:40.8043510] Selection/UpdateSelection took 00:00:00.0046853.
[22:07:40.8043510] Notifying 1 'Selection/Changed' handlers
[22:07:40.8053509] Sending request: Properties/GetValue
[22:07:40.8103481] Properties/GetValue took 00:00:00.0046069.
[22:07:40.8113492] Sending request: Controls/GetParent
[22:07:40.8123471] Controls/GetParent took 00:00:00.0007074.
[22:07:40.8123471] Sending request: Controls/GetParent
[22:07:40.8123471] Controls/GetParent took 00:00:00.0006207.
[22:07:40.8123471] Sending request: Controls/GetParent
[22:07:40.8133471] Controls/GetParent took 00:00:00.0005641.
[22:07:40.8143548] Sending request: Commands/HasLockedControl
[22:07:40.8153551] Commands/HasLockedControl took 00:00:00.0005484.
[22:07:41.1534121] Sending request: Designers/GetDesignerVerbs
[22:07:41.1554152] Designers/GetDesignerVerbs took 00:00:00.0014788.
[22:07:41.1554152] Sending request: Designers/GetDesignerActionLists
[22:07:41.1564145] Designers/GetDesignerActionLists took 00:00:00.0011682.
[22:07:41.8184104] [ACQ]: Sending request to remove roots:
[22:07:41.8184104] [ACQ]:   - f1: 2 root(s).
[22:07:41.8184104] Sending request: Objects/RemoveObjectRoots
[22:07:41.8194139] Objects/RemoveObjectRoots took 00:00:00.0007642.

pedautreppe avatar Nov 16 '22 21:11 pedautreppe

Hi @pedautreppe. We have not yet implemented the BindingNavigator for .NET projects. .NET projects run in a separate process from Visual Studio. We'll take this comment as feedback that we should consider bringing the designer back. As far as creating the designer on your own, I would recommend waiting until @KlausLoeffelmann finishes his blog post (which I am currently editing) about creating control designers in .NET - the fact that there are two processes now involved does mean that it is substantially different to create control designers.

merriemcgaw avatar Nov 17 '22 02:11 merriemcgaw

Thanks @merriemcgaw for the feedback ! Yes indeed, bringing back the designer would be great. It helps a lot when dealing with BindingNavigator. By the way, it would also help to expose the different designers as public classes and not internal ones. Much easier when we need to extend one behavior ! ;-)

When the blog post is ready, can you also publish a link here ?

pedautreppe avatar Nov 17 '22 10:11 pedautreppe

I absolutely will. In fact, I think I will put up a pinned issue so that everyone can see it. We expect it in the month of December, but responses will be delayed after that for the holidays.

merriemcgaw avatar Nov 17 '22 23:11 merriemcgaw

By the way, it would also help to expose the different designers as public classes and not internal ones. Much easier when we need to extend one behavior!

Not sure if I know what you mean with that. Can you elaborate on that with an example?

KlausLoeffelmann avatar Nov 18 '22 00:11 KlausLoeffelmann

Sure !

Let's imagine I want to create my own BusinessTextBox that does include some business related stuff (I don't have a precise idea right now). My BusinessTextBox would inherit either from TextBox or maybe TextBoxBase. As a consequence, it would use in the designer either the TextBoxDesigner or the TextBoxBaseDesigner.

Now let's imagine that I need to add some behavior at design time (for instance adding some actions). And here I am stuck :

  • As the TextBoxDesigner and TextBoxBaseDesigner are both internal I cannot inherit from them
  • So if I create my own BusinessTextBoxDesigner, I would loose the default designer capabilities

So I can create my own designer to add the desired actions, but I cannot "add" that capability to an existing designer

pedautreppe avatar Nov 18 '22 08:11 pedautreppe

@merriemcgaw Hi, how is it going? We need this in order to switch completly to .NET7

deinok avatar Apr 20 '23 10:04 deinok

@merriemcgaw @deinok Hi there, we also need this issue resolved ASAP, we have junior developers unable to create controls, code-behind (one in particular), it's tremendously frustrating.

despiojo avatar Apr 20 '23 10:04 despiojo

We're taking a look at reprioritizing this effort, but the work itself will need to be done internally in our VS designer code. Because we have to run our VS Designer out of proc from Visual Studio the creation of designers has changed substantially. See this blog post for more details.

merriemcgaw avatar Apr 21 '23 22:04 merriemcgaw

One year later, I still can't see BindingNavigator in the toolbox and use it in the designer. Or is there at least a workaround that works?

Thanks in advance for any feedback.

AlessandroVaia avatar Nov 07 '23 14:11 AlessandroVaia

A work-around that works other than has issues when adding to the Toolbox in Visual Studio.

public sealed class CoreBindingNavigator : BindingNavigator
{
	public CoreBindingNavigator()
	{
		AddStandardItems();
	}

	/// <summary>
	/// Set Enable for add button
	/// </summary>
	public void AddButtonEnable(bool enable = false)
	{
		AddNewItem.Enabled = enable;
	}

	/// <summary>
	/// Set Enable for delete button
	/// </summary>
	public void RemoveButtonEnable(bool enable = false)
	{
		DeleteItem.Enabled = enable;
	}
	
	/// <summary>
	/// Remove default actions for delete and add buttons
	/// </summary>
	public void RemoveDefaultHandlers()
	{
		AddNewItem = null;
		DeleteItem = null;
	}
	
	/// <summary>
	/// Provide access to the add new button
	/// </summary>
	public ToolStripItem AddItemButton => Items["bindingNavigatorAddNewItem"]!;
	/// <summary>
	/// Provides access to the delete current row
	/// </summary>
	public ToolStripItem DeleteItemButton => Items["bindingNavigatorDeleteItem"]!;
	public ToolStripItem AboutItemButton => Items["bindingNavigatorAboutItem"]!;
}

karenpayneoregon avatar Feb 26 '24 15:02 karenpayneoregon