viewmodel

Multiple viewmodels sharing a service with notification

微笑、不失礼 提交于 2019-12-12 04:56:47
问题 Question: I have two viewmodels that share a service with a list. My question is how to setup the notification so that both viewmodels know when this list is changed. Description below and code of where i'm at. I found this example HERE that looks right for what I'm trying to do, but I have a question regarding how to be notified in my viewmodels of a change in my service. I'll add some code I've mocked up to see if I'm on the right track. I'm using WPF/MVVM Light. First part is a service

wpf - bind label widths to calculated length property

匆匆过客 提交于 2019-12-12 03:53:15
问题 If I had a label on a view that I wanted to have the width equal to the width of two columns in one of my grids on the same view, how would I set up the binding without using a converter? Should I use properties to preform my calculation and store a value? It is my intention that if the view's grid size changes then this label's size will also change to match the new width of the two columns. And where should I put this logic? I am trying to follow MVVM pattern but I see that a lot of threads

wpf ViewModel Property Binding from another viewmodel

拟墨画扇 提交于 2019-12-12 03:35:59
问题 how do i bind a property declared in a viewmodel to take value from another viewModel? let me explain i have 2 ViewModels (Implements INotifyPropertyChanged) and 1 View InvoiceView ( just my invoice design no matter if is a user control or window or a dataTemplate) InvoiceViewModel NoteListingVM (this viewmodel has a property let's name it TableRefID) In the ViewInvoice i have an expander with it's dataContext set to (NoteListingVM) to show some notes that are linked with the specific

How to show a decimal corretly formatted in 0.00$ format?

末鹿安然 提交于 2019-12-12 03:08:21
问题 I have a view model that show a product.. but the price is in decimal format and i dont want to format it in the view, it should be automaticly formatted using the viewmodel. I know there is a property displayformat.. is there anyone that know to to render the decimal in the view in the formatted form such 0.00$ ? 回答1: you can use DisplayFormat attribute like following to show the formatted result [DisplayFormat(DataFormatString = "{0:###.###$}")] public decimal myVal { get; set; } Then myVal

Best practice for loading non model data in ExtJS

不问归期 提交于 2019-12-12 03:01:09
问题 Let's assume that I have 2 tables in my database, a user table and a folder table. They are matched by two models (beans) in my backend java code and similarly by to models in my extjs client side. Using viewmodel architecture, I want to create a form that shows the username and the amount of folders they have created using viewmodel bindings . Each folder in the database has a CREATE_USER_ID field that contains the id of the user that created the folder. How do I go about loading the

How to define ASP.NET MVC view model for parent/child relationship and its view (*.cshtml)

霸气de小男生 提交于 2019-12-12 02:04:25
问题 I have a domain model below: public class Book { public List<Author> Authors = new List<Author>(); } public class Author { public Book Book { get; set; } public string Name { get; set; } } I want to define an edit view for a book, below is the action methods: public ActionResult BookEdit(int id) { BookModel model = GetBook(id); return View(model); } [HttpPost] public ActionResult BookEdit(BookModel bookModel) { BookModel model = new BookModel(); return View(model); } Two questions: Question 1

MVC2.NET pass object from viewmodel to view and access it

♀尐吖头ヾ 提交于 2019-12-12 01:32:33
问题 When working with Viewmodels from linq to sql I have an architectural problem. When you have an object from your db (let's say "person"), and you load it in your viewmodel. After this in your view, when you try to acces referenced classes (let's say a person has children object which is a different table in db, and a different datacontext object). You get a "cannot access disposed datacontext object (or something) which is logical, because you loaded your object and disposed the datacontext.

Correct way to update property in ViewModel from Model

风格不统一 提交于 2019-12-12 01:29:25
问题 I'm fairly novice with WPF. It's my understanding that data changes in the model, and it should notify the viewmodel, and the view will bind to properties and things alike in the viewmodel. Is this correct? If so, I've been reading that the model should implement INotifyPropertyChanged , and look something like this public class LoginModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string propName) { PropertyChanged?

Android Java ViewModel with Dagger 2

☆樱花仙子☆ 提交于 2019-12-12 00:52:48
问题 I'm trying to use viewmodel with dagger 2. However, on orientation change, ViewModel is being recreated. I get SwipeRefreshLayout NullPointerException on featuredViewModel.getLoading.observe() . Where is my fail? Dagger 2 Fragment Module (ContributesAndroidInjector) @Module(includes = {ApplicationModule.class, PicassoModule.class}) public class FeaturedProjectsModule { @Provides FeaturedViewModel provideMainViewModel(FeaturedProjectsFragment fragment, ViewModelProvider.Factory factory) {

WPF ViewModel not active presenter

北城以北 提交于 2019-12-11 20:43:19
问题 There is a ViewModel that consists of some related object (nodes and lines( , How it can be possible to display (synchronize) these VM in View and keep object connections. I use some DataTemplate to map model to view but each object would be synchronized (with powerful binding) to its related object but how can i link (and synchronize) this DataTemplate generated UI element together. I describe problem from another viewpoint here: Sunchronizing view model and view 回答1: To keep your view