From e1b2ac56977b08eba8ca19d1bd3168a983f79a1f Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 22 Feb 2017 18:31:35 +0300 Subject: [PATCH] Add a way to pass view model for the main window --- src/Avalonia.Controls/AppBuilderBase.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/AppBuilderBase.cs b/src/Avalonia.Controls/AppBuilderBase.cs index b098c270a5..97de093a59 100644 --- a/src/Avalonia.Controls/AppBuilderBase.cs +++ b/src/Avalonia.Controls/AppBuilderBase.cs @@ -115,13 +115,16 @@ namespace Avalonia.Controls /// Starts the application with an instance of . /// /// The window type. - public void Start() + /// A delegate that will be called to create a data context for the window (optional). + public void Start(Func dataContextProvider = null) where TMainWindow : Window, new() { Setup(); BeforeStartCallback(Self); var window = new TMainWindow(); + if (dataContextProvider != null) + window.DataContext = dataContextProvider(); window.Show(); Instance.Run(window); }