ورود

View Full Version : نحوه ي استفاده از CommandParameter



happy65_sh
دوشنبه 18 مرداد 1389, 09:34 صبح
سلام
دارم يه برنامه با wpf مينويسم مي خواهم يه command بنويسم كه پارامتر هم داشته باشه .command را توي كلاس viewmodel به شكل زير نوشته ام:


Command _delete;

public Command delete
{
get
{
if(_delete==null)
_delete= new Command(param=>DeleteWork(),param=>CanDelete)
return _delete
}
}

public void DeleteWork()
{
حذف كار بر اساس آي دي آن
}

bool CanDelete
{
get
{
return True;
}
}



و توي XAML براي باتن Delete دارم:


<Button command="{Binding delete}" commandparameter="{Binding ElementName=tbcode,Path=Text}"/>


حالا چه طور ميتونم از پارامتري كه توي xAML تعريف كرده ام توي DeleteWork استفاده كنم؟؟:گیج:

happy65_sh
دوشنبه 18 مرداد 1389, 11:25 صبح
سلام
فهميدم براي استفاده از CommandParameter بايد تغييرات زير را در ViewModel بدهم :


Command _delete;
int id;
public Command delete
{
get
{
if(_delete==null)
_delete= new Command(param=>DeleteWork(id),param=>CanDelete)
return _delete
}
}

public void DeleteWork(int id)
{
حذف كار بر اساس آي دي آن
}

bool CanDelete
{
get
{
return True;
}
}


حالا سوالم اينه كه چطور ميتونم از چند تا پارامتر براي يك باتن استفاده كنم؟؟؟:گریه::متفکر: