Last active
December 15, 2015 23:29
-
-
Save khellang/5340732 to your computer and use it in GitHub Desktop.
Sample usage for WPF Script Pack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- First example | |
public class MyApplication : Application | |
{ | |
private readonly Window _mainWindow; | |
public MyApplication(Window mainWindow) | |
{ | |
_mainWindow = mainWindow; | |
} | |
protected override void OnStartup(StartupEventArgs e) | |
{ | |
_mainWindow.Show(); | |
} | |
} | |
var wpf = Require<Wpf>(); | |
wpf.RunInSTA(() => | |
{ | |
// Load the View from XAML | |
var view = wpf.LoadXaml("CalculatorView.xaml"); | |
// Set the ViewModel | |
view.DataContext = new CalculatorViewModel(); | |
// Create a new Window | |
var mainWindow = new Window { Content = view, SizeToContent = SizeToContent.WidthAndHeight }; | |
// Create a new Application | |
var application = new MyApplication(mainWindow); | |
// Run the Application | |
application.Run(); | |
}); | |
// --- Second example, higher level API | |
var wpf = Require<Wpf>(); | |
wpf.RunApplication("CalculatorView.xaml", new CalculatorViewModel()); | |
// --- Third example, creates a new ViewModel | |
var wpf = Require<Wpf>(); | |
wpf.RunApplication<CalculatorViewModel>("CalculatorView.xaml"); | |
// --- Fourth example, finds a View based on convention (i.e. CalculatorViewModel -> CalculatorView) | |
wpf.RunApplication(new CalculatorViewModel()); | |
// --- Last example, creates a new ViewModel and find View based on convention | |
wpf.RunApplication<CalculatorViewModel>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment