For the complete documentation index, see llms.txt. This page is also available as Markdown.

Data Sources

Data sources allow you to load data a single time and use it with multiple desktop widgets. This provides better performance than loading the data in each widget. It also provides data binding support for WPF components.

To register a data source, use the Register-CommanderDataSource cmdlet. The following data source loads computer performance information every 5 seconds.

Register-CommanderDataSource -Name 'ComputerInfo' -LoadData {
   $Stats = Get-NetAdapterStatistics
   $NetworkDown = 0
   $Stats.ReceivedBytes | Foreach-Object { $NetworkDown += $_ }

   $NetworkUp = 0
   $Stats.SentBytes | Foreach-Object { $NetworkUp += $_ }

   @{
       CPU = Get-CimInstance Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object -Expand Average
       Memory = (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue
       NetworkUp = $NetworkUp / 1KB
       NetworkDown = $NetworkDown / 1KB
   }
} -RefreshInterval 5

To use this data source with a desktop widget, use the -DataSource parameter for a custom widget. Every time the data source is updated, the WPF custom widget is notified and loads UI components.

This example creates a small, grey bar that formats and displays the computer information.

New-CommanderDesktop -Widget @(
   New-CommanderDesktopWidget -LoadWidget {
       [xml]$Form = Get-Content C:\Users\adamr\Desktop\test.xaml -Raw
       $XMLReader = (New-Object System.Xml.XmlNodeReader $Form)
       [Windows.Markup.XamlReader]::Load($XMLReader)
   } -Height 200 -Width 1400 -Top 20 -Left 100 -DataSource 'ComputerInfo'
}

The XAML can take advantage of binding to the hashtable created by the data source.

This produces a widget that looks like this.

Last updated