viewmodel

Possible to access AndroidViewModel of Activity via Fragment?

痴心易碎 提交于 2020-04-14 07:45:23
问题 In the summer of last year I started refactoring my Android application with Android's architecture components (Room, ViewModel, LiveData). I have two Room repositories, one of them is accessed by multiple views (fragments) of the application. Because of that I used an AndroidViewModel , which has access to this repository and which is initialized in my MainActivity . new ViewModelProvider(this).get(CanteensViewModel.class); In my two fragments I accessed this ViewModel by new

How to perform Single click checkbox selection in WPF DataGrid with IEditableObject object

浪尽此生 提交于 2020-04-13 17:54:05
问题 The default behavior of DataGridCheckBoxColumn is that the user has to click twice to change the checkbox value. In the How to perform Single click checkbox selection in WPF DataGrid topic there are a couple of solutions which work, but there is a problem - is you have a viewmodel object in code behind, which implements the IEditableObject interface, then the EndEdit method doesn't execute. Any idea how to make single click work and also preserve the IEditableObject functionallity? 回答1: You

SwiftUI View Property willSet & didSet property observers not working

余生长醉 提交于 2020-03-21 19:06:01
问题 I have a SwiftUI (Beta 5) view with an attached ViewModel. I want to navigate to it via a navigationLink and pass in a simple parameter (called FSAC in this case) I navigate using NavigationLink("Next", destination: MyTestView(FSAC: "testFsac")) The view has an FSAC Property with willSet and didSet property observer struct MyTestView: View { @ObservedObject var vm = MyTestViewModel() var FSAC: String { willSet { print("will set fsac") } didSet { print("did set fsac") vm.FSAC = FSAC } } var

SwiftUI View Property willSet & didSet property observers not working

坚强是说给别人听的谎言 提交于 2020-03-21 19:04:56
问题 I have a SwiftUI (Beta 5) view with an attached ViewModel. I want to navigate to it via a navigationLink and pass in a simple parameter (called FSAC in this case) I navigate using NavigationLink("Next", destination: MyTestView(FSAC: "testFsac")) The view has an FSAC Property with willSet and didSet property observer struct MyTestView: View { @ObservedObject var vm = MyTestViewModel() var FSAC: String { willSet { print("will set fsac") } didSet { print("did set fsac") vm.FSAC = FSAC } } var

how to instantiate ViewModel In AndroidX?

[亡魂溺海] 提交于 2020-03-18 11:27:20
问题 I want to initialize ViewModel in Activity using androidx library I have tried what documentation says but it is not working. the ".of" is not resolved. import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.databinding.DataBindingUtil import androidx.lifecycle.ViewModelProvider import com.example.myapplication.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate

How does the ViewModel constructor get the required interfaces?

谁都会走 提交于 2020-03-02 17:12:08
问题 My question based on InventorySampleApp by Microsoft. The ServiceLocator contains method Configure() that register Services and ViewModels. With method GetService<T>() we can get it. For example, ProductView.cs : ViewModel = ServiceLocator.Current.GetService<ProductDetailsViewModel>(); Each *ViewModel contains constructor with interface, for example: public ProductDetailsViewModel(IProductService productService, IFilePickerService filePickerService, ICommonServices commonServices) I can't

Multiple calls to set LiveData is not observed

陌路散爱 提交于 2020-03-01 02:06:34
问题 I have recently seen a weird issue that is acting as a barrier to my project. Multiple calls to set the live data value does not invoke the observer in the view. It seems that only the last value that was set actually invokes the Observer in the view. Here is the code snippet for a review. MainActivity.kt class MainActivity : AppCompatActivity() { private lateinit var viewModel: MainViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)

Multiple calls to set LiveData is not observed

家住魔仙堡 提交于 2020-03-01 02:05:15
问题 I have recently seen a weird issue that is acting as a barrier to my project. Multiple calls to set the live data value does not invoke the observer in the view. It seems that only the last value that was set actually invokes the Observer in the view. Here is the code snippet for a review. MainActivity.kt class MainActivity : AppCompatActivity() { private lateinit var viewModel: MainViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)

Android - Can I Databinding programatically? - without layout XML

大憨熊 提交于 2020-02-25 04:47:33
问题 Below is XML equivalent of what I'm trying to achieve, but without XML <Button android:id="@+id/bt_start" android:onClick="@{() -> vm.onClickedStart()}" android:text='@{vm.btStartLbl}' /> so if I have: ConstraintLayout cl = findViewById(R.id.cl); Button btn = new Button(MyActivity.this); btn.setText("How to Data Bind here?"); btn.setOnClickListener(new OnClickListener (){ /* how to databind here? */ }); cl.addView(btn); how to databind it as equivalent as xml above? is it possible? 回答1: For

What's the point of separating the Model from the View Model? (MVVM)

﹥>﹥吖頭↗ 提交于 2020-02-15 08:20:24
问题 I don't think I understand the MVVM pattern properly because having a Model and ViewModel class seems redundant to me. My understanding of the Model is to basically add in minor details of a class and let the ViewModel handle all the logic and implementation. If that is the case why separate the two? Couldn't you create the variables, properties and such in the view model and still have the logic in there? To me it sounds like C++ in a way. You have the header file which describes the class