简体   繁体   English

无法绑定到属性

[英]Can't bind to a property

I've got the following markup. 我有以下标记。

<TextBox x:Name="Address" 
         Text="{x:Static local:MainWindow.Boundie.SomeProp}" 
</TextBox>

In the code behind I have a static property like so. 在后面的代码中,我有一个像这样的静态属性。

static Something Boundie { get; set; }

public class Something { public String SomeProp { get; set; } }

The problem is that it nags that "type expected" when I hover over Boundie and "static member expected" when I hover over SomeProp . 问题是,它耿耿于怀,“第二类预期”当我将鼠标悬停在Boundie和“静态成员预计”当我将鼠标悬停在SomeProp。 When I leave out the latter, it only complains that the expected type is String but it only sees Something . 当我忽略后者时,它只会抱怨期望的类型是String,但只会看到Something

How do I bind to a static member's non-static field? 如何绑定到静态成员的非静态字段?

Why I want to do that? 为什么我要这样做? Because I want to reuse the domain object model and those classes are not equipped with static members. 因为我想重用域对象模型,并且那些类没有配备静态成员。

SomeProp is instance property so you cannot use x:Static to access that. SomeProp是实例属性,因此您不能使用x:Static来访问它。 You can bind to it using combination of static Source and Path 您可以使用静态SourcePath组合将其绑定

<TextBox ...
         Text="{Binding 
           Source={x:Static local:MainWindow.Boundie}, 
           Path=SomeProp}"/> 
<object property="{x:Static prefix:typeName.staticMemberName}" .../>

http://msdn.microsoft.com/en-us/library/ms742135.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM