Attach TargetWithoutContext to an AppBarButton - windows-phone-7

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

Related

How do you know when Durandal has finished swapping views?

I need to perform an action after switching to a view.
The first time you switch to a view 'activate' and then 'compositionComplete' is called.
After that only 'activate' is called.
It would appear that 'activate' is called before the view has finished being displayed and this is causing issues with a JavaScript control I'm using (Bing Maps V7).
I've been using Hooking Lifecycle Callbacks as a reference but there doesn't appear to be a suitable callback to hook in to.
Is there another event or approach I can use to tell when the DOM has finished changing to the view?
It sounds as though your module is a singleton instead of an instance. Is that true? If you create an instance-based module, the module will be created anew each time it's activated. That will cause the compositionComplete to re-execute.
The activate handler is good for preparing data that will ultimately be displayed in the view. compositionComplete is best for handling matters that depend on a fully-constructed DOM.
We use Bing Maps AJAX v7 as well, and I've always placed it in an instance-based module.
To create an instance-based module, if you're not familiar, make sure your viewmodel returns a constructor function instead of an object literal.
Have you tried placing the Bing initialization in attached? Or creating a custom binding for it? Any third party libraries i use will always be initialized in attached, and if its something i want to use more than once, ill either create a custom binding for it or create a widget.

In a single page desktop-like application, should I dynamically instanciate a controller for a window? How?

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.

How do I create a user control view in MVC3, create events and reuse it in other views?

I am new to MVC3. In asp.net user control, its fairly easy to create a user control that has a combo box with a button, with hover over event, and a collection property of combo box that then displays a list
how do i achieve this user control (partial view) in mvc3?
What you are looking for is helper methods. You can see a good explanation of it here. In that post, there is a great link for how to do this: Creating Custom HTML Helpers.
I am also a WebForms developer originally, and I had a hard time making the connection between user controls and HTML Helpers. This should give you enough guidance to get started with what you want.
Hover over event can be done using jQuery, your combo box just needs to have a CSS class in the partial view and then the even can be hooked up to that selector.
The Collection property will be inside the View Model that your partial view binds to.

Using MVVM Light messaging instead of query strings in Windows Phone

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.

Can I trigger a webcontrol panel's OnInit event without a page?

I am working with someone else's code. The code was originally designed so that data would dynamically create controls (and sub-controls of those controls...) on the OnInit event on numerous web control panels. And then later validation methods would check those dynamically created controls for valid data. This continues to work just fine for my web site. However, I need to be able to validate that data without my website (as in this will just be server side). The simpilist solution appeared to be to just have the panels initialize and then run the validation methods. That'd be great...if I could figure out how to initialize those panels server side without a web page.
Can this be done? Is there any way to get a panel to initialize without having a page to display that panel?
That way lies madness - you could use reflection to call the control's InitRecursive method, but it needs a Page (among other things) to run correctly.
You should extract the validation code into a new class that you can call from your server code an change your WebControl to use that class as well.
Try RenderControl.

Resources