Is Telerik ViewModelBase's PropertyChanged extensible?

1 Answer 38 Views
General Discussions
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
Psyduck asked on 18 Aug 2021, 02:12 AM

Hello

 

I am using it by making a ViewModelBase class by default.

I looked at Telerik's ViewModelBase class documentation and this is not what I'm looking for.
https://docs.telerik.com/devtools/wpf/common-information/mvvm-helpers/common-viewmodelbase-class

I prefer to display getter setters on one line.


using Telerik.Windows.Controls;

private object item; public object Item { get => item; set { item= value; RaisePropertyChanged(); } }

 


// Create ViewModelBase helper method
protected virtual bool SetField<T>( ref T member, T newValue, [CallerMemberName] string propertyName) ... ... 

private object item;
public object Item
{
    get => item;
    set  => SetField(ref item, value);
}

 

I want to keep it simple. Do you have any plans to improve this?
Or I would like to ask if it is possible to create a similar one and use it while using the Telerik ViewModelBase Class.

 

If that doesn't work, I'll continue to create and use my ViewModelClass.

Thanks.

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 20 Aug 2021, 09:53 AM

Hello KIM,

Currently we do not have plans to introduce SetField method. However, you can achieve your requirement by extending the ViewModelBase class like so:

public class CustomViewModelBase : ViewModelBase
{
	protected virtual bool SetField<T>(ref T member, T newValue, [CallerMemberName]string propertyName = "")
	{
		if (EqualityComparer<T>.Default.Equals(member, newValue))
		{
			return false;
		}

		member = newValue;
		OnPropertyChanged(propertyName);
		return true;
	}
}

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
Answers by
Martin Ivanov
Telerik team
Share this question
or