Created
February 8, 2017 19:42
-
-
Save anonymous/d8adea2c8bf1a63e248a3b19d3e1e69e to your computer and use it in GitHub Desktop.
PowerShell GUI - DataGridHyperlinkColumn
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
Add-Type -AssemblyName PresentationFramework | |
Import-Module SQLPS -Cmdlet Invoke-Sqlcmd | |
#Build the GUI | |
[xml]$UIXaml = @" | |
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
Name="UI" Title="UIWindow" Height="550" Width="850"> | |
<Grid > | |
<StackPanel Orientation="Vertical"> | |
<Grid> | |
<Menu> | |
<MenuItem Header="Services" Height="25"> | |
<MenuItem Name="miServiceList" Header="Service List" Height="25"/> | |
<MenuItem Name="miAddService" Header="Add Service" Height="25"/> | |
</MenuItem> | |
</Menu> | |
</Grid> | |
<UserControl Height="500" Name="userControl" Background="LightGray" ScrollViewer.VerticalScrollBarVisibility="Auto"> | |
</UserControl> | |
</StackPanel> | |
</Grid> | |
</Window> | |
"@ | |
[xml]$ServiceListXaml =@" | |
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="ServiceListPage" Width="800" Height="500" Background="LightGray" HorizontalAlignment="Left" VerticalAlignment="Top"> | |
<StackPanel Orientation="Vertical"> | |
<Label Name="lblServiceList" Content="Services:" FontWeight="Bold" Margin="10,10,10,0"></Label> | |
<DataGrid Name="dgServiceList" AutoGenerateColumns="False" Height="300" Margin="10,10,10,0"> | |
<DataGrid.Columns> | |
<DataGridHyperlinkColumn Header="Status" Binding="{Binding Status}" CanUserSort="True" Visibility="Visible" Width="140" > | |
</DataGridHyperlinkColumn> | |
<DataGridTextColumn Header="Service Name" Binding="{Binding Name}" CanUserSort="True" Visibility="Visible" Width="250" > | |
<DataGridTextColumn.ElementStyle> | |
<Style> | |
<Setter Property="TextBlock.TextWrapping" Value="Wrap" /> | |
</Style> | |
</DataGridTextColumn.ElementStyle> | |
</DataGridTextColumn> | |
<DataGridTextColumn Header="Display Name" Binding="{Binding DisplayName}" CanUserSort="True" Visibility="Visible" Width="250" > | |
<DataGridTextColumn.ElementStyle> | |
<Style> | |
<Setter Property="TextBlock.TextWrapping" Value="Wrap" /> | |
</Style> | |
</DataGridTextColumn.ElementStyle> | |
</DataGridTextColumn> | |
<DataGridTemplateColumn Width="100"> | |
<DataGridTemplateColumn.CellTemplate> | |
<DataTemplate> | |
<Button Name="btnEdit" Content="Edit" Width="60"></Button> | |
</DataTemplate> | |
</DataGridTemplateColumn.CellTemplate> | |
</DataGridTemplateColumn> | |
</DataGrid.Columns> | |
</DataGrid> | |
</StackPanel> | |
</Grid> | |
"@ | |
#region AtlasUI Controls | |
$UIReader=(New-Object System.Xml.XmlNodeReader $UIXaml) | |
$UIWindow=[Windows.Markup.XamlReader]::Load( $UIReader ) | |
$userControl = $UIWindow.FindName("userControl") | |
$serviceListMenuItem =$UIWindow.FindName("miServiceList") | |
$addServiceMenuItem = $UIWindow.FindName("miAddService") | |
#endregion | |
#region VendorList COntrols | |
$ServiceListReader=(New-Object System.Xml.XmlNodeReader $ServiceListXaml) | |
$ServiceListWindow=[Windows.Markup.XamlReader]::Load($ServiceListReader) | |
$serviceListPage = $ServiceListWindow.FindName("ServiceListPage") | |
$serviceListDataGrid = $ServiceListWindow.FindName("dgServiceList") | |
$arrServiceList = New-Object System.Collections.ArrayList | |
#endregion | |
#region VendorList Page Code | |
$serviceListMenuItem.Add_Click({ | |
$userControl.Content = $serviceListPage | |
Get-VendorList | |
}) | |
Function Get-VendorList() | |
{ | |
try | |
{ | |
$arrServiceList = get-service | Where-Object {$_.Status -eq "Stopped"} | |
$serviceListDataGrid.ItemsSource = @($arrServiceList) | |
} | |
catch | |
{ | |
Write-Host $_.Exception.Message | |
} | |
} | |
#endregion | |
$UIWindow.ShowDialog() | Out-Null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment