Experience the power of XAML :)
So the PDC is over and from what I see and hear .... Its been a smashing HIT!!! Hip Hip Hooray!!
One really good resource to get your hands dirty with Windows Presentation Foundation is the guided Tour by Tim Sneath.
Previously I had put up some code for a RSS reader but it becomes so much simpler using XAML. How so?
---------------------------------------------------------------------------------------
<DockPanel xmlns="https://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="https://schemas.microsoft.com/winfx/xaml/2005" Margin="10">
<DockPanel.Resources>
<XmlDataProvider x:Key="Blog" Source="https://blogs.msdn.com/tims/rss.aspx" />
<DataTemplate x:Key="TitleTemplate">
<TextBlock Text="{Binding XPath=title}"/>
</DataTemplate>
</DockPanel.Resources>
<Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/title}"
FontSize="24" FontWeight="Bold" DockPanel.Dock="Top" />
<Label Content="{Binding Source={StaticResource Blog}, XPath=/rss/channel/description}" FontSize="18" DockPanel.Dock="Top" />
<DockPanel DataContext="{Binding Source={StaticResource Blog}, XPath=/rss/channel/item}" >
<ListBox DockPanel.Dock="Left" ItemsSource="{Binding}" ItemTemplate="{StaticResource TitleTemplate}" IsSynchronizedWithCurrentItem="True" />
<Frame Source="{Binding XPath=link}" Width="Auto" />
</DockPanel>
</DockPanel>
(Above code taken from the Guided Tour To WPF- Tim Sneath)
-------------------------------------------------------------------------------
Thats all... Surprised!!...Thats the power of WPF. aka Avalon :)
Here we make use of data binding to present the different entries of a blog.
Let me explain it in brief. We have a XmlDataProvider which is the source/provider of the data that will be displayed. A dataTemplate is provided which describes how to present an item - in this case we use a textBlock whose Text is bound to the title of an item. This goes as part of the resources tag.
Next we address the actual presentation/layout of the data. We have 2 labels which display the channel title and description.
Below this we have a DockPanel for easier presentation - a ListBox on the Left and a Frame on the Right. Each ListBoxItem is displayed based on the DataTemplate. Also each item is bound to the Items in the data source - in this case the blog.
A more detailed explanation of Data Binding is provided at MSDN
So you see programming gets simpler by the day... And you cant get better than WPF ;)
Comments
- Anonymous
June 09, 2009
PingBack from http://jointpainreliefs.info/story.php?id=1057