为类对象

时间:2016-03-18 04:54:48

标签: c# .net wpf inotifypropertychanged

我有一个课程如下:

public class UserData : INotifyPropertyChnaged
{
    public string strUserName;
    public string UserName
    {
        get { return strUserName; }
        set { SetProperty(ref strUserName, value); }
    }

    private string strPhoneNumber;
    public string UserPhoneNumber
    {
        get { return strPhoneNumber; }
        set { SetProperty(ref strPhoneNumber, value); }
    }

    private List<UserMailID> listUserMailID;
    public List<UserMailID> ListOfUserMailID
    {
        get { return listUserMailID; }
        set { SetProperty(ref listUserMailID, value); }
    }
}

我正在某个地方访问这个类,这个类对象我绑定到我的视图:

private UserData cActiverUser;
public UserData ActiverUser
{
    get { return cActiverUser; }
    set { SetProperty(ref cActiverUser , value); }
}

假设我的视图中有UserName字段;我的数据绑定是这样的:

TextBox.Text="{Binding ActiverUser.StrUserName, UpdateSourceTrigger=PropertyChanged}

绑定效果很好,但是当我在视图中更改此用户名字段时,我无法引发属性更改事件。我也试过设置Mode="TwoWay"

2 个答案:

答案 0 :(得分:1)

如果你正在使用Prism,那么派生UserData以及UserData作为BindableBase的属性来实现INotifyPropertyChanged,但也允许你使用SetProperty(...) INotifyPropertyChanged。我甚至不确定您之前是如何让它工作的,但我怀疑您没有向我们展示您的原始代码,因为您拼写错误INotifyPropertyCh - ged <强> NA ActiverUser.StrUserName

此外,您实际上是在实例化对象吗?别忘了这样做。

最后,您绑定到UserData,但StrUserName没有属性UserName。它有public class WebserviceAmazon extends AsyncTask<Void, Void, Void> { private String mParams; private String mResult = "x"; WebServiceInterface<String, String> mInterface; private int mRequestType; private String UserId; private Context mContext; public WebserviceAmazon(Context context,String imagePath,String AppId,int type) { this.mContext = context; this.mParams = imagePath; this.mRequestType = type; this.UserId = AppId; } public void result(WebServiceInterface<String, String> myInterface) { this.mInterface = myInterface; } @Override protected Void doInBackground(Void... params) { String ACCESS_KEY ="abc.."; String SECRET_KEY = "klm..."; try { if (mRequestType == 1) { // POST AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)); PutObjectRequest request = new PutObjectRequest("bucketName", "imageName", new File(mParams)); s3Client.putObject(request); mResult = "success"; } if (mRequestType == 2) { // For get image data AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)); S3Object object = s3Client.getObject(new GetObjectRequest("bucketName", mParams)); S3ObjectInputStream objectContent = object.getObjectContent(); byte[] byteArray = IOUtils.toByteArray(objectContent); Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); mResult = "success"; } } catch (Exception e) { mResult = e.toString(); e.printStackTrace(); } return null; } @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); mInterface.success(this.mResult); } public interface WebServiceInterface<E, R> { public void success(E reslut); public void error(R Error); } } ,这是你要绑定的东西。

答案 1 :(得分:1)

在您的XAML绑定中,尝试设置LEFT OUTER JOIN shifts ON shifts.shift_user = users.user_id and date(shifts.shift_user) = '2016-03-16' WHERE users.user_owner = 2 AND users.user_level= 'Personnel' AND date(shifts.shift_start) IS NULL AND users.user_active = 1 GROUP BY users.user_id ORDER BY secud_sname ASC ,或者如果它不起作用NotifyOnTargetUpdated=True

我和我之前做过的一个项目有同样的问题,而且它是其中一个让它发挥作用的问题。

同样在这一行:

NotifyOnSourceUpdated=True

这应该是私人的吗?你应该将绑定指定为public string strUserName; ,而不是UserName

我认为绑定也区分大小写。