Data Binding in Windows Presentation Foundation
- Posted: Sep 06, 2005 at 5:07 PM
- 54,935 Views
- 11 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
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.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
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.
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
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
TextWrapping="Wrap"
And for TextContent="..." just use Text="..."
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"/>
<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