public class MyWindow : Window{}
[STAThread] public static void Main(string[] args){}
[STAThread] public static void Main(string[] args) { var win = new MyWindow { Width = 350, Height = 350}; var grid = new Grid(); var text = new TextBox {Text = "my text"}; grid.Children.Add(text); win.Content = grid; }
app.MainWindow = win; app.MainWindow.Show(); app.Run();
Task.Run(async () => { await Task.Delay(1000); app.Dispatcher.Invoke((Action) delegate { app.Shutdown(); }); }); ;
[STAThread] public static void Main(string[] args) { var app = new Application(); var win = new MyWindow { Width = 350, Height = 350}; var grid = new Grid(); var text = new TextBox {Text = "my text"}; grid.Children.Add(text); win.Content = grid; app.MainWindow = win; app.MainWindow.Show(); Task.Run(async () => { await Task.Delay(1000); app.Dispatcher.Invoke((Action) delegate { app.Shutdown(); }); }); app.Run(); }
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ConsoleApplication1" mc:Ignorable="d" Title="MyWindow" Height="450" Width="800"> <Grid> <Label Content="Label" /> </Grid> </Window>
XmlTextReader r = new XmlTextReader("MyWin.xaml"); var win = XamlReader.Load(r) as Window;
[STAThread] public static void Main(string[] args) { var app = new Application(); XmlTextReader r = new XmlTextReader("MyWin.xaml"); var win = XamlReader.Load(r) as Window; app.MainWindow = win; app.MainWindow.Show(); Task.Run(async () => { await Task.Delay(1000); app.Dispatcher.Invoke((Action) delegate { app.Shutdown(); }); }); app.Run(); }
Source: https://habr.com/ru/post/437642/