Prism for Xamarin.Forms unable to AutoWire - c#

I am trying out Prism.Forms for my next client project. Unfortunately, I am seeing a strange behavior with my samples.
Pretext
It seems like XF or Prism does not like me including an existing XAML page (also mentioned by Brian Lagunas - The man - himself at the Evolve session). But renaming a page also throws it off and the ViewModelLocator can't seem to locate the ViewModel anymore. Even if I re-create the page with same name, It can't find it ViewModel. Manually setting the BindingContext works, but I am trying not to create my dependencies for constructor injection.
Question
While working on existing code, a minor change caused NullReference exception when using NavigationPage as a root. Here is an example of a working sample app
https://github.com/hnabbasi/xamarin/tree/master/XFPrism/XFPrism
I am using a NavigationPage and pushing a ContentPage. Then I push another ContentPage, then I show a Modal page via button click and communicate. I send parameters back to Second content page via NavigationParameters.
To break it, simply try to swap the ISayHello service with IPageDialogService. I am not sure what's going on that's breaking it.
Thanks in advance :)

The INavigationService is a named type and as I recall a known limitation of Unity is that named types must precede unnamed types.

As mentioned by Dan S. in the comments. The MainPage is not set when I was calling the PageDialogService to display the alert, hence the NullReference.
In case you really need to do something like this where you want to somehow wait for something to finish before doing an operation, try Task.Yield().
I fixed my scenario as below,
// will yield for current operation of page appearing
await Task.Yield();
// by now, the page has appeared and set, so this should work fine
SayHiCommand.Execute(this);
I have used this workaround in the past. If you know a better way of handing this, please comment away.

Related

MAUI Shell + TabbedPage

I have application based on Shell. Application contains pages with tabs which are deffined in Shell. Everything works properly and correctly.
I need create second level page with tabs whitch contains options for return to previous page. In the case of standard "ContentPage", "Routing.RegisterRoute" and "Shell.Current.GoToAsync" it is no problem. However, if I create a TabbedPage like this, my application ends with exception:
0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception
I am aware of this information:
TabbedPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use TabbedPage in a Shell app.
However, I am not sure if this also applies to the second level page, or only to pages that are directly referenced in Shell.
How can I create second level page with tabs?
Is there anyone who has encountered a similar problem, or someone who can give me advice?
Thanks a lot
Using shell, you are limited to content pages.
Navigating to such page is not a problem. Calling GoToAsync will give you the "second layer" you request.
The more interesting part is how to implement tab control, so you have tabs in that ContentPage.
One way to solve this is by using BindableLayouts.
(Here is a good example: https://dev.to/davidortinau/making-a-tabbar-or-segmentedcontrol-in-net-maui-54ha)
You can make really neat UI with this.
It will be worth your time.
Ask if you have any questions.
You can combine TabbedPage, FlyoutPage and NavigationPage instead of shell if you really want to create second level page with tabs. Obviously shell is based on flyouts and tabs, so if you use FlyoutPage and TabbedPage alone in your project, it will be more flexible and troublesome than the shell.
These are the documents about the specific use of FlyoutPage and TabbedPage, you can refer to them if you need: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage?view=net-maui-7.0 and https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage?view=net-maui-7.0.
Hope this will help you.

Awesomium webcontrol

So I've been trying to use something other than IE for my webcontrol in a side-project of mine (C#, WPF project type) and I was looking around for alternatives and have tried in the past but failed to implement them.
I decided to try again and implement awesomium, however it is still confusing as always and doesn't have any straight forward examples for me to use as a base.
Would someone be able to show me how to implement awesomium for a webview/webcontrol? My vision is to have it navigate to a shoutbox website, and while my application is still open to keep it there (i.e not refresh it so that it doesn't lose anything) as it is being shown in the space of tabitem.
I have used Awesomium, but the last version I used was 1.6.1, and there are some differences between that and the current version - they've actually made things easier.
The documentation says that you should be able to force navigation of the control simply by setting the Source property:
<osm:WebControl Name="webControl"
Source="http://www.google.com/"
/>
If you find the Source property is not bindable then simply revert to using some code behind in the view - subscribe to a property change event from the viewmodel (or from an event broker if you are using one), and change the Source property in response to an event.
I believe, the problem with the Source property is that if you are setting it to the same URI to refresh, it won't refresh because of a bug. It is documented on their github page and their answers page.
As workaround, to refresh your page correctly you need to pass a fake URI first and then your page again to your binding property, like this:
CurrentSource = "FakeUriString".ToUri();
CurrentSource = "http://www.yourpage.com".ToUri();
Keep in mind, my current version of Awesomium is 1.7.4.2 and they may fix this issue in the future as they stated in their issues page.

Last view superimposed on current view when double-back navigating

I do the following navigation pattern:
Navigate into the app (and it's main view)
Go into a detail view that fetches something from a REST server (that is - it shows a progress indicator for a few seconds)
While progress indicator still is shown, I click the back-button twice in quick succession (easy to do by mistake)
The app returns to the main view, but with the content of the detail view superimposed on it.
A screenshot of the resulting mess is shown below.
This was recreated both on a Nokia Lumia 800 and HTC Titan.
First of all - what the h..? And is there anything I could have done to make this happen?
There is no exceptions (or anything else) shown in the output. The only thing happening in the OnNavigatedFrom() method of the detail view is nulling out the background image (for memory reasons). It happens in other views as well.
My idea is that the draw method on both views are called on different threads, leaving only the main view to be responsive.
Any idea as to what has happened here, and how I can fix this bug?
This type of issue happened to me when using TransitionFrame from Silverlight for Windows Phone toolkit. Using transitions when navigating from page to page can cause this if the user taps on back button once or twice while the transition/navigation is in progress.
I believe it's a bug, but couldn't find it reported at the official CodePlex site of the toolkit, therefore I don't know about any reliable solution or workaround except trying to handle the back button press on the page that's causing issues. In other words, catching the back button/key press and either disabling it (I'm not sure that this would pass certification!), or simply prompting user with a MessageBox that the page is still loading and if they are sure that they want to navigate back, might work for you.
Other solution I can think of is that you avoid using TransitionFrame, but that's not really a solution, right? :)

RadToolTip's RenderControl method

I have an asp.net application which uses the web part framework to allow users to customise their interface. One of the features of this is a catalog of available web parts, one is provided by default, but it can be overriden if you wish to change the layout, etc.
override void RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart)
That, as far as I can tell, is the only way to do it. At the moment I'm creating a panel with all the necessary elements in it, and using the panel's RenderControl method to output it to the htmlwriter. So far, so good. The problem occurs when I try to add a radtooltip to my panel, using the same RenderControl method, and I get the following runtime error:
Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.
I can see why this might be a problem, since the tooltip presumably uses javascript and has to write it to the page - but the RenderCatalogPart method has no knowledge of which page it's going to be outputting to. Is there any way around this or am I going to have to come up with an alternative?
I've posted this on the telerik website but though I'd ask here as well incase anyone has any ideas.
Thanks.
The Telerik ASP.NET controls require a MS AJAX ScriptManager control. I suppose that's why they want to access the page as well - to get a reference to the ScriptManager. Try setting the tooltip's RegisterWithScriptManager property to false and see if the control renders then.
The issue here is that the ToolTips must be created and added as controls in PreRender, so that it can add it's script to the ScriptManager.
Creating a collection of tooltips in the PreRender() method and then writing them to the httpwriter as shown above in RenderCatalogPart fixes the problem.

Handle navigation between several view in a WPF application

I've done several WPF application(not using MVVM) in the past and I had always to implement my own system of navigation between view(instantiate the view once, and then load in a container component, with refreshing required components of my view).
It works, but:
It's always custom, so if a new developer comes he has to learn of it how it works
I'm pretty sure that It's not the most optimized(most of things haven't been done in background worker, ...)
It's a time loss
So I was wondering if there is an official way to handle this ? I don't exactly how, but I was thinking to a navigation component, which can act a little like a tab panel, or a little like the MVC framework in asp.net, we can call a specified controller for an action and some parameters.
Maybe deactiviting bindings when they aren't in the current view
You can use DataTemplates/Styles to customize content of your control ( not only apearance, but data, cause that what you're asking for I presume)
http://msdn.microsoft.com/en-us/library/ms742521.aspx
You can have one Host control and at runtime change its appearance based on events/ states.
Like an example can have a look here:
http://code.google.com/p/svnradar/ how this program manages a appearance of Group and Flat view of repository information.
Another example:
Podder of Josh Smith
http://joshsmithonwpf.wordpress.com/2008/03/05/podder-v2-has-been-released/
Hope this helps.
You may be interested by Lakana, a lightweight (but powerful) framework that can handle for you all the navigation concerns !
Riana

Categories

Resources