Hey guys!
I have the following strunctire:
PaneToolWindow -> SplitPane -> ContentPane.
How can I disable ability to close window? Setting AllowClose to false doesn't help because I still can close it via close button in Start Task Bar.
I also tried to set e.Cancel to true for Closing event but in this case after docking the window I am getting extra pane tool window (as it was not closed due to setting e.Cancel flag to true).
Hello Maksim,Thank you for contacting Infragistics Developer Support.
The close button existing on the PaneToolWindows that are used for the floating panes in the XamDockManager are not affected by the close-related properties on the panes. This is because by default, the XamDockManager uses a WPF Window with its WindowStyle property set to ToolWindow to wrap the floating panes. So, this close button is essentially the same as the one that exists in your typical WPF window, in other words.
To remove this close button, I would recommend handling the ToolWindowLoaded event of the XamDockManager. This event will allow you to retrieve the PaneToolWindow as it loads via the e.Window property of the event arguments. From here, you can set the PaneToolWindow’s UseOsNonClientArea property to “false,” which will cause the window provide the chrome for the window itself, rather than using its built-in template to display the window chrome that includes the close button. This will essentially hide the close button, and prevent closure of the PaneToolWindow.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Andrew,
I am already using this property set to false because I am using custom style for header. For undocked view of the PaneToolWindow there is no the close button.
The issue is I still can close the window via Context Menu:
It looks like setting window.AllowClose to false makes this option disable... OK. But there is one more way to close the window:
And i was not able to disable this ability. "May be it's possible to do via Win32 functions?" I thought.
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
var hwnd = new WindowInteropHelper(paneToolWindow).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
But the Handle property return null. It looks like our PaneToolWindow doesn't inherit thw Window.
So I also tried to handling the Closing event and set args.Cancel to true:
private void PaneToolWindowOnClosing(object sender, CancelEventArgs cancelEventArgs) { cancelEventArgs.Cancel = true; }
And at first sight it works, but... right after I am docking the window from the indocked state, this event occurs, I am setting Cancel to true and I am getting docked content pane and empty PaneToolWindow:
Do you have any ides? I really need your help guys!
Thank you.
Hello Maksim,
I am personally rather unsure of the custom style that you are using for the PaneToolWindow in this case, but I would like you to take a look at the sample project that I have attached.
In the attached sample, using a mix of the AllowClose and CloseButtonVisibility properties of the ContentPanes set to "False" and "Collapsed," respectively, and also using the e.Window.UseOSNonClientArea property of the ToolWindowLoaded event of the XamDockManager being set to false, I am personally unable to close any panes when they are floating.
I did notice the disabled close button visibility on the ToolWindow with these settings, and so I have also included a solution to remove that as well. This solution is to include the default style for ToolWindow, which the PaneToolWindow derives from. This style, and its dependencies can commonly be found in the PrimitivesGeneric.xaml file at the following directory:
C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\Windows.
By modifying this default style, you can remove the close button entirely, rather than having it show up as disabled. After doing so, I am unable to reproduce a situation in which the PaneToolWindow and its containing panes are able to be closed.
The sample project is attached to this post. I hope it helps you.
Regarding the PaneToolWindowOnClosing method that you had mentioned, I would not really recommend this, as the PaneToolWindow needs to close when docking the panes, and this event will prevent it from doing so. Instead, I would recommend following the procedures shown in the sample project that is attached to see if they will work for you on this matter.
Please let me know if you have any other questions or concerns on this matter.
Thank you for attetion to my matter!
Your sample works for me too.. It look s like on my project somewhere enabled some property for dock manager that is responsible for separate window for PaneToolWindow.. like on my screenshot:
Do you know hot it could be enabled?
I have been researching the ability to actually remove the "X" in the task bar tile, but as of yet, I have not found anything that says you can remove this, as it is a built-in windows function. However, even when clicking this close button, I see that the PaneToolWindow still remains open. Are you seeing a different behavior? The best recommendations that I have found so far are that you should use the ShowInTaskBar property set to "false" as this exists on all Window derivations, and so it exists on the XamDockManager's PaneToolWindow.
Regarding the events for docking/undocking via button click, I imagine you must be invoking some sort of command to programmatically dock the panes that exist in your PaneToolWindow. I am under the assumption that you are likely using the ContentPaneCommands.ToggleDockedState command. If this is the case, I would recommend handling the ContentPane's ExecutedCommand event, and check the event arguments for this ToggleDockedState command. You can also cast the sender of that event to a ContentPane and check the PaneLocation property of that pane to determine whether or not the pane was floated or docked. The code for this could look like the following, inside of the ExecutedCommand event handler.
if (e.Command == ContentPaneCommands.ToggleDockedState){ ContentPane cp = sender as ContentPane; var x = cp.PaneLocation;
if(x == PaneLocation.Floating) { //FLOATED } else { //DOCKED }}
For the drag and drop events, I would recommend utilizing the PaneDragStarting and PaneDragEnded events of the XamDockManager.
Regarding the double click event, I am assuming you wish to have the double click event on the PaneToolWindow, and so I would recommend hooking this event in the ToolWindowLoaded event of the XamDockManager, by hooking into the e.Window.MouseDoubleClick event. This should allow you to catch a double click on the floating window.
I jave foung a property for this: ShowInTaskBar. But I'm not sure if setting to false is acceptable for out clients.
Andrew, do you have an event that I can handle during docking/undocking of window via button/drag&drop/double click?