Allow parent window to be set before initialized - #264
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a fluent API to set a PhotinoWindow’s parent window prior to native instantiation, enabling multi-window apps (e.g., photino.Blazor) to associate child windows with a parent for better OS-level grouping behavior.
Changes:
- Makes the internal
_dotNetParentfield mutable (wasreadonly). - Adds
SetParent(PhotinoWindow parent)with a guard to prevent changes after native instantiation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /// <summary> | ||
| /// Gets the reference to parent PhotinoWindow instance. | ||
| /// This property can only be set in the constructor and it is optional. |
There was a problem hiding this comment.
The XML doc for Parent says it "can only be set in the constructor", but _dotNetParent is now mutable and can be set via SetParent(...). Please update the Parent documentation to reflect that it can be set either in the constructor or via SetParent (before native instantiation).
| /// This property can only be set in the constructor and it is optional. | |
| /// This property is optional and can be set in the constructor or via <c>SetParent(...)</c> | |
| /// before native instantiation. |
| /// <param name="parent">The window that should be used as this window's parent</param> | ||
| public PhotinoWindow SetParent(PhotinoWindow parent) | ||
| { | ||
| Log($".SetParent({parent.Id})"); |
There was a problem hiding this comment.
SetParent logs parent.Id without validating parent. Since PhotinoWindow allows parent = null in the constructor, calling SetParent(null) will currently throw a NullReferenceException while logging. Please either (a) explicitly disallow null by throwing a clear exception before logging, or (b) support clearing the parent and log safely (e.g., handle null in the log message).
| Log($".SetParent({parent.Id})"); | |
| Log($".SetParent({(parent is null ? "null" : parent.Id.ToString())})"); |
This PR adds the ability to set the parent window on a new window before it's instantiated. This allows applications built with photino.Blazor to have new windows with parents.
photino.Blazor utilizes dependency injection when creating new windows, so each window is effectively a separate Blazor app. This creates the undesired UI effect where one application can look like multiple. i.e. on Windows, multi-window Photino Blazor applications will not combine under one taskbar item.
A check was put in place to make sure that a native instance of the current window does not already exist. As the parent is used as a startup parameter, this mirrors checks put in for other pre-instantiated parameters such as chromeless.