Take the 2-minute tour ×

I'm trying to follow along with the code example for data binding to a clr-object.

The example states

    <c:MyData x:Key="myDataSource"/>
    <Binding Source="{StaticResource myDataSource}"/>
  <Button Background="{Binding Path=ColorName}"
          Width="150" Height="30">I am bound to be RED!</Button>

However, I seem to be having problems getting a reference the object I created (in C#) from with in my XAML


        <src:MainPage+Person x:key="person" />

Here is my C#

  public Person person = new Person();

    public class Person
        public String name { get; set; }

I created the "src" namespace as shown. However, Visual Studio does not recognize "Person" and wants to add "MainPage+Person" in front of it. I get the following error


So I am confused about this and also about the "MainPage+Person." I would assume I need a way to tell the XAML not only the type of object, but also get a handle on the actual object I am creating.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Unfortunately, you're being challenged by slight differences in the XAML syntax for WPF and for Windows Store applications. The DockPanel example is WPF (DockPanel isn't a native Windows Store control), and your MainPage would appear to be from a Windows Store app.

Change your namespace declaration from




using is the Windows Store version of clr-namespace.

share|improve this answer
Thanks for you help Jim. I'm now using <local:MainPage x:Key="person" /> but I'm still not about where to link my CLR (called "person") up with XAML. I believe the "Key" it just giving the that an alias. I tried <local:person x:key="person" /> but that only seems to want to resolve to local:MainPage –  Frank Sposaro Jan 22 '13 at 20:04
<local:Person x:Key="person" /> should be working assuming the Person class resides in the HelloWindows namespace. It sounds like you might have Person as a class nested in your MainPage class - probably not what you want here. –  Jim O'Neil Jan 23 '13 at 4:27
Yes. That was it exactly. I moved that definition outside of the MainPage class and that fixed my issue. Thanks Jim –  Frank Sposaro Jan 23 '13 at 15:17
add comment

Your Answer


