Making Silverlight App plugin capable - silverlight

I want to know about general methods to dynamically load content into your silverlight application.
More specifically, I want to create something like a widget-based application, where all GUI objects are small independent widgets. I want to provide a static chrome, like a frame, hosting the actual widget, that is loaded from an extern source like a website or is uploaded by the user and is shown in this frame.
The questions are:
What does the widget author specifically have to provide, in order for me to load his widget application into my application? I imagine I have to query the provided DLL for something like a ViewModel and its DataTemplate, a UserControl or even a XAP File. What would be the best way? The external widget should also implement a certain interface, so that the outer application can call methods like Loaded and Unloaded on it.
Small code samples would be appreciated.
What about security? How do I prevent the inner widget application to access my outer application. I think the widget app could go up the control tree or access the DataContext of my frame control, hosting the application. Is this an issue? If so, how to solve it?
Thanks in advance!
Andrej

You can dynamically load controls from dlls that your widget authors could provide, MS's Mike Taulty's done a walkthrough.
Microsoft also have Prism which allows you to break up your silverlight code in a modular fashion. I haven't tried it yet to see if it's suitable for loading individual controls, but my impressions of what I've read about it seem to indicate it has a framework for doing that.
As for security, they would have access to the rest of the application, so perhaps this isn't suitable.

Related

Client XAML Customization in Silverlight

I am working in Silverlight 4.0 and have created a web application which is intended to be used as a utility for others. I have set up several screens using XAML in particular configurations as the UI, however I imagine that some people would like the option to customize the pages of the application. Is there a way they can do this? The XAML is not in the XAP file, it is compiled into a DLL, so
The answer depends on what kind of customization you want to offer your users. If you want users to be able to rearrange elements of the UI, you would not have them modify XAML. You would want to implement a "web part" interface in which users can move elements of the screen around, similar to Visual Studio. The major control vendors (e.g. Telerik, Intersoft, etc) include a Docking-style control.

Silverlight Composite application

I'm trying to figure out what would be best solution to the problem I'm facing. I have a Silverlight application which should be composed from different modules. I can use Prism, place regions and load modules and fill regions with loaded modules but this is not enough in my situation. Here's what I want to accomplish:
For most views that gets loaded from different xap files, I should place an element somewhere in the shell, which will perform navigation to the dynamically loaded view.
That element (which links to dynamically loaded view) should support localization and should have dynamically assignable data templates, different module links should have different content/data template (I'm thinking writing data templates in xaml files on the server and reading them from silverlight via XamlReader, maybe there's a better way?).
Uri mapping and browser journal should work with navigation. Silverlight default navigation mechanism better suits my needs than the one found in Prism.
The architecture should support MVVM.
I think thats all. I just couldn't think of a good architecture which will satisfy all my needs. Any help would be greatly appreciated.
I do not know of a single product/solution that would cover all your requirements, so here are some comments on each:
If one area of the shell has a region that supports multiple items, you just register a control of type link/button etc with the same region name in each module. For example we register views based on the Telerik TadRibbonTab (instead of UserControl) with a region named "views" which is a RibbonBarTab with a region named "views". Every module then adds its its own button to the list. You can do the same thing with any multi-item container.
Localisation is a completely different issue and can be solved in a number of ways. See my answer here: Load Resources ".resx" from folder in Silverlight
A custom navigation mapper can be made to behave like the standard one, without messing up the support for Prism regions. The one we created encodes GUI information such as current selections (current view and item selections etc) into the URL. That means we are in total control of the state and the URL controls the state.
Hardly anything stops you using MVVM as that is one small feature for separating views from code-behind data.
I will be interested in what other solutions are proposed as we are always looking for new ideas too.

Alternatives to WebBrowser control in WPF?

We are working on a WPF app with the web browser control. When the user drags the window, the web browser lags behind the window as it drags.
Does anyone know how to solve this issue? Failing that, does anyone know an alternative to the web browser control itself?
Thanks!
Yes, as long as you don't require IE specific features you can use Awesomium which basically gives the same browser engine used by Google Chrome except for everything is rendered in pure WPF. For a while it was open source but I believe it is becoming a commercial product.
I haven't heard about any Native WPF WebBrowser Control. The only options I know are based on Win32 controls which are wrapped into WPF controls in order to displayed. (See more details at http://msdn.microsoft.com/en-us/library/ms752055.aspx )
Recently I have to use the WPF wrapper for the WebBrowser control, and it's very limited regarding the options available for the developer. During my research I found that you are able to inject scripts or html content in order to modify the page behavior. Also, you can call .NET code (e.g. CSharp function from Javascript).
However tasks such as accessing the cache, modifying cookies are difficult task or changing the web browser behavior are very difficult. Here is when you will have to use DLL Imports in order to invoke unmanaged routines (see http://msdn.microsoft.com/en-us/library/aa984739(v=vs.71).aspx )
It's possible to look for an alternative WebBrowser control such as:
http://code.google.com/p/csexwb2/
http://wpfchromium.codeplex.com/
I hope this helps
You can try CefSharp.Wpf which uses Chromium as a base browser. You can find it on NuGet

Starting out Silverlight 4 design

I come from mainly a web development background (ASP.NET, ASP.NET MVC, XHTML, CSS etc) but have been tasked with creating/designing a Silverlight application. The application is utilising Bing Maps control for Silverlight, this will be contained in a user control and will be the 'main' screen in the system.
There will be numerous other user controls on the form that will be used to choose/filter/sort/order the data on the map. I think of it like Visual Studio: the Bing Maps will be like the code editor window and the other controls will be like Solutions Explorer, Find Results etc. (although a lot less of them!)
I have read up and I'm comfortable with the data side (RIA-Services) of the application. I've (kinda) got my head around databinding and using a view model to present data and keep the code behind file lite.
What I do need some help on is UI design/navigation framework, specifically 2 aspects:
How do I best implement a fluid design so that the various user controls which filter the map data can be resized/pinned/unpinned (for example, like the Solution Explorer in VS)? I made a test using a Grid with a GridSplitter control, is this the best way? Would it be best to create a Grid/Gridsplitter with Navigation Frames inside the grid to load the content?
Since I have multiple user controls that basically use the same set of data, should I set the dataContext at the highest possible level (e.g. if using a grid with multiple frames, at the Grid level?).
Any help, tips, links etc. will be very much appreciated!
Microsoft has created a great community site for helping people get started with both design and Silverlight here: http://www.microsoft.com/design/toolbox/
It may be far more than what you need for your current project, but it definitely will give you the training you need to master Design with Silverlight.

How should I architect my Silverlight Application?

So far I have been creating Silverlight apps with all logic crunched into a single xap file. But as the application grows in size,
I seriously think I should break my Silverlight application into smaller multiple independent applications.
I would like to know how others solve this increasing size problem??
If you're looking to make some changes to your application, by refactoring it and splitting out parts, consider all of these.
Custom controls get their own control assembly
Definitely create control assemblies for any custom controls you develop. Not only do you get the benefit of self-contained controls, and optional use in your current and future projects, you can
take advantage of default control styles
use the cached assembly feature with them
share components with other projects
invest in your core code and controls, instead of investing in cleaning up application logic (if you're using static or style analysis, for instance) - spend your time where it will make the most impact
Consider dynamically loading new assemblies
There are some methods available for dynamically loading additional code into your app domain, it may be possible to abstract out less-often used parts of your app, and use this to load in those components. This is a more complex and involved app, but it can improve start-up performance.
It'll take time to split out the code into other assemblies when you're looking at a large application, and testing it can be a challenge. But you can end up with "sub-pages" and parts of your app being loaded only as needed.
Taking the time to design a system to load in new functionality and parts of your app, and architecting this framework, can take time to do right. This typically is using AssemblyPart to load a new assembly that you can reflect into and instantiate new objects from.
Merged Resource Dictionaries
Resource dictionaries can allow you to store styles, control templates, and other resources outside of pages, and outside of your App.xaml.
Cached Assemblies
Once you move to Silverlight 3, you can use the cached assemblies feature to store individual assemblies outside your .Xap, alongside, on your server - and as a bonus, those assemblies will be cached on the machine for quite some time.
A resource diet
Are you really using all of your graphic assets, XAML, controls, string resources, etc., that are stored inside your XAP file? Audit it from time-to-time and make sure you're getting the most bang for your byte.
A splash screen
If you're simply trying to improve the performance (download time) for your application initially, consider creating a splash screen. The Silverlight Toolkit samples have one - it's a simple Silverlight page that will load and display while your .Xap downloads.
Remote graphics
Instead of including image resources right inside your application/XAP, move your images to your CDN or server, so they can be loaded only as needed. This is often a nice and quick win.
Simplify your app
Make sure you actually need it to be XAML-heavy, graphic-heavy, etc. Maybe it can be simplified!
You should distribute your Silverlight modules using PRISM or MEF frameworks.
Visit http://mef.codeplex.com/

Resources