Link to home
Start Free TrialLog in
Avatar of GrahamSkan
GrahamSkanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

XML error not understood

Trying to jump from decades of classic VB to .Net and WPF, I am working through this Microsoft tutorial: "Walkthrough: My First WPF Desktop Application", which is here: https://msdn.microsoft.com/en-gb/library/mt270964.aspx.

Nearing the end, I am getting this error, which doesn't appear to fit the actual code.
'The 'Grid' start tag on line 37 position 10 does not match the end tag of 'StackPanel'. Line 63, position 15.' XML is not valid.      

Note: the line numbers in the following code snippet are the same as those in the VS2015 IDE
<Page x:Class="ExpenseReportPage"
	  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	  xmlns:local="clr-namespace:ExpenseIt"
	  mc:Ignorable="d" 
	  d:DesignHeight="300" d:DesignWidth="300"
	  Title="ExpenseIt – View Expense">
	<Grid Margin="10,0,10,10">
		<!--Templates to display expense report data-->
		<Grid.Resources>
			<!-- Reason item template -->
			<DataTemplate x:Key="typeItemTemplate">
				<Label Content="{Binding XPath=@ExpenseType}"/>
			</DataTemplate>
			<!-- Amount item template -->
			<DataTemplate x:Key="amountItemTemplate">
				<Label Content="{Binding XPath=@ExpenseAmount}"/>
			</DataTemplate>
		</Grid.Resources>

		<Grid.Background>
			<ImageBrush ImageSource="watermark.png" />
		</Grid.Background>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="230" />
			<ColumnDefinition />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition />
		</Grid.RowDefinitions>
		<Label Grid.Column="1" Style="{StaticResource headerTextStyle}">
			Expense Report For:
		</Label>
		<Grid Margin="10" Grid.Column="1" Grid.Row="1">
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
				<ColumnDefinition />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition />
			</Grid.RowDefinitions>

			<!-- Name -->
			<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Orientation="Horizontal">
				<Label Style="{StaticResource labelStyle}">Name:</Label>
				<Label Style="{StaticResource labelStyle}" Content="{Binding XPath=@Name}"></Label>
			</StackPanel>

			<!-- Department -->
			<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal">
				<Label Style="{StaticResource labelStyle}">Department:</Label>
				<Label Style="{StaticResource labelStyle}" Content="{Binding XPath=@Department}"></Label>
			</StackPanel>

			<Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" VerticalAlignment="Top"   
			   HorizontalAlignment="Left">
				<!-- Expense type and Amount table -->
				<DataGrid ItemsSource="{Binding XPath=Expense}" ColumnHeaderStyle="{StaticResource columnHeaderStyle}" AutoGenerateColumns="False" RowHeaderWidth="0" >

					<DataGrid.Columns>
						<DataGridTextColumn Header="ExpenseType" Binding="{Binding XPath=@ExpenseType}"  />
						<DataGridTextColumn Header="Amount" Binding="{Binding XPath=@ExpenseAmount}" />
					</DataGrid.Columns>

				</DataGrid>
			</Grid>
		</Grid>
	</Grid>
</Page>

Open in new window

Avatar of FaheemAhmadGul
FaheemAhmadGul
Flag of United Kingdom of Great Britain and Northern Ireland image

I am not sure if it will help your problem or not, but the following XAML is not giving any error on my machine.
This XAML is almost exactly the same as yours except that I have taken out Style="{StaticResource labelStyle}"  from line 50 and 51, 56 and 57 I have also taken out ColumnHeaderStyle="{StaticResource columnHeaderStyle}"  from line 63 in your code and ImageSource="watermark.png"  from line 24 (primarily because I do not have these StaticResources on my machine)

<Page x:Class="ExpenseReportPage"
	  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	  xmlns:local="clr-WpfApplication2"
	  mc:Ignorable="d" 
	  d:DesignHeight="300" d:DesignWidth="300"
	  Title="ExpenseIt – View Expense">
    <Grid Margin="10,0,10,10">
        <!--Templates to display expense report data-->
        <Grid.Resources>
            <!-- Reason item template -->
            <DataTemplate x:Key="typeItemTemplate">
                <Label Content="{Binding XPath=@ExpenseType}"/>
            </DataTemplate>
            <!-- Amount item template -->
            <DataTemplate x:Key="amountItemTemplate">
                <Label Content="{Binding XPath=@ExpenseAmount}"/>
            </DataTemplate>
        </Grid.Resources>

        <Grid.Background>
            <!-- ImageSource="watermark.png" -->
            <ImageBrush  />
        </Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="230" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label Grid.Column="1" >
            Expense Report For:
        </Label>
        <Grid Margin="10" Grid.Column="1" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!-- Name -->
            <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Orientation="Horizontal">
                <Label  >Name:</Label>
                <Label  Content="{Binding XPath=@Name}"></Label>
            </StackPanel>

            <!-- Department -->
            <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal">
                <Label  >Department:</Label>
                <Label  Content="{Binding XPath=@Department}"></Label>
            </StackPanel>

            <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" VerticalAlignment="Top"   
			   HorizontalAlignment="Left">
                <!-- Expense type and Amount table -->
                <DataGrid ItemsSource="{Binding XPath=Expense}"  AutoGenerateColumns="False" RowHeaderWidth="0" >

                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ExpenseType" Binding="{Binding XPath=@ExpenseType}"  />
                        <DataGridTextColumn Header="Amount" Binding="{Binding XPath=@ExpenseAmount}" />
                    </DataGrid.Columns>

                </DataGrid>
            </Grid>
        </Grid>
    </Grid>
</Page>

Open in new window

Avatar of GrahamSkan

ASKER

Hi FaheemAhmadGul,
It's been a long time since you last posted a question that I could help with.

Thank you for your comment.
In accordance with the tutorial, that portion of the code has just been modified to link to an XmlDataProvider from another part of the project. It was that change that initiated the error.

I saved and closed the project after posting the question. After reopening, the design-time XML error has gone away, but I do get an XMLParseException when I try to run the project. I am still trying to find exactly where that is and whether it is the same problem problem in another guise

This is the error

System.Windows.Markup.XamlParseException was unhandled
Message: An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '29' and line position '55'.
ASKER CERTIFIED SOLUTION
Avatar of FaheemAhmadGul
FaheemAhmadGul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. That is a great help. I will be able to see where I have gone wrong.
Thank you