connect-wpf
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||
#!markdown ## Connect to the WPF app First, let's start the WPF app and connect to it. #!pwsh Start-Process -NoNewWindow dotnet run #!csharp #!connect named-pipe --kernel-name wpf --pipe-name InteractiveWpf #!markdown ## Formatter (Rendering) #!csharp #!wpf #!dispatcher using System.Windows.Media; App.MainWindow.Background = new SolidColorBrush(Colors.Fuchsia); App.MainWindow.Background #!csharp #!wpf #!dispatcher using System.Windows.Media; using System.Windows.Controls; using System.Windows; var grid = (Grid)App.MainWindow.Content; grid.Background = new SolidColorBrush(Colors.CadetBlue); grid #!markdown ## View Model Stuff Create and apply a new view model to the main window. #!csharp #!wpf using System.ComponentModel; public class TestViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private string _text = "Notebook Initial Value"; public string Text { get => _text; set { if (_text != value) { _text = value; PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(Text))); } } } } var vm = new TestViewModel(); #!dispatcher App.MainWindow.DataContext = vm; #!markdown Update the value on the data bound property. #!csharp #!wpf vm.Text = "Value changed!" #!markdown ## Dispatcher stuff Demonstate enabling and disabling running code on the dispatcher. #!csharp #!wpf #!dispatcher --enabled true //This should work App.MainWindow.Title = "Done correctly"; #!dispatcher --enabled false //This is expected to fail App.MainWindow.Title = "Not so much";