Comments (5)
I think a bit more information may be needed in order to answer your question. There is not enough code posted to determine the control flow of your app up to this point. Typically, if passing a base page or something similar into a ViewModel I would use an interface. But that's just what I can gather from what is posted. I will be glad to help if you can give a bit more context.
from fasetto-word.
Hi, thanks for your answer.
I have a Product List page and I want to which in the list double-clicked product id send product details page but I can't send it product id to product detail view model. How can I send Product Id another view model?
I tried field-initialization but not work because if the class has a constructor, first initializing constructor and after sets fields. Example:
I tried ProductDetail constructor parameter but I got an error;
'ProductDetailViewModel' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TVm' in the generic type or method 'BasePage<TVm>'
Sorry for my bad English.
I'm using BasePage and BaseViewModel.
fasetto-word/Source/Fasetto.Word/Pages/BasePage.cs
Lines 1 to 224 in 25d2428
fasetto-word/Source/Fasetto.Word/ViewModel/Base/BaseViewModel.cs
Lines 1 to 111 in 25d2428
from fasetto-word.
I have personally used some sort of state storage for issues like this. I use the MVVM pattern for all of my WPF applications and this is always an issue when loading a new page that is dependent on the data obtained from another.
So your product list page's viewmodel would store the ID in the state manager, and when loaded, the product detail page would retrieve the ID from the state manager. That decouples the two pages from one another.
You could store this state in a database, in a static StateManager class, or some other solution that you feel is best for your application. I'm not sure what methods other MVVM developers use but this has always been the best for my use case. Other methods that I've seen are overly complicated, add way too many steps, and are difficult to maintain and debug.
Without seeing the entire code base I cannot make a solid recommendation, but hopefully this will get you started.
from fasetto-word.
Honestly, I tried to use a similar pattern to create a WPF application in the past and had some issues like this.
I never load pages by passing view models. I always allow a page to load a new view model in their constructor and retrieve the data from some sort of state storage that will work for your application.
Again, it is hard to determine without seeing the entire code base, but you might try something similar to avoid these issues.
from fasetto-word.
Hi, thanks for your answer and the interest you have shown. I think I found a solution. I changed my Base Page to BasePage in Xaml File and constructor like this;
#region Constructor
/// <summary>
/// Default constructor
/// </summary>
public ProductDetail(Product product)
{
InitializeComponent();
ViewModelObject = new ProductDetailViewModel(product);
}
#endregion
In This way I can define fields viewmodel constructor.
#region Constructor
/// <summary>
/// Default constructor
/// </summary>
public ProductDetailViewModel(Product product)
{
// Set product
Product = product;
}
#endregion
from fasetto-word.
Related Issues (20)
- LoginViewModel binding for Email not working HOT 2
- Use Fasetto.Word.Web.Server in WPF-Project HOT 1
- ConcurrencyException
- When Window is Maximized, it goes under the TaskBar. HOT 5
- large data
- Can't Run HOT 4
- Framework.Service bug HOT 3
- System.ArgumentException: 'The path is not of a legal form.' HOT 1
- How to remove old page feature
- Change item selection
- MinWidth and MinHeight does't work. HOT 1
- Unable to open database file HOT 1
- DockChanged not detected when discplay scaling at 100%
- Errors using the code HOT 1
- Window cut when TaskBar is moved
- How to add a new dialog control?
- Design Time Exception HOT 2
- Question - Modify ObservableCollection from Non-UI-Thread
- WPF Application error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fasetto-word.