Reputation: 297
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
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
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