如何使用已更改的Inotify属性 [英] how to use Inotifypropertychanged
本文介绍了如何使用已更改的Inotify属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法实现INotifyPropertyChanged.
请帮忙
查看:
I am not able to implement the INotifyPropertyChanged.
Please help
View:
<listboxitem foreground="Red" fontfamily="Verdana" fontsize="12" fontweight="Bold" verticalalignment="Center">
<checkbox name="baseMapChkBox" ischecked="{Binding IsBaseMapChecked,Mode=TwoWay}" horizontalalignment="Center" verticalalignment="Center">
<textblock text="Base Map Layer"></textblock>
</checkbox>
</listboxitem>
视图模型:
Viewmodel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.ComponentModel;
using Microsoft.Practices.Composite.Presentation.Commands;
namespace CoM_SWBaseMapModule
{
public class BaseMapViewModel : ViewModelBase, INotifyPropertyChanged
{
#region Members
private ICommand baseMapCheckCommand;
private BaseMapService baseMapService;
private bool isbaseMapChecked;
private object x=null;
#endregion
#region Properties
public BaseMapView BaseMapView { get; private set; }
public MapService MapService { get; private set; }
public bool IsBaseMapChecked
{
get { return isbaseMapChecked; }
set
{
isbaseMapChecked = value;
OnBaseMapCheck(x);
OnCheckPropertyChanged("IsChecked");
}
}
#endregion
#region Methods
public BaseMapViewModel(BaseMapView baseMapView, MapService mapService)
{
BaseMapView = baseMapView;
MapService = mapService;
baseMapService = new BaseMapService();
IsBaseMapChecked = true;
}
#endregion
#region CommandProperties
#endregion
#region Private Methods
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnCheckPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
}
private void OnBaseMapCheck(object p)
{
if (isbaseMapChecked)
baseMapService.LoadBaseMap(MapService, true);
if (!isbaseMapChecked)
baseMapService.LoadBaseMap(MapService, false);
}
#endregion
}
}
推荐答案
将UpdateSourceTrigger添加到绑定中.对于UI元素,默认的UpdateSourceTrigger是LostFocus.您可以在绑定内将UpdateSourceTrigger = PropertyChanged设置为
Hi,
Add the UpdateSourceTrigger to the binding.For UI elements the default UpdateSourceTrigger is LostFocus.You can set the UpdateSourceTrigger=PropertyChanged inside the binding as,
<checkbox name="baseMapChkBox" ischecked="{Binding IsBaseMapChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" horizontalalignment="Center" verticalalignment="Center">
还有一点,"IsBaseMapChecked"是您定义并触发了propertychange方法中的"IsChecked"属性的属性,您必须在我认为的PropertyChanged事件中触发"IsBaseMapChecked"属性.
One more point, "IsBaseMapChecked" is the property that you defined and triggered the "IsChecked" property inside the propertychange method,you have to trigger the "IsBaseMapChecked" property inside the PropertyChanged event I think.ie.;
PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
成为
PropertyChanged(this, new PropertyChangedEventArgs("IsBaseMapChecked"));
问候,
Vineeth
Regards,
Vineeth
这篇关于如何使用已更改的Inotify属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文