WPF 폼의 컨트롤을 인터페이스에 바인딩하려고하는데 런타임 오류가 발생하여 인터페이스의 속성을 찾을 수 없습니다.WPF 인터페이스에 Databind 할 수 없습니까?
가 여기에 XAML을의public interface IPerson
{
string UserId { get; set; }
string UserName { get; set; }
string Email { get; set; }
}
public class Person : EntityBase, IPerson
{
public virtual string UserId { get; set; }
public string UserName { get; set; }
public virtual string Email { get; set; }
}
(발췌) : 여기
<TextBox Name="userIdTextBox" Text="{Binding UserId}" />
<TextBox Name="userNameTextBox" Text="{Binding UserName}" />
<TextBox Name="emailTextBox" Text="{Binding Email}" />
뒤에 코드입니다 (다시 발췌) :
여기
내가 데이터 소스로 사용하고 클래스의
var person = PolicyInjection.Wrap<IPerson>(new Person());
person.UserId = "jdoe";
person.UserName = "John Doe";
person.Email = "[email protected]";
this.DataContext = person;
제가 Policy Injection을 통해 t를 사용하고 있기 때문에 제가 데이터 소스로 사용하고있는 클래스는 엔티티 여야합니다. 그는 entlib의 Policy Injection Application Block을 사용합니다.
내가 런타임에이 오류를 받고 있어요 : 나는 entlib의 정책 주입에 익숙하지 않은,하지만 난이 사실에 문제가있다, 그리고 꽤 확신
System.Windows.Data Error: 16 : Cannot get 'Email' value (type 'String') from '' (type 'Person'). BindingExpression:Path=Email; DataItem='Person' (HashCode=22322349); target element is 'TextBox' (Name='emailTextBox'); target property is 'Text' (type 'String') TargetException:'System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'
@Robert Jeppesen : PolicyInjection 코드를 실행할 수 없습니다. – user7116
Robert가 맞습니다 - WPF 데이터 바인딩이 PolicyInjection.Wrap이 만드는 프록시 클래스의 속성을 인식하지 못하는 문제가 있습니다. PI가 없으면 데이터 바인딩이 제대로 작동하므로 사용하지 않는 작업을 수행해야합니다. –