Advertisement
Guest User

Powershell WPF DataTemplate _click

a guest
Mar 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $global:CurrentLocation = Get-Location
  2.  
  3. function SetMainWindow($Picture, $HeaderText, $Text)
  4. {
  5.     #region Controls
  6.     $tMain = $WindowMain.FindName("tMain")
  7.     $tHeader = $WindowMain.FindName("tHeader")
  8.     $iMain = $WindowMain.FindName("iMain")
  9.     $MainBorder = $WindowMain.FindName("MainBorder")
  10.     #endregion
  11.    
  12.     $WindowMain.FindName("MainBackground").Background = "#FF076A80"
  13.    
  14.     $ScreenRes = [System.Windows.SystemParameters]::PrimaryScreenWidth
  15.     if ($ScreenRes)
  16.     {
  17.         $WindowMain.Left = $Screenres - $WindowMain.Width
  18.     }
  19.    
  20. }
  21.  
  22. $readerMain = (New-Object System.Xml.XmlNodeReader $xamlMain)
  23. $WindowMain = [Windows.Markup.XamlReader]::Load($readerMain)
  24.  
  25. #region Controls
  26. $btnTest = $WindowMain.FindName("btnTest")
  27. $listBox = $WindowMain.FindName("listBox")
  28. $label = $WindowMain.FindName("label")
  29. #endregion
  30.  
  31. $WindowMain.FindName("btnTest").Add_click({
  32.         $label.Content = "Normal button clicked"
  33.     })
  34.  
  35. $WindowMain.FindName("btnRemoveOSCollEntry").Add_click({
  36.         $label.Content = "DataTemplate button clicked"
  37.     })
  38.  
  39. $DataSource = @()
  40. $obj = New-Object PSCustomObject
  41. $obj | Add-Member -MemberType 'NoteProperty' -Name Title -Value "Test title"
  42. $DataSource += $obj
  43. $listBox.ItemsSource = $DataSource
  44.  
  45. $WindowMain.ShowDialog() | Out-Null
  46. Exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement