I am trying to use MVVM light messaging to send a value from one page to another during Navigation (for example, send the id of an item that was selected to an edit page). So the list page's viewmodel sends a message and then sends a navigation message to the view which redirects to the edit page. The edit page's viewmodel gets created only when the navigation to the page happens. So when I register for this event in the edit page viewmodel, I never get the message? What is the best solution for this?
Thanks in advance.
Your best solution would be to use the querystring instead of messaging. If you don't use the querystring, you'll have to deal with situations like the application being deactivated (tomestoned), then the user clicking "back" and your application loads the second page without receiving the message.
However, if you want to continue down this path, you can modify your ViewModelLocator such that your page's ViewModel is created immediately (in ctor for instance) instead of as needed. Since the ViewModelLocator is created as soon as your App.xaml is loaded, you know that any view models will be created immediately. As long as your view model is registering for messages in it's constructor it should receive the message.
Related
So I have this Laravel 9 project. In this view below you can see the navigation bar:
The menu above for the active link (Overview) styling (Tailwind) is active via the check below in the view for the component looking at the request information:
#if(request()->is('dashboard/*/overview'))
This works great as the url currently is
localhost/dashboard/{ID}/overview
When clicking the bottom nav link for the Dividends this fires a livewire event for this account as they don't have permissions to access the page. No navigation away from the page Overview is performed. This event is used to setup a popup when the user doesn't have access to a feature. (I have these in a few places)
The issue is that when one of these fires it sets the 'is' check value in the request to
/livewire/message/{COMPONENT_NAME}
This seems to be the expected behaviour of the livewire events. I attempted a similar check using the code below but the same result occurred as the data is still tied to the request.
#if(request()->pathInfo == "dashboard/7/overview")
If anyone knows of another way or a better way I could have the intended functionality so that the button keeps it's 'active' properties after a livewire event has ran, I'd appreciate it :)
So I have a Shell that has a home page and a settings page.
The settings page makes changes to a singleton service that the home's ViewModel is binded to (MVVM).
I have set up break points on the PropertyChangedEvents of elements on the Home page and they hit as soon as changes are made to the service's properties and their PropertyChanged is executed.
However, upon going back to the home page via the Shell, the page's UI only updates when the page is active and visible. This causes fields to flash when they change. But the breakpoints suggest that they should have updated before.
Is there a way to force refresh the UI before or are there any other alternatives?
For now I have made my view perform a Fade In animation so that changes to the ViewModel don't cause flashing.
Even I have a Xamarin Forms Shell app, and I also had the same issue, So what you can do is, Make the common properties Global as in make those properties in App.xaml.cs and mark them as static.
So when the User changes the property on settings change the App.PropertyName.
Then on the OnApearing method of homepage call a method on the ViewModel say LoadDataValues() and read the App.PropertyName and modify the UI as needed.
What this will do is just before the HomePage appears it will keep the UI of HomePage ready.
Let me know if you have further issues.
I have an app with 3 sections:
Main menu;
Context Menu - Related to selected item in main menu;
and Page body - Related to selected item in context menu;
"Main menu" and "Context menu" are based on membership. I don't want to load them everytime my page loads, because that would consume resources database. So, I'm using ajax to load main menu only one time, and when an item is selected, I load the context menu for that item.
My problem is: Every form's post will erase my menu.
Question: Will I have to build my entire application using ajax? I don't wanna do that, because it is too much simpler do a post in the form then send all data to controller with ajax.
Until now, I have 2 options:
Load my menus with ajax and the page body with IFRAME, so the post's will not render again my menus.
Do everything using ajax;
Is there any alternative to load my menus with ajax and be able to use form's post?
Sorry if I wasn't clear enough.
The sentence that gave me a pause is this "I don't want to load them everytime my page loads, because that would consume resources database."
You see, I've build quite a lot of apps, that display menus and sub-menus based on user roles (what you called membership). This has never been an issue from the resources or database perspective.
You can access all the membership information that you need once, when your used is being logged in. In the simplest case user's identity will be stored in the context along with the roles they have (HttpContext.User), so you do not to need a database lookup at all to get this information on every request. Note that with this scenario no ajax is required either.
If for whatever reason you can't store your membership information in the context like this, you still can store in in session (if in-memory) or in encrypted Cookies.
Now, I understand, that I don't all the details of your scenario, and that may be in your scenario what you are trying to do is warranted, however I suggest you think it through again, as under normal circumstances what you indicate is a problem (database resource) should not be a problem at all.
The bottom line is: if you alter your application that it stores the membership information when user logs on you won't have your problem to start with.
You don’t have to build all of your application using Ajax. But in this scenario Ajax may be the best way forward.
Following is my suggestion
Create your data entry for inside a dev
Have each input controller marked with a class (say ‘dataEntry’)
Create a javascript function to iterate the dev and build a list of all elements that has class dataEntry
Build a json object using the list. Use the name of each element as property name and value as the property value
Use jquery ajax to post this to the controller action
[optional] you can use .done and .fail methods to take action on success or failures of the call
I know this may look intimidating, but if you have many data entry forms, you can re-use this code.
I'm asking this because I really don't know where I should handle events of my dynamically created window.
When someone clicks on a desktop icon, the window (if it doesn't exist) will be dynamically created. Should I create a controller when creating the window and hook to it? If yes, how?
Here you can read different approaches I've thought about:
Create a controller that will instanciate the Window (as its view), I will handle everything there
Create the window only and hook everything in my taskbar controller (which is where the window is created). In this case, the Taskbar controller will become very big.
Pre-create all window controllers and eventually windows too and hide them (when page is ready). Then just show/hide them, so I will have "static" references to all controllers with getController in Application
Which approach should I use?
Edit 1:
I'm trying to dynamically instanciate (and reference it through another controller) a controller. I'm having hard time expecially in referencing it. Any suggestion on how it should be done?
I found Ext's MVC unusable with desktop demo as it's possible to have multiple windows (views) of the same type tied to a single controller. Each window has it's own state and it's hard to differentiate between the views in the controller.
I solved the problem by myself: I preinstanciate the controller as I do with all controllers, by inserting them in Application controllers array. After this, I instanciate the view on that controller when a method is called, then I simply use refs to access this view.
The method is quite clean and using refs feel so good. Obviusly the controller has a method hasWindow which checks if the controller view has been created already.
I have a Conductor<MyItem>.Collection.OneActive ViewModel and try to attach the application bar buttons to methods of MyItem with cal:Action.TargetWithoutContext="{ Binding ActiveItem }". My view is a Pivot, if someone wonders why am I trying to attach the application bar to a child ViewModel. The compiler says "Property 'TargetWithoutContext' is not attachable to elements of type 'AppBarButton'." Though it works with normal buttons elsewhere in the view.
How can I get it work? Or maybe any workaround?
The AppBar functionality that Caliburn.Micro provides is a hack due to the flaws in the underlying framework, which doesn't allow arbitrary binding. Unfortunately, we can't support TargetWithoutContext. For AppBars the target will always be the page's view model and messages can only be directed to it. If the page's view model is a conductor, and you want a child to receive the message, you could have the conductor receive it and then forward it on to its ActiveItem.
Unfortunatly the ApplicationBar is not bindalbe as it is not Part of the Silverlight Framework.
You can only interact with the Application via the Code Behind File of the Page which uses the ApplicationBar.
You have to register the Click Event and invoke the Action form the code Behind.
The WP7 ApplicationBar is just a simple wrapper around the native shell and doesn't support data binding at all. However, there are a couple of workarounds available.
http://caliburnmicro.codeplex.com/discussions/232742