John
John

Reputation: 297

How to bind a property in one assembly to another property in another assembly

I have a class in assembly "AssemblyX" with property "Comment". I want to bind AssemblyX.Comment to TextBlock.Text in another assembly?

I'm trying to do it in the following way but it is not working.

<Window xmlns:cc="clr-namespace:SomeNamespace;assembly=AssemblyX">
<TextBlock Text={Binding cc:Comment}/>
...

Upvotes: 0

Views: 1314

Answers (3)

shakram02
shakram02

Reputation: 11846

To bind to a static property of a class ( static Command maybe ) try this

<MenuItem Header="{x:Static SomeClass.SomeProperty}"/>

Code behind

public class SomeClass
{
    public static string SomePropety 
    { get { return "done"; } }
}

Upvotes: 0

bitbonk
bitbonk

Reputation: 49629

You usually don't bind to a property of a class, you bind to a property of an instance of a class. So in your codebehind you'd create an instance:

SomeNamespace.SomeClass instance = new SomeClass();
instance.Comment = "bla";
this.DataContext = intstance;

And in your xaml you bind:

<TextBlock Text="{Binding Comment}"/>

In this case it absolutely does not matter in what assembly SomeClass is declared, as long as you current project references that assembly. It also doesn't matter what SomeClass is named. All that matters is that the instance you bind against has a property named Comment.

If the property of your class is static and you therefore don't have an instance, you can bind to the static property like this:

<TextBlock Text="{Binding cc:SomeClass.Comment}"/> 

Upvotes: 6

blindmeis
blindmeis

Reputation: 22445

if your class is not static, you have to create an instance for your class. then you can bind to a property.

look here maybe it helps you

Upvotes: 0

Related Questions