ParserError: Unknown element: Button
Last post 05-07-2008 7:18 AM by Bill Reiss. 6 replies.
Sort Posts:
05-05-2008 10:38 PM
ParserError: Unknown element: Button

I'm sure this is a simple problem, but I've spent all day fighting it.

I'm trying to instantiate silverlight from a xaml file.  I can create a grid, a canvas, text, etc, but whenever I try to add a Button, I get:

 
Silverlight error message
ErrorCode: 2007
ErrorType: ParserError
Message: Unknown element: Button.
XamlFile: myxaml.xaml
Line: 28
Position: 80

The xaml code is as follows:

<Canvas
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="Black" x:Name="root" Width="280" Height="330"
    >

    <Canvas Background="AliceBlue" Width="260" Height="310" Margin="10">
     
      <TextBlock TextAlignment="Center" Width="260">Let's make a calculator!</TextBlock>
      <TextBox Width="220" Grid.Column="2" Margin="20,20,10,10" TextAlignment="Right"></TextBox>

            <Grid Width="220" Height="250" Background="green" Margin="20,50">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="55" />
          <ColumnDefinition Width="55" />
          <ColumnDefinition Width="55" />
          <ColumnDefinition Width="55" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
          <RowDefinition Height="50"/>
          <RowDefinition Height="50"/>
          <RowDefinition Height="50"/>
          <RowDefinition Height="50"/>
          <RowDefinition Height="50"/>
        </Grid.RowDefinitions>

        <Button Content="1" Width="40" Height="40" Grid.Column="0" Grid.Row="0"></Button>
        <Button Content="2" Width="40" Height="40" Grid.Column="1" Grid.Row="0"></Button>
        <Button Content="3" Width="40" Height="40" Grid.Column="2" Grid.Row="0"></Button>

        <Button Content="4" Width="40" Height="40" Grid.Column="0" Grid.Row="1"></Button>
        <Button Content="5" Width="40" Height="40" Grid.Column="1" Grid.Row="1"></Button>
        <Button Content="6" Width="40" Height="40" Grid.Column="2" Grid.Row="1"></Button>

        <Button Content="7" Width="40" Height="40" Grid.Column="0" Grid.Row="2"></Button>
        <Button Content="8" Width="40" Height="40" Grid.Column="1" Grid.Row="2"></Button>
        <Button Content="9" Width="40" Height="40" Grid.Column="2" Grid.Row="2"></Button>

        <Button Content="0" Width="40" Height="40" Grid.Column="0" Grid.Row="3"></Button>
        <Button Content="+/-" Width="40" Height="40" Grid.Column="1" Grid.Row="3"></Button>
        <Button Content="." Width="40" Height="40" Grid.Column="2" Grid.Row="3"></Button>

        <!-- Calculator Functions -->
        <Button Content="+" Width="40" Height="40" Grid.Column="3" Grid.Row="0"></Button>
        <Button Content="-" Width="40" Height="40" Grid.Column="3" Grid.Row="1"></Button>
        <Button Content="*" Width="40" Height="40" Grid.Column="3" Grid.Row="2"></Button>
        <Button Content="/" Width="40" Height="40" Grid.Column="3" Grid.Row="3"></Button>

        <Button Content="=" Width="95" Height="40" Grid.Column="2" Grid.Row="4" Grid.ColumnSpan="2"></Button>

       </Grid>

    </Canvas>
 
</Canvas>
 

 

if I do the same (well, changing the outer tags) in a VS2008 project, everything works fine, but I need to be able to do this using just a xaml file (and later some javascript).  If I remove all Button elements, everything else works fine.

Any ideas?  Any help would be greatly appreciated.

Richard
 

RichardBateman

Joined on 05-06-2008
Posts 3
05-05-2008 11:02 PM
Marked as Answer
Re: ParserError: Unknown element: Button

Looks like you're trying to do this in Silverlight 1.0? If so, Button is not supported in 1.0.


Bill Reiss - Client App Dev MVP (What's an MVP?)
Silverlight and XNA Game Development Tutorials at http://www.bluerosegames.com/brg

Bill Reiss

Joined on 05-01-2007
Posts 470
05-06-2008 9:17 AM
Marked as Answer
Re: ParserError: Unknown element: Button

Neither is Grid, though.

My guess is that somehow the reference to System.Windows.Controls (an external dll) was trashed. That's an odd one.

For the OP, have you tried creating a new project and seeing if you get the same message? If you get the same thing, I suggest uninstalling and reinstalling Silverlight and the Silverlight 2 SDK.

You can also manually go to the references in your Silverlight project and check to see if System.Windows.Controls is referenced. In a normal install, you don't need to do that unless you accidentally deleted it.

Pete

If your question was answered, please mark the response as the answer.

Silverlight.net Moderator
MVP: Visual Developer - Client Application Development
POKE 53280,0 - My Blog

Psychlist1972

Joined on 10-12-2004
Maryland, USA
Posts 717
05-06-2008 1:52 PM
Re: ParserError: Unknown element: Button

Grid works, Button doesn't.  I may be doing it 1.x style.  Is there a way to build a 2.x silverlight control w/out code-behind?  just using a xaml file? 

RichardBateman

Joined on 05-06-2008
Posts 3
05-06-2008 2:16 PM
Marked as Answer
Re: ParserError: Unknown element: Button

Grid is built into Silverlight. IIRC, Button is currently in an external assembly: System.Windows.Controls. That's why I think you have a reference problem. If you're trying to build this all using just xaml with no compilation, that is likely part or all of the issue.

You can build a 1.0 application using javascript and xaml, and run it on Silverlight 2, but that won't let you take advantage of things like grid/stackpanel/button etc.

What's your use-case for wanting to do xaml-only? Perhaps we can come up with an alternative solution.

Pete

If your question was answered, please mark the response as the answer.

Silverlight.net Moderator
MVP: Visual Developer - Client Application Development
POKE 53280,0 - My Blog

Psychlist1972

Joined on 10-12-2004
Maryland, USA
Posts 717
05-06-2008 11:55 PM
Re: ParserError: Unknown element: Button

Primarily simply to make the API I'm working on usable even to those who can't afford the tools.  I guess I'm used to working on home-brew type projects and I try to keep everything usable to as wide an audience as possible.

In this case, that's not critical... it would just be nice.  Is there any way to import the assembly from an xaml file?  if it's impossible, then it's impossible... but it would still be cool to be able to get all the power of the interface w/out the expensive tools or having to compile anything.

Thanks for your help!
 

RichardBateman

Joined on 05-06-2008
Posts 3
05-07-2008 7:18 AM
Re: ParserError: Unknown element: Button

There are some similarities between what you're trying to do and what some people are doing with dynamic languages and Silverlight, possibly looking through some of their stuff may give you some ideas? Here is one blog article:

http://www.iunknown.com/2008/03/dynamic-silverl.html


Bill Reiss - Client App Dev MVP (What's an MVP?)
Silverlight and XNA Game Development Tutorials at http://www.bluerosegames.com/brg

Bill Reiss

Joined on 05-01-2007
Posts 470