cnromaine
8/19/2013 - 11:52 AM

From http://www.drdobbs.com/windows/building-gui-applications-in-powershell/240049898?pgno=2The Search-Twitter function returns an array of

From http://www.drdobbs.com/windows/building-gui-applications-in-powershell/240049898?pgno=2The Search-Twitter function returns an array of PowerShell objects with properties from the Twitter query. From that data, we extract the text of the tweet and the URL pointing to the Twitter user's profile image. If you look closely at the PowerShell code here, you'll see no loops at all. ShowUI supports WPF's data binding capabilities as well as its templating features.( Secrets to Building a WPF Application in Windows PowerShellhttp://msdn.microsoft.com/en-us/magazine/hh288074.aspx )

Import-Module .\ShowUI 
function Search-Twitter ($q) { 
$wc = New-Object Net.Webclient 
$url = http://search.twitter.com/search.rss?q=$q
     ([xml]$wc.downloadstring($url)).rss.channel.item | select * 
}
   
$ws = @{
     WindowStartupLocation = "CenterScreen"
     Width = 500
     Height = 500 
}

New-Window @ws -Show {
     ListBox -Background Black -ItemTemplate {
         Grid -Columns 55, 300 {
         Image -Column 0 -Name Image -Margin 5
         TextBlock -Column 1 -Name Title `
             -Margin 5 `
             -Foreground White `
             -TextWrapping Wrap
     } | ConvertTo-DataTemplate -Binding @{
             "Image.Source" = "image_link"
             "Title.Text" = "title"
     }
   } -ItemsSource (Search-Twitter PowerShell)
}