[Code template] WPF window registration

We’re starting to publish reusable code templates for common io.Connect patterns. The idea: small, self-contained snippets you can adapt to reproduce issues or test integration scenarios without stripping down your whole app. More context here: Templates to help troubleshooting and support

Minimal WPF Window snippet

Registers a WPF window as an io.Connect tab window with Channel support and a TextBox for testing keyboard input:

var view = new Window
{
    Width = 250,
    Height = 250
};

var panel = new StackPanel { Orientation = System.Windows.Controls.Orientation.Vertical, Margin = new Thickness(10) };
panel.Children.Add(new TextBox { Text = "Dynamic TextBox", Margin = new Thickness(5) });
view.Content = panel;

await glue_.GlueWindows.RegisterWindow(view,
    new GlueWindowOptions().WithTitle("MyWindow").WithType(GlueWindowType.Tab).WithChannelSupport(true)
        .WithPlacement(new GlueWindowScreenPlacement
        {
            Bounds = new GlueWindowBounds(700, 10, 300, 300)
        }));

Registering WPF Apps via the App Manager

If you’re using RegisterWPFAppAsync to register WPF child windows as io.Connect apps (for Layout persistence, launcher visibility, etc.), enable message forwarding via the window options modifier:

glue_.AppManager.RegisterWPFAppAsync<WpfApp, MyWpfState, MyWpfContext>(builder =>
    builder.WithTitle("WPF in WinForms")
        .WithWindowOptionsModifier(gwo => gwo.WithWPFMessageForwarding(true)));

Focus Tracking

If you need to track which io.Connect window has focus (e.g. as a workaround for Form.ActiveForm being null after embedding in io.Connect), subscribe to WindowFocusChangedEvent:

glue42_.GlueWindows.SubscribeEvents<WindowFocusChangedEvent>(((@event, descriptor) =>
{
    Debug.WriteLine($"{(@event.Data ? "got" : "lost")} focus: {@event.WindowId}");
}));

Docs

More templates coming. Let us know what scenarios you’d want next.