O'Reilly Forums: Visual Studio 2013 Professional - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Visual Studio 2013 Professional Differences in xaml and C# code between 2012 and 2103 VS

#1 User is offline   sgmurchie 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 11-May 14
  • Gender:Male
  • Location:Omaha, NE

Posted 11 May 2014 - 10:30 AM

I just purchased this book and am working through the first chapter. I have Windows 8.1 and Visual Studio Professional 2013. I noticed that the xaml code is slightly different between what I am seeing in VS2013 and what I am seeing in the book. Is there much difference in the actual code writing and syntax between the 2 VS versions with relation to C# and xaml?
I could download the VS 2012 express editions but I would like to be able to go through this book with VS 2013 Pro if that is possible.

Thanks,
0

#2 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 749
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 12 May 2014 - 06:03 AM

You're right, Microsoft made changes in Visual Studio 2013 that do affect the code, and unfortunately it was released after our book went to press. I strongly recommend installing Visual Studio 2012 for Windows 8. You can install it alongside 2013. You can download it here: http://www.microsoft...s.aspx?id=30664

This only affects the Windows 8 projects. You can use VS2013 for Windows Desktop for all of the desktop projects (starting partway through Chapter 2).
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

#3 User is offline   sgmurchie 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 11-May 14
  • Gender:Male
  • Location:Omaha, NE

Posted 12 May 2014 - 06:22 AM

View PostAndrewStellman, on 12 May 2014 - 06:03 AM, said:

You're right, Microsoft made changes in Visual Studio 2013 that do affect the code, and unfortunately it was released after our book went to press. I strongly recommend installing Visual Studio 2012 for Windows 8. You can install it alongside 2013. You can download it here: http://www.microsoft...s.aspx?id=30664

This only affects the Windows 8 projects. You can use VS2013 for Windows Desktop for all of the desktop projects (starting partway through Chapter 2).



Thanks for your reply. I have downloaded and installed Visual Studio 2012 for Windows 8. I will go back and redo chapter 1 using the 2012 edition.
0

#4 User is offline   Chris K Seattle 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 08-August 14

Posted 08 August 2014 - 11:26 AM

Andrew, have you updated the text for VS2013 yet? I really don't want to have 2 IDE's running on my machine if I can avoid it. My error is:
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in Save the Humans.exe but was not handled in user code

WinRT information: Cannot find a Resource with the Name/Key Bold [Line: 62 Position: 61]

Additional information: The text associated with this error code could not be found.



Cannot find a Resource with the Name/Key Bold [Line: 62 Position: 61]

If there is a handler for this exception, the program may be safely continued.


Here is my .cs:
using Save_the_Humans.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Animation;

// The Basic Page item template is documented at http://go.microsoft..../?LinkId=234237

namespace Save_the_Humans
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
public sealed partial class MainPage : Page
{
Random random = new Random();
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();

/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}

/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}


public MainPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}

/// <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="sender">
/// The source of the event; typically <see cref="NavigationHelper"/>
/// </param>
/// <param name="e">Event data that provides both the navigation parameter passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
/// a dictionary of state preserved by this page during an earlier
/// session. The state will be null the first time a page is visited.</param>
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}

/// <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="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
}

#region NavigationHelper registration

/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
/// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}

#endregion

private void startButton_Click(object sender, RoutedEventArgs e)
{
AddEnemy();
}

private void AddEnemy()
{
ContentControl enemy = new ContentControl();
enemy.Template = Resources["EnemyTemplate"] as ControlTemplate;
AnimateEnemy(enemy, 0, playArea.ActualWidth - 100, "(Canvas.Left)");
AnimateEnemy(enemy, random.Next((int)playArea.ActualHeight - 100), random.Next((int)playArea.ActualHeight - 100), "(Canvas.Top)");
playArea.Children.Add(enemy);
}

private void AnimateEnemy(ContentControl enemy, double from, double to, string propertyToAnimate)
{
Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever };
DoubleAnimation animation = new DoubleAnimation()
{
From = from,
To = to,
Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6)))
};
Storyboard.SetTarget(animation, enemy);
Storyboard.SetTargetProperty(animation, propertyToAnimate);
storyboard.Children.Add(animation);
storyboard.Begin();
}
}
}


and my XAML:

<Page
x:Name="pageRoot"
x:Class="Save_the_Humans.MainPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Save_the_Humans"
xmlns:common="using:Save_the_Humans.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">Save the Humans</x:String>
<ControlTemplate x:Key="EnemyTemplate" TargetType="ContentControl">
<Grid>
<Ellipse Fill="#FF0881F9" Height="100" Stroke="Black" Width="100"/>
</Grid>
</ControlTemplate>
</Page.Resources>

<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160"/>
<ColumnDefinition/>
<ColumnDefinition Width="160"/>
</Grid.ColumnDefinitions>
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition/>
<RowDefinition Height="160"/>
</Grid.RowDefinitions>

<!-- Back button and page title -->
<Grid Grid.ColumnSpan="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
</Grid>
<Button x:Name="startButton" Content="Start!" HorizontalAlignment="Center" Grid.Row="2" VerticalAlignment="Center" Click="startButton_Click"/>
<StackPanel Grid.Column="2" Orientation="Vertical" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox TextWrapping="Wrap" Text="Avoid These" FontWeight="{ThemeResource Bold}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<ContentControl Content="ContentControl" HorizontalAlignment="Center" VerticalAlignment="Center" Template="{StaticResource EnemyTemplate}"/>
</StackPanel>
<ProgressBar Grid.Column="1" Grid.Row="2" Height="20"/>
<Canvas x:Name="playArea" Grid.Row="1" Grid.ColumnSpan="3">
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFEE1818" Offset="0"/>
<GradientStop Color="#FF98E849" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
<StackPanel x:Name="human" Orientation="Vertical">
<Ellipse Fill="White" Height="10" Width="10" />
<Rectangle Fill="White" Height="25" Width="10" />
</StackPanel>
<TextBlock x:Name="gameOverText" Canvas.Left="417" TextWrapping="Wrap" Text="Game Over" Canvas.Top="200" FontFamily="Arial Black" FontSize="100" FontWeight="Bold" FontStyle="Italic"/>
<Rectangle x:Name="target" Height="50" Canvas.Left="885" Canvas.Top="140" Width="50" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<CompositeTransform Rotation="45"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Grid>
</Page>

0

#5 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 749
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 09 August 2014 - 07:52 AM

You should absolutely feel comfortable with multiple versions of Visual Studio on the same machine -- it's designed to work that way. I currently have VS2005, VS2008, VS2010, VS2012, and VS2013 installed on the same box. You'll be able to go back to VS2013 Professional once you get to the Windows Forms projects in the middle of Chapter 2, and you'll be able to stay with it for the next 400 pages or so.

The code you posted looks like it was created in VS2013 -- the line of C# code that says "public sealed partial class MainPage : Page" would be different for a project created in VS2012 (it would say "MainPage : Save_the_Humans.Common.LayoutAwarePage" instead).

I pasted your code into VS2013 (not VS2012) and got the same error you did: "Cannot find a Resource with the Name/Key Bold [Line: 62 Position: 61]". I went to line 62 and at position 61 I saw this in the XAML code:
FontWeight="{ThemeResource Bold}" 

When I deleted it, the code you posted worked.

Also, yes, I'm working on the VS2013 update for the book. It's a lot of work, and I'm trying to be very careful to get everything right. I've asked O'Reilly to release the update as errata instead of doing a whole new edition -- so if you bought the ebook from oreilly.com (not the printed version from a bookstore, obviously -- not sure how it works with Kindle versions) I'm pretty sure you'll see the update appear on your download page automatically once I'm done and we go through production. I'll also put out the first three chapters as a free PDF for people with the current printing, that way they can do the projects in Chapters 1 and 2 in Visual Studio 2013 from the PDF and jump back into the book for the next 400 pages.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

#6 User is offline   Philip Vasta 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 09-August 14

Posted 09 August 2014 - 06:51 PM

View PostAndrewStellman, on 09 August 2014 - 07:52 AM, said:

You should absolutely feel comfortable with multiple versions of Visual Studio on the same machine -- it's designed to work that way. I currently have VS2005, VS2008, VS2010, VS2012, and VS2013 installed on the same box. You'll be able to go back to VS2013 Professional once you get to the Windows Forms projects in the middle of Chapter 2, and you'll be able to stay with it for the next 400 pages or so.

The code you posted looks like it was created in VS2013 -- the line of C# code that says "public sealed partial class MainPage : Page" would be different for a project created in VS2012 (it would say "MainPage : Save_the_Humans.Common.LayoutAwarePage" instead).

I pasted your code into VS2013 (not VS2012) and got the same error you did: "Cannot find a Resource with the Name/Key Bold [Line: 62 Position: 61]". I went to line 62 and at position 61 I saw this in the XAML code:
FontWeight="{ThemeResource Bold}" 

When I deleted it, the code you posted worked.

Also, yes, I'm working on the VS2013 update for the book. It's a lot of work, and I'm trying to be very careful to get everything right. I've asked O'Reilly to release the update as errata instead of doing a whole new edition -- so if you bought the ebook from oreilly.com (not the printed version from a bookstore, obviously -- not sure how it works with Kindle versions) I'm pretty sure you'll see the update appear on your download page automatically once I'm done and we go through production. I'll also put out the first three chapters as a free PDF for people with the current printing, that way they can do the projects in Chapters 1 and 2 in Visual Studio 2013 from the PDF and jump back into the book for the next 400 pages.


That's great news! I just bought the book, and though I'm very early in the book, I can already tell it's filling in a lot of the gaps in my knowledge. I'm glad to hear it will hopefully be updated for VS2013. Universal apps seem to be the way forward, and I'm really excited to learn Windows development as the whole modern Microsoft platform comes together.

This post has been edited by Philip Vasta: 09 August 2014 - 06:52 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users