How to write a ViewModelBase in MVVM

It’s worth nothing to use MVVM frameworks if you don’t know what’s going on inside. So let’s go step by step and build your own ViewModelBase class. ViewModelBase is class common for all your viewmodels. Let’s move all common logic to this class. Your ViewModels should implement INotifyPropertyChanged (do you understand why?) public abstract class … Read more

MVVM and collections of VMs

Your general approach is perfectly fine MVVM, having a ViewModel exposing a collection of other ViewModels is a very common scenario, which I use all over the place. I would not recommend exposing items directly in a ViewModel, like nicodemus13 said, as you end up with your view binding to models without ViewModels in between … Read more

Jetpack Compose – Unresolved reference: observeAsState

observeAsState is part of the runtime-livedata library. Add the dependency to your module’s build.gradle file. Replace $compose_version with the version of compose which you use, e.g. 1.0.0-beta01: implementation “androidx.compose.runtime:runtime-livedata:$compose_version” You can find the available versions here in Google’s Maven repository.

‘by viewModels()’ Kotlin property delegate unresolved reference

Add these dependencies: implementation “androidx.activity:activity-ktx:$activity_version” implementation “androidx.fragment:fragment-ktx:$fragment_version” You can find the latest versions of libraries here: https://developer.android.com/jetpack/androidx/releases/activity https://developer.android.com/jetpack/androidx/releases/fragment

how to instantiate ViewModel In AndroidX?

Updated answer: Things changed a little bit, as the previously needed dependency – ViewModelProviders – got deprecated (see the old answer for details). You can now use the ViewModelProvider constructor directly. So, in this case, the answer would be: private val viewModel = ViewModelProvider(this).get(SheduleViewModel::class.java) Note that, however, if you include the androidx.activity:activity-ktx:$Version dependency (a few … Read more

How to bind WPF button to a command in ViewModelBase?

<Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width=”*”/> </Grid.ColumnDefinitions> <Button Command=”{Binding ClickCommand}” Width=”100″ Height=”100″ Content=”wefwfwef”/> </Grid> the code behind for the window: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = new ViewModelBase(); } } The ViewModel: public class ViewModelBase { private ICommand _clickCommand; public ICommand ClickCommand { get { return _clickCommand ?? (_clickCommand … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)