چطور after update را در wpf پیاده سازی کنیم؟
سلام
چطور میشه رویداد after update را در wpf پیاده سازی کرد. یعنی وقتی که مقدار داخل تکست باکس عوض شد دستور اجرا شود
از رویداد textChange نمی خوام استفاده کنم چون که به ازای هر کارمتر اجرا میشه
رویداد lostfocus هم که چه تغییر داده باشیم چه نداده باشیم اجرا میشه
چه روشی برای انجام این کار هست؟
نقل قول: چطور after update را در wpf پیاده سازی کنیم؟
از binding و UpdateSourceTrigger=PropertyChanged استفاده كنيد:
Text="{Binding prop1, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
نقل قول: چطور after update را در wpf پیاده سازی کنیم؟
ولی من خیلی از تکست باکسهام این روش را نیاز داره. برای همه اونا باید پروپرتی تعریف کنم؟
prop1 از نو dependency باید باشه؟
نقل قول: چطور after update را در wpf پیاده سازی کنیم؟
نقل قول:
نوشته شده توسط
sajjad_kochekian
ولی من خیلی از تکست باکسهام این روش را نیاز داره. برای همه اونا باید پروپرتی تعریف کنم؟
prop1 از نو dependency باید باشه؟
شما برای خودت یه تکس باکس درست کن خوب. از Wpf Custom Control Library استفاده کن
نقل قول: چطور after update را در wpf پیاده سازی کنیم؟
نقل قول:
نوشته شده توسط
sajjad_kochekian
سلام
چطور میشه رویداد after update را در wpf پیاده سازی کرد. یعنی وقتی که مقدار داخل تکست باکس عوض شد دستور اجرا شود
از رویداد textChange نمی خوام استفاده کنم چون که به ازای هر کارمتر اجرا میشه
رویداد lostfocus هم که چه تغییر داده باشیم چه نداده باشیم اجرا میشه
چه روشی برای انجام این کار هست؟
سلام
اگه من جای شما بودم، برای کنترل تغییر اطلاعات کاری به کنترلها نداشتم.
معمولاً وقتی تو فرم ویرایش اطلاعات داری کار میکنی یه شی ( instance ) داری که propertyهای اون
رو به کنترلهای رو صفحه bind کردی.
حالا این مراحل رو انجام بده
1. کلاسش باید INotifyPropertyChanged رو پیاده سازی کنه.
public class MyClass: INotifyPropertyChanged{
}
2. برای این کار باید یه متد و یه رویداد به کلاست اضافه کنی
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged( object sender, string propertyName ) {
if ( PropertyChanged != null )
PropertyChanged( sender, new PropertyChangedEventArgs( propertyName ) );
}
3. کلیهی propertyهایی رو که میخوای تغییراتشون رو کنترل کنی رو بجای AutoProperty از روش Back field استفاده کن و
تو قسمت set متد onpropertychanged رو فراخوانی کن
private int _id;
public override int Id {
get { return _id; }
set {
if ( _id == value ) return;
_id = value;
OnPropertyChanged( this, "Id" );
}
}
این یک روش استاندارد هست تو WPF و همونطور که دوستمون anubis_ir نوشته binding رو انجام بده.
صبا صبوحی