Код: Выделить всё
public MainWindow()
{
InitializeComponent();
DataContext = new MainWindowViewModel();
this.WhenAnyValue(window => window.Bounds)
.Subscribe(bounds =>
{
var vm = (MainWindowViewModel)this.DataContext;
vm.WindowResized(bounds);
vm.WindowInfo = $"Position: {bounds.Position.X}, {bounds.Position.Y} | Size: {bounds.Width} x {bounds.Height}";
});
}
Код: Выделить всё
public class MainWindowViewModel : ReactiveObject
{
private double _width;
private double _height;
private double _x;
private double _y;
public double Width
{
set => this.RaiseAndSetIfChanged(ref _width, value);
}
public double Height
{
set => this.RaiseAndSetIfChanged(ref _height, value);
}
public double X
{
set => this.RaiseAndSetIfChanged(ref _x, value);
}
public double Y
{
set => this.RaiseAndSetIfChanged(ref _y, value);
}
public void WindowResized(Rect bounds)
{
Width = bounds.Width;
Height = bounds.Height;
X = bounds.Position.X;
Y = bounds.Position.Y;
}
private string _windowInfo;
public string WindowInfo
{
set => this.RaiseAndSetIfChanged(ref _windowInfo, value);
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... the-window