Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Сценарии для Windows

Модерирует : KLASS, IFkO

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

YuS_2



Silver Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
#requires -Version 5.1
Using Assembly PresentationFramework
Using Namespace System.ComponentModel
Using Namespace System.Windows.Threading
 
[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) {
        $this.SetServices($S)
    }
 
    [void] SetServices($Services) {
        if ($this.Services -cne $Services) {
            $this.Services = $Services
            $this.NotifyPropertyChanged('Services')
        }
    }
}
 
$Window = [Windows.Markup.XamlReader]::Parse($xaml)
$data = {get-service}
[ViewModel] $VM = [ViewModel]::new((&$data))
$Window.DataContext = $VM
 
function update() {
    $VM.SetServices((&$data))
}
 
$timer = new-object dispatchertimer -prop @{
    Interval = new-object timespan 0, 0, 0, 0, 2000
}
 
     
$Window.add_loaded({
    update
    $timer.start()
})
 
$timer.add_tick({
    if ($true){update}
})
 
$Window.showdialog() | out-null
$timer.stop()

Всего записей: 3218 | Зарегистр. 03-02-2009 | Отправлено: 23:36 13-09-2019 | Исправлено: YuS_2, 23:56 13-09-2019
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Сценарии для Windows


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru