开发者

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.

&开发者_运维百科lt;Window xmlns:cc="clr-namespace:SomeNamespace;assembly=AssemblyX">
<TextBlock Text={Binding cc:Comment}/>
...


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}"/> 


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


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"; } }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜