Prototype test.
MainWindow:
Only 3 row:
A: Title
B: Logo Image
C: Selector (Row of Buttons and SearchBox)
Structure
1. Global, Define the Closing Protocol, and make the Protocol definition Visible Everywhere
namespace NasaImages.Widgets
{
public delegate void NotifyParentDelegate(ClosingEventArgs closingArgs);
public class ClosingEventArgs : EventArgs
{
public ClosingEventArgs(string message) { Message = message; }
public string Message { get; set; }
}
}
2. MainWindow, define the Delegate Protocol Handler
void ClosingDelegateEventHandler(ClosingEventArgs closingArgs)
{
TbCurrentWidgetName.Text = "Main: Selector *- " + closingArgs.Message;
WidgetSelector.Visibility = Visibility.Visible;
int lastIndex = MainWindowMainGrid.Children.Count - 1;
// should not be 0, who knows? May be passing the index to the child, to be sure.
MainWindowMainGrid.Children.RemoveAt(lastIndex);
}
3. Child Widget: to be ADDed, to the MainWindow Grid's Children List
Example
namespace NasaImages.Widgets
{
public sealed partial class TvMasterView : UserControl
{
// Widget Closing Protocol
public event NotifyParentDelegate parentDelegate = null;
and Exit Method
private async void BtnCloseMe_Click(object sender, RoutedEventArgs e)
{
TMDBAPI.httpClient.CancelPendingRequests();
await Task.Delay(100);
if (parentDelegate != null)
{
ClosingEventArgs myEventArg = new("TvMaster");
parentDelegate(myEventArg); // remove me from the Grid's children list
}
else
{
// persistent, just collapse
this.Visibility = Visibility.Collapsed;
}
}
4: MainWindow, Add the Child Widget to the MainGrid's Children List
Example
WidgetSelector.Visibility = Visibility.Collapsed;
var tvMaster = new TvMasterView();
// set parent as delegate
tvMaster.parentDelegate += new NotifyParentDelegate(ClosingDelegateEventHandler);
MainWindowMainGrid.Children.Add(tvMaster);
Grid.SetRow(tvMaster, 1);
tvMaster.Visibility = Visibility.Visible;
tvMaster.SetContentWith(item.id);
_____________________________
That is IT.
Compose the MainWindow with Widgets, on demand.
All those Widgets, itself, is a composition of smaller widgets.