Skip to content

Instantly share code, notes, and snippets.

@altrive
Created April 4, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altrive/45b2b92282458eae7aa2 to your computer and use it in GitHub Desktop.
Save altrive/45b2b92282458eae7aa2 to your computer and use it in GitHub Desktop.
Sample code to use Exxtended WPF Toolkit PropertyGrid
#Require -Version 5.0
$ErrorActionPreference = "Stop"
Use-NuGetPackage -PackageId Extended.Wpf.Toolkit -Verbose #Require PSNuGet package <https://github.com/altrive/PSNuGet>
function Main
{
class AAA
{
[int] $AAA
[string] $BBB
[string] $CCC
}
$obj = [AAA]::new()
$obj.AAA = 2
$obj.BBB = "test"
Show-PropertyGridView $obj
}
function Show-PropertyGridView
{
param (
[parameter(Mandatory)]
$InputObject
)
#Load WPF assembly for Powershell.exe
Add-Type -AssemblyName PresentationFramework
#Create WPF Window object
$xaml = @'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid>
<xctk:PropertyGrid x:Name="propertyGrid">
</xctk:PropertyGrid>
</Grid>
</Window>
'@
$window = [Windows.Markup.XamlReader]::Parse($xaml)
$window.Topmost = $true
#Bind Data
$propertyGrid = $window.FindName("propertyGrid")
$propertyGrid.SelectedObject = $InputObject
$task = $window.Dispatcher.InvokeAsync({
$window.ShowDialog() > $null
})
$task.Wait() > $null
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment