Please click this logo to help me get on their beta program:

Xobni outlook add-in for your inbox








13/7/2006

Note to self - mapping of external namespaces into XAML files changed

Filed under: General, Programming, .NET — Oliver Sturm @ 4:30 pm - 2 years, 3 months ago

I stumbled upon this yesterday. If an external class needs to be referenced in a XAML file, a namespace must be mapped for it, so the compiler knows where to find that class. For example, I had a DataTemplate for a specific type in my file:

  <DataTemplate DataType="{x:Type arbitraryName:Klasse}">
    <StackPanel Orientation="Horizontal">
      <TextBlock Text="{Binding Path=Name}" />
      <TextBlock Text=", Jahrgang " />
      <TextBlock Text="{Binding Path=Anfangsjahr}" />
    </StackPanel>
  </DataTemplate>

Now, the class Klasse is part of a certain namespace (Sturm.MyNamespace), in a certain assembly (Sturm.MyDataAssembly.dll), and in the many references I was able to find, it said I should have something like this in my XAML file for the mapping of the “arbitraryName” namespace:

<?Mapping XmlNamespace="arbitraryName" ClrNamespace="Sturm.MyNamespace" Assembly="Sturm.MyDataAssembly" ?>
...
<Window ...
  xmlns:arbitraryName="arbitraryName"
  ... >

The problem was that this didn’t seem to work for me – I got errors all the time saying the type “arbitraryName:Klasse” couldn’t be cast to a Type object. Finally I found the solution somewhere: Microsoft changed the syntax of this, a few months back apparently, but obviously not long enough ago judging from the number of web pages giving the old syntax. The new format doesn’t need (and actually doesn’t seem to make any use of) the Mapping instruction, and the xmlns entry has to look like this:

...
<Window ...
  xmlns:arbitraryName="clr-namespace:Sturm.MyNamespace;assembly=Sturm.MyDataAssembly"
  ... >

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Powered by WordPress
© Copyright 2005-2008 Oliver Sturm