iNNOKENTIY21
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: #requires -Version 5.1 using Assembly PresentationFramework using namespace System.ComponentModel [string]$xaml = @" <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="Главное окно" Height="480" Width="640"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="30"/> </Grid.RowDefinitions> <ListView Grid.Row="0" ItemsSource="{Binding Services}"> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Header="Start type" DisplayMemberBinding="{Binding StartType}" /> <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Status}" /> </GridView> </ListView.View> </ListView> </Grid> </Window> "@ class ViewModel : INotifyPropertyChanged { Hidden [PropertyChangedEventHandler] $PropertyChanged Hidden [Void] NotifyPropertyChanged([String] $propertyName) { If ($this.PropertyChanged -cne $null) { $this.PropertyChanged.Invoke($this, (New-Object PropertyChangedEventArgs $propertyName)) } } [Void] add_PropertyChanged([PropertyChangedEventHandler] $propertyChanged) { $this.PropertyChanged = [Delegate]::Combine($this.PropertyChanged, $propertyChanged) } [Void] remove_PropertyChanged([PropertyChangedEventHandler] $propertyChanged) { $this.PropertyChanged = [Delegate]::Remove($this.PropertyChanged, $propertyChanged) } $Services ViewModel() { $S = Get-Service $this.SetServices($S) } [void] SetServices($Services) { if ($this.Services -cne $Services) { $this.Services = $Services $this.NotifyPropertyChanged('Services') } } } $Window = [Windows.Markup.XamlReader]::Parse($xaml) [ViewModel] $VM = [ViewModel]::new() $Window.DataContext = $VM $Window.ShowDialog() |
|