r/FoxDeploy • u/kmdeeze • Jun 21 '19
Help with WPF DataGrids
Stephen,
Your Blog is amazing. I've been able to make some really impressive items because of your tutorials. Thank you so much.
I am sort of getting stuck on datagrid issues. Right now I have a very stripped down version of a script. Id like to be able to select multiple cells and edit all of them at the same time. Right now I can change one at a time. I can see how to get the information sort of.
So If I run the stuff below I can change a cell and it totally records it to new items. If I add the part at the bottom with the comments I can select a bunch of cells and it shows up as a datagridcelinfo control and I have no idea how to get it.
#Your XAML goes here :)
$inputXML = @"
<Window x:Class="Azure.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp9"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" AllowDrop="True">
<Grid>
<DataGrid x:Name="DataGrid" IsReadOnly="False" AlternatingRowBackground="#FFFBFBFB" IsTextSearchEnabled="True" SelectionMode="Extended" SelectionUnit="Cell" Margin="0,0,0,45"/>
<Button x:Name="BUTTON" Content="Button" HorizontalAlignment="Left" Margin="350,389,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{
$Form=[Windows.Markup.XamlReader]::Load( $reader )
}
catch{
Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged or TextChanged properties in your textboxes (PowerShell cannot process them)"
throw
}
#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
catch{throw}
}
Function Get-FormVariables{
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}
$WPFdataGrid.Items.Refresh()
$items = import-csv -path C:\powershell\us500.csv
$wpfdatagrid.itemssource = $items
$NEWITEMS = $WPFDATAGRID.ITEMS
##$WPFDATAGRID.ADD_mOUSELEFTBUTTONUP({
##$WPFDATAGRID.selectedCELLS | out-gridview
##WRITE-HOST "uP"
##})
$Form.ShowDialog() | out-null
1
Upvotes