R – Why can a WPF/Silerlight XAML file parse without the default namespace

namespacessilverlight

I read that "the default namespace is important because otherwise the XAML parser will not recognize the elements".

However, just as a test, I take it out and, although the visual designer cannot recognize the element names anymore, this Silverlight XAML runs just fine:

<UserControl x:Class="Second12.Page"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="This is a test."/>
    </Grid>
</UserControl>

Why is that?

Best Answer

I would look at it being reasonable for the Silverlight parser to fall back to the WPF silverlight parsing by default.

you would get errors if you used wf xaml or even WPF xaml not supported by Silverlight parser.

I would look at the importance of having the namespace going forward though.

XAML is a language supported currently by WPF, Silverlight which uses a subset of WPF, and WF and a little bit in WCF. each of those have their own Parsers right now.

With .net 4.0 there will be system.xaml.dll or something to that effect. The namespace will mean quite a bit more as it will direct the parser further. WPF, WF, and WCF will all be using that parser, and would guess that silverlight in the future will use it.

edit, primarily the top level namespaces are used to provide intellisense schema in the way that parser is written for each group.

Related Topic