Created
April 4, 2015 10:59
-
-
Save altrive/45b2b92282458eae7aa2 to your computer and use it in GitHub Desktop.
Sample code to use Exxtended WPF Toolkit PropertyGrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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