Create and use global view in C# WP8 XAML - xaml

I was trying to digg something on this topic before, but have no luck. What I'm trying to achieve is pretty simple, but seems to be hard to achieve :-)
I have a WP8 app (C# XAML) and I need to implement global messages (something like toasts) which could be displayed across whole application no matter of current navigation processes. Such toast message(s) should be displayed even while user is navigating between pages. To use the built in toasts is not a way (in case some other solution exists) since I'm possibly in need to have more than one message displayed at the same time (each one is independent of another) and should disappear after specified period of time.
So, my question is. Is there any way how to implement and use some kind of global view instance which sits above all pages and can be called from any page?
All I found until now is the possible ability to use PhoneApplicationFrame, but I would like rather avoid that if possible. I'm still unsure if this is even the way it can be done, but I suppose so. Do you have any alternatives or assurance this is possible and only way to achieve this goal?
Thank you all for your time and answers.

You can have UerControl for the Functionality you are looking for. It is Control that has its own Seprate Xaml and cs file. You can call it from any page into your Project. UserControl provides the base class for defining a new control that encapsulates related existing controls and provides its own logic. You have a XAML file and C# class file for a user control. The class file extends the UserControl class and adds additional behaviours and properties. The XAML file encapsulates the composing controls, the styles, the templates, animations and whatever necessary to form the UI. Since it is a just composition, it is really easy to create. for more Reference you can go here Why and how to create a User Control in Windows Phone

I have ended up rolling my own custom navigation using a single master page. As such any global controls are instantiated once at startup. Navigations are called from my viewmodels and result in usercontrols being removed and added to the visual tree as necessary (using transition animations to give the impression of page navigation) This works but im not sure whether it is best practice and would appreciate some opinions and comments on this. Certainly it solves the problem of global views described.

Related

Xamarin - How to view rendered Xaml

Our team is working on an effort to improve the accessibility of our mobile application developed with Xamarin. One area we're having trouble tackling is Focus Path (i.e. tab order). Research examples suggest that the focus path should naturally be top down if the layout is created correctly. However, the examples are often simple and not real-world with respect to complex layouts and navigation (or whatever Marketing dreams up). We have several re-usable 'controls' and templates the get injected as part of the layout like main navigation, search, etc. The focus path, or tab order, is all over the place.
Tools that offer live preview/xaml edit only work against the opened xaml file which in many of our cases is just part of the overall xaml that makes up the screen.
Looking for a way to view 'rendered xaml' that makes a up a given screen in a xamarin mobile app. We need to see the final xaml that includes all of the dynamic controls, templates, etc. that get mashed together. This may help us understand what's happening to our focus path.
EDIT: we've found that forcing/setting tabindex does not help.
Is there such a tool or process?
I was using https://www.livexaml.com/ for such a purpose.

Where does ExtJS Action fit into MVC pattern

I really like concept of ExtJS Actions. I looked at this example and it is (almost) exactly what I need. Only thing is that I'm trying to use MVC pattern.
I have:
invoicelist (view)
Inovice (controller)
Invoice (model)
Invoices (store)
Where and how do I put definition for Action? Should they be in controller? How to call them and reference them? I need several Actions and they will be in context menu and in menu in invoicelist's toolbar.
Good question. It seems Actions break the MVC pattern by somehow combining View and Controller paradigms under one roof. Because they have handlers they carry functionality with them as well as UI elements like text and icons. However they are not components - in ExtJS sense of the word. Hence you can't target them with a selector.
The best way to think of them is as a config object. No more, no less. A config object is meaningless by itself - and can not be targeted. Same with Actions. They can actually be used as a config object to buttons for example.
Now where should they go? The answer to that I guess is really up to you as a designer. Since they don't confirm to strict MVC pattern you get to make a decision based on how widely you need a particular action be accessible. For a truly global action that is shared by many views you might even put it in the application config: MyApp.app.actions["delete"] for example.
Controller might be a good place to put it if that controller will configure multiple views and wire them together with stores. They can potentially wire up multiple views with shared actions.
Hope this helps. Good luck :)
just do a someview.fireEvent('Yourcustomevent');

ExtJS 4 MVC multiple instances of views and sub/child controller difficulties

I have encountered a problem with the MVC pattern in ExtJS 4. At least, I think I have. Having approached multiple people with this question, and having posted numerous times in the Sencha forums, I am now turning to a broader audience in hopes of getting either a light bulb or a confirmation.
Problem
Your application has the ability to open many different views, some of which themselves are mini-applications. Additionally, a user may wish to have multiple concurrent copies of a view open.
This application is a single-page client-side Javascript application.
The ExtJS 4 MVC model expects you to define all of your controllers in your Application class. These controllers are then initialized when the Application loads. Controllers keep track of views, models and stores.
When you initialize controller A multiple times, say to create more than one copy of a view, you end up with two views that reference the same data stores, and functionally send duplicate events to the Application event bus.
I have refactored my application by adding new prototype methods to Component and Controller to allow for both a) sub controllers (some of my controllers were getting pretty huge) and b) defining stores specifically for the view they work with. The models can still be defined on the controller, just for ease of use by handlers if you need to do something like grab a record from the server.
Question
My understanding of MVC would lead me to believe that models more directly relate to the View than then Controller. I asssssume that ExtJS 4 decides to attach stores (which I think can be seen as wrappers to a more classic model) to Controllers for purposes of encouraging re-use of loaded data, and to optimize away from having many copies of the same class instantiated. It seems to me, however, that one cannot do this if one intends to have many instances of a view available to the user. To my thinking, having many instances is an important option in an OO framework, hence why I have bucked the trend and implemented prototypes on some of the Ext base classes. (Thank you Ext.implement!).
Is there any way to have multiple concurrent instances of a view with different data loaded into them using the out of the box MVC classes and making uses of the provided setters, getters, etc?
I was faced with a similar problem:
Consider a tabpanel for a CRM type application which opens new instances of a view for each client. And say that tab view contains 3 or 4 row-editing gridpanels for interacting with different collections of data relating to that client.
The solution I came up with was based on this from the Sencha forums. In a nut shell, almost all events that are dispatched from a view contain a reference to the view itself. The handlers in my controller's control function all use these to get a reference to the correct view instance.
For dealing with the multiple instances of the same store needed for this, I took this to heart from that post:
For the Store instance on the view or a global one... depends on the
needs. If you are going to use globally then make it global. If you
only are going to need it on the view then put it on the view. MVC is
not a law, you can change it to fit your needs. Technically the
Controller part of MVC is suppose to be the middle man between the
View and Model parts but sometimes that's just not needed. I create
the Store in the view 95% of the time. I'll give you an example...
If you have a Store for products, you probably only need to reference
that Store in your Grid. That usually isn't needed for other parts of
the application. However, if you have a Store to load countries, I
often need it globally so I only have to load it once and can then
set/use that Store in several views.
So I just created the needed store's that relate to a view instance specifically, inside the view's initComponent method. The application did have a few global stores that I created as store classes following the MVC recommendations. It worked out nicely to encapsulate the view instance stores inside the view. Then I only needed one instance of the controller.
To answer your question specifically, currently, there is no ExtJS official recommendation or config for dealing with multiple instances of the same view that use the same store constructor. I have spent some time looking for something like that and the best I have found was this recommendation from one of their forum moderators.
I don't think you ever need more than 1 instance of a controller, regardless of how many views/models you have. See functional example here:
http://whatisextjs.com/extjs-4-extension/fieldset-w-dynamic-controls-7
This can be done, reasonably easily. You need to follow a few rules:
load your controllers at app startup. Don't unload them. Don't worry about the memory or time, it's pretty small even for hundreds of controllers, as long as you minimize and concatenate your js.
Never use the refs or views properties of a controller. You are going to use one instance of a controller, but multiple instances of views, so you never want a reference to a view.
only use event listeners in controllers. You are only going to listen to events on your views. You can always get a (temporary) reference to a view in the event handler via the "cmp" parameter in the handler.
To "launch" a view, create it and add it to another view. To destroy it, destroy it. You don't use a controller to launch a view. You can use the afterrender and beforedestroy events in the controller to add logic.
In ExtJS' MVC the controller is a Singleton for you view. I like how DeftJS thinks about MVC. Each instance of a view has an own instance of a controller. In this way you can put all "controlling rules" in a controller for a particular part of your view, and this will be instantiated only when the view opens.
I did not have any experience how I could use multiple Defts JS apps in the same project.
Of course. What led you to believe otherwise?
Here is an example of creating a custom View which extends from a Window component. You can run this method many times from the same controller and each time you will get a new instance of a View.
"this" refers to a controller that code runs in:
this.getRequestModel().load(requestID,{ //load from server (async)
success: function(record, operation) {
var view = Ext.widget('requestEdit',{
title: 'MyRequest '+requestID
});
var form = view.down('form');
form.loadRecord(record);
}
});
How do you create your views? I see no reason why you cannot pass a different store or config data to every object. Some code samples would help for what exactly you are doing. For example, we have a similar sounding application, and everything is done with extensions. So, if we need a grid, we run
Ext.define('MyApp.grids.something',{
extends:'Ext.grid.panel'
//...
These classes are predefined. Then, when a controller or view is loading this grid, they are using
var grid=Ext.create('MyApp.grids.something',{id:'unique',store:mystore});
As you can see, we can pass in different config options to the same grid each time it is created. We can treat this exactly as you would treat
Ext.create('Ext.grid.Panel');
Except of course that we make some options predefined, and some non-override-able, and so on.
Hope this helped.
Check out this post. The idea there is to take some configuration (like store and itemId) from view config and put it into the viewport config:
// .../app/view/Viewport.js
Ext.define('MyApp.view.Viewport', {
// ...
items: [
// ...
{ xtype: 'testview', store: 'Store1', itemId: 'instance1' },
{ xtype: 'testview', store: 'Store2', itemId: 'instance2' }
]
});
The problem with store will be solved, obviously. Different itemIds will enable you to handle events properly.

HTML in Silverlight

I am making a silverlight interface for a discussion board. The boards web interface allows the usual HTML tags like i,a,img,b,u. So now I need to be able to display that in Silverlight.
This: http://www.vectorlight.net/silverlight/controls/rich_textblock.aspx seemed like exactly what I need except that it hardly displays anything right. Every HTML(i've made sure it's valid with HTMLAgility) string I give it either makes the whole SL app go white, or the block displays all the text on top of each other. Occasionally(with a few VERY simply strings), it will display right.
This needs to work OOB and in, and I cannot use the WebBrowser control as I would need hundreds of instances at a time and it gets slow(tried it OOB).
Thanks.
Have you tried this one?
http://www.sharpgis.net/post/2010/09/15/Displaying-HTML-in-Silverlight.aspx
Maybe it can serve your needs better.
Some others
http://www.isosoft.org/taoffi/post/Html-Content-Viewer-for-Silverlight.aspx
http://blog.gfader.com/2010/05/silverlight-showing-html-content-inside.html
http://www.divelements.co.uk/silverlight/tools.aspx
Component one and Telerik both have silverlight html controls at a cost.
http://www.telerik.com/products/silverlight/htmlplaceholder.aspx
http://www.componentone.com/SuperProducts/HtmlHostSilverlight/

Need to access the Page object in Global.asax in the PreRequestHandlerExecute

I have a huge website (containing around 5000+) pages. There is a theme functionality in the website where user can choose different colors for their profile. Now i want to use the ASP.net theme feature and put different CSS (for different colors) in the theme folder and in Global.asax i want check the user theme and render appropriate link element with the css. But my problem is, i am not able to access the Page element for adding the link in the page.
Here is my code
Dim page As System.Web.UI.Page = TryCast(System.Web.HttpContext.Current.Handler,System.Web.UI.Page)
page.StyleSheetTheme = "Black"
But when i run this code I get a Null reference error.
P.s : My application is very huge so its not possible to have a master page or a base class and inherit it in every page.
Please suggest.
The page is not available in PreRequestExecute. This function is called before asp.net steps in to handle things, and asp.net is responsible for the page. Think of PreRequestExecute as being earlier in the scheme of things, like when IIS is first trying to figure out what to do with this thing it has, the thing is not even a page yet.
You might want to look into some of the other events that you can hook, there are events that would take place after the page has loaded that may allow you to do what you are suggesting.
Rather than going into global.asax for this, consider using master pages. One possibility is to have nested master pages, where the first master page sets up overall layout, and the nested master handles the theme. (Or one of several nested master pages, all referencing the same top-level master page). If necessary, you can use the PreInit event in the page to change master pages, and select the master that matches your theme selection.
You can centralize this function by having your own class that inherits System.Web.UI.Page, and have all your own pages inherit this new class. Handle the PreInit event there. (As well as other useful functions, like page-level handling of unhandled exceptions, general security issues, etc.
EDITED TO ADD: As #aepheus correctly notes, the page hasn't been instantiated at the PreRequestHandlerExecute event. So there's no page class you can access.