Windows Vista Forums

DataBinding to object in external assembly

  1. #1


    Philipp Schmid Guest

    DataBinding to object in external assembly

    For the live of me I cannot get a simple databinding scenario to work! Here
    are my repro steps:

    1. Create WPF Application solution (say WindowsApplication1).
    2. Create class library project w/in the same solution (ClassLibrary1)
    3. Implement a simple class in ClassLibrary1:

    namespace ClassLibrary1
    {
    public class Class1
    {
    public Class1() { }

    private string _name;
    public string Name
    {
    get { return _name; }
    set { _name = value; }
    }
    }
    }


    4. Add a project reference to WindowsApplication1 using the project tab and
    referencing ClassLibrary1.

    5. Add the following to Window1.xaml


    <? Mapping XmlNamespace="eco" ClrNamespace="ClassLibrary1"
    Assembly="ClassLibary1" ?>
    < Window x:Class =" WindowsApplication2.Window1"
    xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
    Title= "WindowsApplication2" Height="300" Width="300"
    xmlns:eco ="eco"
    >

    < Window.Resources >
    <eco:Class1 x:Name =" foo" />
    </ Window.Resources >
    < Grid>
    </ Grid>
    </ Window>

    For me this results in the following compilation error:

    Error 2 The tag 'Class1' does not exist in XML namespace 'eco'. Line 9
    Position 6. c:\temp\WindowsApplication2\WindowsApplication2\Window1.xaml 9 6
    WindowsApplication2

    What am I missing? Clearly it doesn't understand the reference to
    ClassLibrary1.dll. I've tried linking directly before with the same result.
    Signing the assembly also doesn't seem to have an effect (I haven't tried the
    fully qualified name yet).

    BTW, these repro steps are a simplification of a more extensive scenario
    involving ObservableReadOnlyCollection<T> to bind to a ListBox.

    -- Philipp Schmid

      My System SpecsSystem Spec

  2. #2


    Julie Knibbe Guest

    Re: DataBinding to object in external assembly

    For me it works just fine.

    Try to use another mapping syntax :
    xmlns:eco="clr-namespace:ClassLibrary1;assembly=ClassLibrary1"

    See
    http://www.sellsbrothers.com/writing...hangeNotes.htm



    "Philipp Schmid" <PhilippSchmid@discussions.microsoft.com> a écrit dans le
    message de news: F6C6D426-8D5A-47D8-8073-6BFCEF8E6C34@microsoft.com...
    > For the live of me I cannot get a simple databinding scenario to work!
    > Here
    > are my repro steps:
    >
    > 1. Create WPF Application solution (say WindowsApplication1).
    > 2. Create class library project w/in the same solution (ClassLibrary1)
    > 3. Implement a simple class in ClassLibrary1:
    >
    > namespace ClassLibrary1
    > {
    > public class Class1
    > {
    > public Class1() { }
    >
    > private string _name;
    > public string Name
    > {
    > get { return _name; }
    > set { _name = value; }
    > }
    > }
    > }
    >
    >
    > 4. Add a project reference to WindowsApplication1 using the project tab
    > and
    > referencing ClassLibrary1.
    >
    > 5. Add the following to Window1.xaml
    >
    >
    > <? Mapping XmlNamespace="eco" ClrNamespace="ClassLibrary1"
    > Assembly="ClassLibary1" ?>
    > < Window x:Class =" WindowsApplication2.Window1"
    > xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
    > Title= "WindowsApplication2" Height="300" Width="300"
    > xmlns:eco ="eco"
    > >

    > < Window.Resources >
    > <eco:Class1 x:Name =" foo" />
    > </ Window.Resources >
    > < Grid>
    > </ Grid>
    > </ Window>
    >
    > For me this results in the following compilation error:
    >
    > Error 2 The tag 'Class1' does not exist in XML namespace 'eco'. Line 9
    > Position 6. c:\temp\WindowsApplication2\WindowsApplication2\Window1.xaml 9
    > 6
    > WindowsApplication2
    >
    > What am I missing? Clearly it doesn't understand the reference to
    > ClassLibrary1.dll. I've tried linking directly before with the same
    > result.
    > Signing the assembly also doesn't seem to have an effect (I haven't tried
    > the
    > fully qualified name yet).
    >
    > BTW, these repro steps are a simplification of a more extensive scenario
    > involving ObservableReadOnlyCollection<T> to bind to a ListBox.
    >
    > -- Philipp Schmid




      My System SpecsSystem Spec

  3. #3


    Philipp Schmid Guest

    Re: DataBinding to object in external assembly

    Indeed this works for me! I was looking at some older examples.

    -- Philipp Schmid


    "Julie Knibbe" wrote:

    > For me it works just fine.
    >
    > Try to use another mapping syntax :
    > xmlns:eco="clr-namespace:ClassLibrary1;assembly=ClassLibrary1"
    >
    > See
    > http://www.sellsbrothers.com/writing...hangeNotes.htm
    >
    >
    >
    > "Philipp Schmid" <PhilippSchmid@discussions.microsoft.com> a écrit dans le
    > message de news: F6C6D426-8D5A-47D8-8073-6BFCEF8E6C34@microsoft.com...
    > > For the live of me I cannot get a simple databinding scenario to work!
    > > Here
    > > are my repro steps:
    > >
    > > 1. Create WPF Application solution (say WindowsApplication1).
    > > 2. Create class library project w/in the same solution (ClassLibrary1)
    > > 3. Implement a simple class in ClassLibrary1:
    > >
    > > namespace ClassLibrary1
    > > {
    > > public class Class1
    > > {
    > > public Class1() { }
    > >
    > > private string _name;
    > > public string Name
    > > {
    > > get { return _name; }
    > > set { _name = value; }
    > > }
    > > }
    > > }
    > >
    > >
    > > 4. Add a project reference to WindowsApplication1 using the project tab
    > > and
    > > referencing ClassLibrary1.
    > >
    > > 5. Add the following to Window1.xaml
    > >
    > >
    > > <? Mapping XmlNamespace="eco" ClrNamespace="ClassLibrary1"
    > > Assembly="ClassLibary1" ?>
    > > < Window x:Class =" WindowsApplication2.Window1"
    > > xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > > xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
    > > Title= "WindowsApplication2" Height="300" Width="300"
    > > xmlns:eco ="eco"
    > > >

    > > < Window.Resources >
    > > <eco:Class1 x:Name =" foo" />
    > > </ Window.Resources >
    > > < Grid>
    > > </ Grid>
    > > </ Window>
    > >
    > > For me this results in the following compilation error:
    > >
    > > Error 2 The tag 'Class1' does not exist in XML namespace 'eco'. Line 9
    > > Position 6. c:\temp\WindowsApplication2\WindowsApplication2\Window1.xaml 9
    > > 6
    > > WindowsApplication2
    > >
    > > What am I missing? Clearly it doesn't understand the reference to
    > > ClassLibrary1.dll. I've tried linking directly before with the same
    > > result.
    > > Signing the assembly also doesn't seem to have an effect (I haven't tried
    > > the
    > > fully qualified name yet).
    > >
    > > BTW, these repro steps are a simplification of a more extensive scenario
    > > involving ObservableReadOnlyCollection<T> to bind to a ListBox.
    > >
    > > -- Philipp Schmid

    >
    >
    >


      My System SpecsSystem Spec

DataBinding to object in external assembly

Similar Threads
Thread Forum
Get Currently Existent Object Not Created with New-Object - PowerShell
Basically I have a script where it logs into a site and browses to a particular page. It then clicks a link that opens a popup window. I'm trying...
General Discussion
Re: .NET 3.5 - System.Reflection.Assembly does not release object (DLL
Yes I know but the answer doesn't help me. I though it belong to this newsgroup anyway because it is an issue with the .Net Framework and not VB...
.NET General
Binding TextBox.Text to property in nested (multi levels) object withbindingsource, Error if grandchild object is NULL
Hi all, I am binding a TextBox to an object which has child object which has a grandchild object, and I want to bind to the property of the...
.NET General
Inherit from usercontrol - Object not set to instance of an object
I am trying to inherit from a user control, but when i try to change the value of a property of a control within the base control, i get the above...
.NET General
datalist -- Object reference not set to an instance of an object.
I have a page with a datalist that on load works fine but on an edit postback I get the error "Object reference not set to an instance of an...
.NET General
Can you reference a XAML Resource from an External Assembly?
I have an assemblt called ControlsEx. In its project is a XAML file that has some resources in a dictionary. How can I add those resources into an...
Avalon
Adding canonical aliases for Compare-Object, Measure-Object, New-Object
Vote on this, please. :) https://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=79879 Of the 9 object cmdlets, 6 have...
PowerShell