Microsoft® Surface® Live Stream Code Sample

ive Stream enables businesses to engage their customers face-to-face using the most recent and relevant Twitter™, Flickr®, and RSS newsfeeds.

C# (5.9 MB)
 
 
 
 
 
4.3 Star
(4)
6,647 times
Add to favorites
4/19/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
<s:SurfaceUserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:s="http://schemas.microsoft.com/surface/2008"
                      xmlns:controls="clr-namespace:LiveStream.Controls"
                      xmlns:helpers="clr-namespace:LiveStream.Helpers" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"
                      xmlns:props="clr-namespace:LiveStream.Properties"
                      xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:Microsoft_Surface_Presentation_Generic="clr-namespace:Microsoft.Surface.Presentation.Generic;assembly=Microsoft.Surface.Presentation.Generic" mc:Ignorable="d" x:Class="LiveStream.Controls.RiverContent.LargeNews"
                      d:DesignWidth="325" d:DesignHeight="270"
                      xmlns:feeditems="clr-namespace:FeedProcessor.FeedItems;assembly=FeedProcessor">
  <s:SurfaceUserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/LiveStream;component/Resources/Converters.xaml"/>
      </ResourceDictionary.MergedDictionaries>
      <Style x:Key="SurfaceScrollViewerStyle" TargetType="{x:Type s:SurfaceScrollViewer}">
        <Setter Property="Elasticity" Value="0.4,0.4"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type s:SurfaceScrollViewer}">
              <Grid HorizontalAlignment="Stretch" Margin="{TemplateBinding Padding}" VerticalAlignment="Stretch" OpacityMask="{x:Null}" Background="{TemplateBinding Background}">
                <VisualStateManager.VisualStateGroups>
                  <VisualStateGroup x:Name="TopShadowStates">
                    <VisualStateGroup.Transitions>
                      <VisualTransition GeneratedDuration="0:0:0.1"/>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="HideTopShadow">
                      <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.OpacityMask).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="ShadowContainer">
                          <SplineColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                      </Storyboard>
                    </VisualState>
                    <VisualState x:Name="ShowTopShadow"/>
                  </VisualStateGroup>
                  <VisualStateGroup x:Name="BottomShadowStates">
                    <VisualStateGroup.Transitions>
                      <VisualTransition GeneratedDuration="0:0:0.1"/>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="HideBottomShadow">
                      <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="ShadowContainer">
                          <SplineColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                      </Storyboard>
                    </VisualState>
                    <VisualState x:Name="ShowBottomShadow"/>
                  </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border x:Name="PART_ConsistentViewport">
                  <Border x:Name="PART_ElasticBorder" Background="{TemplateBinding Background}">
                    <Grid x:Name="ShadowContainer" Background="{x:Null}">
                      <Grid.OpacityMask>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                          <GradientStop Color="#00000000" Offset="0"/>
                          <GradientStop Offset="1" Color="#00000000"/>
                          <GradientStop Color="Black" Offset="0.92"/>
                          <GradientStop Color="Black" Offset="0.08"/>
                        </LinearGradientBrush>
                      </Grid.OpacityMask>
                      <ScrollContentPresenter OpacityMask="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" VerticalAlignment="Top"/>
                    </Grid>
                  </Border>
                </Border>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
      <feeditems:NewsFeedItem x:Key="DesignData"
                              Date="6/21/2010 10:23:00 AM"
                              Author="Eric Havir"
                              Title="Surface at WIND Mobile stores in Canada"/>
    </ResourceDictionary>
  </s:SurfaceUserControl.Resources>
  <Grid d:DataContext="{DynamicResource DesignData}">
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="FailureStates">
        <VisualState x:Name="Success"/>
        <VisualState x:Name="Fail">
          <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_failLabel">
              <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
            </ObjectAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_richTextBox">
              <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
            </ObjectAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border Background="{DynamicResource ForegroundBrush}"/>
    <Grid Margin="5">
      <Border Background="{DynamicResource ThemeBrush}" CornerRadius="35,0,0,0" />
      <Grid Margin="20,10,20,45">
        <Viewbox x:Name="_scalingContentContainer" VerticalAlignment="Top" />
        <Border x:Name="_fixedContentContainer">
          <Grid x:Name="_contentRoot">
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="{x:Static props:Resources.News}" FontSize="36" FontFamily="{DynamicResource HeaderFont}" />
            <s:SurfaceScrollViewer Grid.Row="1" x:Name="_scroller" x:FieldModifier="private" HorizontalScrollBarVisibility="Disabled" Style="{DynamicResource SurfaceScrollViewerStyle}">
              <i:Interaction.Behaviors>
                <helpers:ScrollViewerInScatterViewItemBehavior/>
                <helpers:ShadowScrollBehavior x:Name="_shadowScroll"/>
              </i:Interaction.Behaviors>
              <StackPanel>
                <TextBlock Text="{Binding Title}" FontSize="18" FontFamily="{DynamicResource HeaderFont}" TextWrapping="Wrap" LineStackingStrategy="BlockLineHeight" LineHeight="22" />
                <StackPanel Orientation="Horizontal" Opacity=".5">
                  <TextBlock FontSize="10" Foreground="{DynamicResource ForegroundBrush}" Text="{x:Static props:Resources.Posted}" />
                  <TextBlock FontSize="10" Foreground="{DynamicResource ForegroundBrush}">
                    <TextBlock.Text>
                      <Binding Path="Date" StringFormat="{x:Static props:Resources.DateFormat}" />
                    </TextBlock.Text>
                  </TextBlock>
                  <StackPanel Orientation="Horizontal" Visibility="{Binding Path=Author, Converter={StaticResource VisibilityConverter}}">
                    <TextBlock FontSize="10" Foreground="{DynamicResource ForegroundBrush}" Text="{x:Static props:Resources.By}" />
                    <TextBlock TextTrimming="CharacterEllipsis" FontSize="10" Foreground="{DynamicResource ForegroundBrush}" Text="{Binding Path=Author}" />
                  </StackPanel>
                </StackPanel>
                <Grid Margin="0,15,0,0">
                  <RichTextBox x:Name="_richTextBox" x:FieldModifier="private" IsReadOnly="True" Cursor="Arrow" FontSize="12" BorderThickness="0" Padding="0" Background="Transparent" Foreground="{DynamicResource ForegroundBrush}" FontFamily="{DynamicResource MainFont}" Margin="-4,0"/>
                  <TextBlock x:Name="_failLabel" x:FieldModifier="private" Visibility="Collapsed" FontSize="12" TextWrapping="Wrap" Text="{x:Static props:Resources.NewsFailed}" />
                </Grid>
              </StackPanel>
            </s:SurfaceScrollViewer>
          </Grid>
        </Border>
      </Grid>
      <s:SurfaceButton x:Name="_closeBtn" x:FieldModifier="private" ContactTapGesture="Close_ContactTapGesture" Style="{DynamicResource CloseButtonStyle}" VerticalAlignment="Top" Foreground="{DynamicResource ForegroundBrush}" Background="{DynamicResource ForegroundBrush}" HorizontalAlignment="Right"/>
      <s:SurfaceButton x:Name="_flipBtn" x:FieldModifier="private" ContactTapGesture="Flip_ContactTapGesture" Style="{DynamicResource FrontFlipButtonStyle}" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
    </Grid>
  </Grid>
</s:SurfaceUserControl>