Skip to content

Instantly share code, notes, and snippets.

@JuanKRuiz
Created October 29, 2012 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanKRuiz/3973990 to your computer and use it in GitHub Desktop.
Save JuanKRuiz/3973990 to your computer and use it in GitHub Desktop.
Parte 7 - Tutorial App Lector RSS
<Application
x:Class="RSSJuanK4Blog.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RSSJuanK4Blog">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="Title-Main-Style" TargetType="TextBlock">
<Setter Property="FontSize" Value="45"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="Margin" Value="10" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="Logo-Style" TargetType="Image">
<Setter Property="Margin" Value="10"/>
</Style>
<Style x:Key="Title-Post-Style" TargetType="TextBlock"
BasedOn="{StaticResource Title-Main-Style}" >
<Setter Property="FontSize" Value="30"/>
<Setter Property="TextTrimming" Value="WordEllipsis"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
<Style x:Key="WebView-Style" TargetType="WebView">
<Setter Property="Margin" Value="10,0"/>
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="CacheMode" Value="BitmapCache"/>
</Style>
<Style x:Key="Lista-Posts-Style" TargetType="ListView">
<Setter Property="Margin" Value="10,0"/>
</Style>
<Style x:Key="Image-Post-List" TargetType="Image">
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="120"/>
</Style>
<Style x:Key="Title-PostList-Style" TargetType="TextBlock">
<Setter Property="Width" Value="350"/>
<Setter Property="Height" Value="Auto"/>
<Setter Property="Margin" Value="0,5,5,10"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="TextTrimming" Value="WordEllipsis"/>
</Style>
<Style x:Key="Summary-PostList-Style" TargetType="TextBlock"
BasedOn="{StaticResource Title-PostList-Style}">
<Setter Property="FontSize" Value="14"/>
</Style>
<DataTemplate x:Key="Post-List-ItemTemplate">
<StackPanel Orientation="Horizontal">
<Image Style="{StaticResource Image-Post-List}"
Source="{Binding ImgUri}"/>
<StackPanel>
<TextBlock TextWrapping="Wrap"
Text="{Binding Title}"
Style="{StaticResource Title-PostList-Style}"/>
<TextBlock TextWrapping="Wrap"
Text="{Binding Summary}"
Style="{StaticResource Summary-PostList-Style}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="RSSJuanK4Blog.View.RssMainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RSSJuanK4Blog.View"
xmlns:common="using:RSSJuanK4Blog.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:vm="using:RSSJuanK4Blog.ViewModel">
<Page.Resources>
<x:String x:Key="AppName">Blog Ideas de un Conejo</x:String>
<vm:RssMainViewModel x:Key="ViewModel" x:Name="ViewModel"
FeedUrlString="http://blogs.msdn.com/b/juank/rss.aspx"/>
</Page.Resources>
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="pageTitle"
Grid.Column="1" Grid.Row="0"
Text="{StaticResource AppName}"
Style="{StaticResource Title-Main-Style}"
/>
<Image Style="{StaticResource Logo-Style}" Source="ms-appx:///Assets/img/ideas-logo.png"/>
<TextBlock Grid.Column="2" Grid.Row="0"
Text="{Binding ElementName=lvwBlogPosts, Path=SelectedValue.Title}"
Style="{StaticResource Title-Post-Style}" />
<WebView x:Name="wvBlogContent"
Grid.Column="2" Grid.Row="1"
vm:RssMainViewModel.HtmlString="{Binding ElementName=lvwBlogPosts, Path=SelectedValue.Content}"
Visibility="Visible"
Style="{StaticResource WebView-Style}" />
<ListView x:Name="lvwBlogPosts" Grid.ColumnSpan="2" Grid.Row="1"
Style="{StaticResource Lista-Posts-Style}"
ItemsSource="{Binding Articles}"
ItemTemplate="{StaticResource Post-List-ItemTemplate}" >
</ListView>
</Grid>
</common:LayoutAwarePage>
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
namespace RSSJuanK4Blog.View
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
public sealed partial class RssMainView : RSSJuanK4Blog.Common.LayoutAwarePage
{
public RssMainView()
{
this.InitializeComponent();
this.Loaded += ViewModel.ViewLoadHandler;
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
protected override void SaveState(Dictionary<String, Object> pageState)
{
}
}
}
using RSSJuanK4Blog.Common;
using RSSJuanK4Blog.Model;
using RSSJuanK4Blog.Util;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace RSSJuanK4Blog.ViewModel
{
public class RssMainViewModel : BindableBase
{
private ArticleList _articles = new ArticleList();
public ArticleList Articles
{
get { return _articles; }
set
{
SetProperty(ref _articles, value);
}
}
private string _feedUrlString;
public string FeedUrlString
{
get { return _feedUrlString; }
set
{
SetProperty(ref _feedUrlString, value);
}
}
public async Task Initialize()
{
Articles = await RSSHelper.GetArticleListFromFeedAsync(this.FeedUrlString);
}
public async void ViewLoadHandler(object o, RoutedEventArgs e)
{
var tmpView = o as FrameworkElement;
if (tmpView != null)
tmpView.DataContext = this;
if (!string.IsNullOrWhiteSpace(FeedUrlString))
await Initialize();
}
public static string GetHtmlString(DependencyObject obj)
{
return (string)obj.GetValue(HtmlStringProperty);
}
public static void SetHtmlString(DependencyObject obj, string value)
{
obj.SetValue(HtmlStringProperty, value);
}
// Using a DependencyProperty as the backing store for HtmlString. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HtmlStringProperty =
DependencyProperty.RegisterAttached("HtmlString",
typeof(string), typeof(RssMainViewModel),
new PropertyMetadata("", HtmlStringChanged)
);
public static void HtmlStringChanged(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
{
var wb = sender as WebView;
if (wb != null)
wb.NavigateToString((string)arg.NewValue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment