Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Data Binding in Windows Presentation Foundation

Download

Right click “Save as…”

Tim Sneath shows how to build a basic RSS reader using Windows Presentation Foundation (formerly codenamed “Avalon”) in just 14 lines of code, using the data binding and XAML features that are central to this new technology.

Tag:

Follow the Discussion

  • ChadkChadk excuse me - do you has a flavor?
    In the video, you set ListBox ItemSource="{Binding}", that dosen't make sense to me. You need to explain that one abit more. But once again, a GREAT video. Really helped me alot! Keep up that good work Cool
  • OkobojiOkoboji Kevin Moore, Program Manager, WPF, WinFX
    Fast-forward to 7:55 in the video.

    Tim sets the DataContext on the DockPanel to be a binding to the items in the RSS feed.

    Then the nested ListBox doesn't need to say anything except to Bind. It gets its data from its parent DataContext.

  • Tyler BrownTyler Brown Bullets change governments far surer than votes.
    Is it just me... or is no one else able to view this video? I can't seem to find a link to view it anywhere. The view link on the front page simply directs me to this thread.
  • Tyler,

    I just tested it out and it seemed to be fine. Try going directly to the URL for the WMV:
    http://channel9.msdn.com/Screencasts/DataBindinginWPF.wmv

    Best wishes,

    Tim
  • Tyler BrownTyler Brown Bullets change governments far surer than votes.
    Thanks Tim, thats got it working now.
  • Here's the source code, based on the Sept CTP bits:

    <StackPanel xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" Margin="10">
       <StackPanel.Resources>
          <XmlDataSource x:Key="Blog" Source="http://blogs.msdn.com/tims/rss.aspx"/>

          <DataTemplate x:Key="TitleTemplate">
             <TextBlock TextContent="{Binding XPath=title}"/>
          </DataTemplate>
       </StackPanel.Resources>

       <Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/title}" FontSize="24" FontWeight="Bold" />     
      
       <Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/description}" FontSize="18" />

       <DockPanel DataContext="{Binding Source={StaticResource Blog}, XPath=/rss/channel/item}" >
          <ListBox DockPanel.Dock="Left" ItemsSource="{Binding}" ItemTemplate="{StaticResource TitleTemplate}" IsSynchronizedWithCurrentItem="True" />
          <TextBox Name="Contents" Text="{Binding XPath=description}" Wrap="True" Width="Auto" />
       </DockPanel>
    </StackPanel>

  • Tim,

    After attending the PDC, I've installed the Sept CTP bits.  I've copied your sample (above) and it doesn't work in XAMLPAD.  Am I missing something? 

    Here's a couple keywords that its "upset" about:

    XmlDataSource   --> changed to XmlDataProvider

    Wrap  --> removed as it just won't work.

     

    Then another quick question...  What code could I add to this sample to automatically get new RSS content and have the lists automatically update?  I was trying to do things declartively... I was trying to set the source of the XmlDataProvider to be bound to a TextBox.  But to no avail.  Do I need to revert to code behind?

     

    Joe

  • We've experienced some pain trying to make the various demos we saw at PDC05 and on various tech evang blogs work on the PDC05 "The Goods" bits because of changes to the class libs/schemas since the WinFX Beta was released. With some effort it has been possible to figure out the changes and/or find updated demos.

    However, it would be helpful if the various tech evangelists were to post updated demos that work on the PDC05 bits.

    Thanks!

    Erik

     

  • For Wrap="True" use the following:

    TextWrapping="Wrap"

    And for TextContent="..." just use Text="..."

    Wink
  • Databining without codebehind or compliling is so sweet http://slyi.members.winisp.net/rss.xaml (works as of the WPF Nov run-time using static rss on my root).

    If only we didnt need to compile for events, roll on wpf/e 
  • I got it to work with the Feb CTP. See updated code below:

    <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Margin="10">
       <StackPanel.Resources>
          <XmlDataProvider x:Key="Blog" Source="http://blogs.msdn.com/tims/rss.aspx"/>

          <DataTemplate x:Key="TitleTemplate">
             <TextBlock Text="{Binding XPath=title}"/>
          </DataTemplate>
       </StackPanel.Resources>
       <Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/title}" FontSize="24" FontWeight="Bold" />      
      
       <Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/description}" FontSize="18" />
       <DockPanel DataContext="{Binding Source={StaticResource Blog}, XPath=/rss/channel/item}" >
          <ListBox DockPanel.Dock="Left" ItemsSource="{Binding}" ItemTemplate="{StaticResource TitleTemplate}" IsSynchronizedWithCurrentItem="True" />
          <TextBox Name="Contents" Text="{Binding XPath=description}" TextWrapping="Wrap" Width="Auto" />
       </DockPanel>
    </StackPanel>

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.