O'Reilly Forums: Chapter: 1 Save The Humans - O'Reilly Forums

Jump to content

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

Chapter: 1 Save The Humans System.Windows.Markup.XamlParseException

#1 User is offline   Cdelorenzo 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 06-January 14

Posted 06 January 2014 - 06:47 PM

Hi!

I'm new to programming in C# and followed the first chapter Save the Humans with the WPF version provided via the website. I have combed through my code line by line looking for the exception or error that may be causing the following problem. I'm using Visual studio 2012 on Windows 7. Any Assistance on how to find and resolve this issue would be greatly appreciated I'm enjoying the book and hope to finish this section soon and continue learning.

Cheers,
Corey

Attached Image: error.jpg
0

#2 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 713
  • 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 07 January 2014 - 09:48 PM

Happy to help if I can. This sometimes happens when the XAML for the window has a typo or an error. Can you post the XAML for your window so I can have a look?
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

#3 User is offline   Cdelorenzo 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 06-January 14

Posted 08 January 2014 - 05:14 PM

Hey,

Thanks in advance for all your here is the XAML Code.

<Window x:Class="Save_the_Humans.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Save the Humans" Height="700" Width="1000">
    <Window.Resources>
        <ControlTemplate x:Key="EnemyTemplate" TargetType="{x:Type ContentControl}">
            <Grid>
                <Ellipse Fill="Red" Stroke="Black" Height="100" Width="100"/>
            </Grid>
        </ControlTemplate>
    </Window.Resources>

    <Grid x:Name="grid" Background="Black">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="140"/>
            <ColumnDefinition/>
            <ColumnDefinition Width="160"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="150"/>
        </Grid.RowDefinitions>

        <Button x:Name="startButton" 
                Content="Start!" 
                Grid.Row="1"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" Click="startButton_Click"/>
        <ProgressBar x:Name="progressBar" Grid.Column="1" Grid.Row="1" Height="20"/>
        <Canvas x:Name="playArea" Grid.ColumnSpan="3" MouseLeave="playArea_MouseLeave" MouseMove="playArea_MouseMove">
            <Canvas.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA640EE" Offset="0"/>
                    <GradientStop Color="#FF87EE40" Offset="1"/>
                </LinearGradientBrush>
            </Canvas.Background>
            <StackPanel x:Name="human" Orientation="Vertical" MouseDown="human_MouseDown">
                <Ellipse Fill="White" Height="10" Stroke="Black" Margin="0,0,0.021,0" Width="10"/>
                <Rectangle Fill="White" Height="25" Stroke="Black" Margin="0,0,0.021,0" Width="10"/>
            </StackPanel>
            <TextBlock x:Name="gameOverText" Canvas.Left="71" TextWrapping="Wrap" Text="Game Over" 
                       Canvas.Top="80" FontFamily="Arial" FontSize="100" FontWeight="Bold" FontStyle="Italic"/>
            <Rectangle x:Name="target" Height="50" Canvas.Left="725" Stroke="Black" Canvas.Top="255" 
                       Width="50" RenderTransformOrigin="0.5,0.5" MouseEnter="target_MouseEnter">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="45"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </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>

        <StackPanel Grid.Column="2" Orientation="Vertical" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBlock 
        		TextWrapping="Wrap" 
        		Text="Avoid These" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
            <ContentControl Content="ContentControl" Template="{DynamicResource EnemyTemplate}"/>
        </StackPanel>

    </Grid>
</Window>

Attached thumbnail(s)

  • Attached Image: xaml_1of2.jpg
  • Attached Image: xaml_2of2.jpg

This post has been edited by Cdelorenzo: 08 January 2014 - 05:19 PM

0

#4 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 713
  • 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 January 2014 - 07:56 AM

Hmm, it doesn't look like there's anything wrong with that XAML. I was able to copy it and paste it into a working project and it worked just fine. Can you post your C# code from MainWindow.xaml.cs?

Also, you definitely won't have any problems moving onto Chapter 2 while we figure this out.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
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