background preloader

Articles

Facebook Twitter

Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp. A complete Silverlight 3 Drag and Drop solution, inspired by Fle. In RIA’s it often happens that you need some kind of drag and drop support. Flex has provided in this support, with it’s DragManager class. This is a class with static methods like StartDrag, you only have to supply a UIComponent, and the DragManager creates a nice transparent image, which follows the mouse and gives you visual feedback about whether the components underneath your mouse will accept the drop. Silverlight was lacking drag and drop support, until now that is! Creating The DragManager class The challenge of building a DragManager class, is to keep a generated proxy image, in sync with the mouse cursor. This is harder in Silverlight than in Flex, because the root visual of Silverlight, can be any Panel. In Flex you can just paint on the highest container in absolute coordinates, this isn’t the way it works in Silverlight.

We will go through this in a couple of steps: First, creating a drag image, this a snapshot / photo of the control that initiates the drag. 1: /// <summary> RIA Services : The Official Microsoft Silverlight Site. Skip to main content Silverlight Developer Center Sign in United States (English) © 2014 Microsoft. Getting started with the repository pattern in Silverlight - The. Getting started with the repository pattern in Silverlight The repository pattern is quite a common design pattern when working with databases. And for a good reason as standardizing code on design patterns it makes it easer to read and understand. The typical repository pattern in .NET Most of the time the repository pattern looks something like this. public interface IRepository<T> IEnumerable<T> All(); IEnumerable<T> FindAll(Func<T, bool> exp); Note that I am only implementing the loading of data.

In regular .NET code that is just fine but in Silverlight not quite. So the logical implementation in Silverlight would be more like this where the action is whatever needs to be done when the request finishes. void All(Action<IEnumerable<T>> action); void FindAll(Func<T, bool> filter, Action<IEnumerable<T>> action); unfortunately that doesn’t quite work when we use an ADO.NET Data Service and the Entity Framework to get to our data. The Silverlight implementation of the repository pattern Enjoy! Consuming an ADO.NET Data Service from Silverlight - The Problem. Consuming an ADO.NET Data Service from Silverlight When developing Silverlight line of business (LOB) applications we often need to get at some data from a database.

There are various ways to do so. One option that is easy to get started with with is creating an ADO.NET Entity Data Model (EDM) and exposing that entity model using an ADO.NET Data Service. Getting started The first thing we need to create is an ASP.NET Web Application. This is basically going to act as a container for our Data Service and our Silverlight LOB application. Next we need to add the ADO.NET Entity Data Model. When the popup ask if I want to create a new EDM based on an existing database or start from scratch I selected the existing database option and pointed it at my Northwind database.

Next step is creating the ADO.NET Data Service to publish the entity model. If we open the Northwind.svc.cs file we need to enter a few details before we can proceed. Testing our data service Creating a Silverlight LOB client. Silverlight Custom Content Control with Events. Silverlight Custom Content Control with Events. Silverlight Custom Content Control. Synchronous Invocation of Delegates with the Silverlight Dispatc. Introduction In this post, I would like to briefly discuss the System.Windows.Threading.Dispatcher class, and the significant differences between its Silverlight and Desktop CLR implementations.

We are going to look at solving two things: Consuming the UI’s Dispatcher in Silverlight before a page has been instantiated. Allowing for synchronous invocation of delegates on the UI thread. Background Recently my good friend Sacha Barber published an article, in the comments of which we briefly touched on a cross threading issue that we have both experienced with the Silverlight Dispatcher class. Silverlight Thread Affinity When working with Silverlight, one has to contend with the usual single threaded apartment model (STA) that is also present when working with WPF or Windows Forms. There is an excellent article describing the Dispatcher in detail. Consuming the UI’s Dispatcher Application.Current.RootVisual.Dispatcher Synchronous Invocation of Delegates on the UI Thread Using the code: Conclusion.

Reusing .NET Assemblies in Silverlight. Table of Contents Introduction Long before Silverlight 1.0 was released, it was actually called WPF/E or WPF Everywhere. The idea was to allow you to create WPF like interfaces in your web browser. This can be seen in a very small way in Silverlight 1.0. As a technology parallel to .NET, Silverlight is not part of the .NET family. Furthermore, despite the rumors, Silverlight also shares the exact same module and assembly format as .NET. To answer this, we need to understand that just because an optional helper tool (i.e. Fortunately, there are ways around Visual Studio's fascist regime. The Assembly-Level Technique For this technique, you need to understand what's going on under the covers when you try to add a .NET reference to your Silverlight application in Visual Studio. In this case, Visual Studio 2008 uses the Microsoft.VisualStudio.Silverlight .NET assembly. Below is the sample code we will be working with for this part of the discussion.

ILDasm DotNet.dll /out:DotNet.il Conclusion. Understanding WCF Services in Silverlight 2. If you like this document, please consider writing a recommendation for me on my LinkedIn account. Contents Introduction Regardless of what platform you are working with, you need some mechanism for dealing with errors. When it comes to using WCF in Silverlight we are all very fortunate to be able to build out solutions on the back of many tried and true techniques for error management.

When working in this context, we are dealing with basic SOAP messages (that is, XML) and WCF's abstraction of those messages, neither of which are new to the world. If you haven't done so already, you should read the first part of this document entitled Understanding WCF Services in Silverlight (here after "previous document"). You may consider this document an appendix to that one.

SOAP Review Before we take a look at error management over SOAP services, we will take a moment to review SOAP messaging. Here is a message the service could possibly send back to the client: Handling Errors Applying to WCF. Writing WPF/Silverlight compatible code. Part 2: Dependency Prop. Note for future readers: These series discuss WPF and Silverlight versions that are current stable versions at the time of this writing – WPF 3.5 and Silverlight 3.

These are ongoing series of posts on the subject of WPF/Silverlight compatibility. New posts will be added to the Table of Contents post as they are written so bookmark that post or just subscribe to my RSS feed. DependencyProperty.Register Dependency properties are one of the core concepts of both WPF and Silverlight. 1: public static DependencyProperty Register( 2: string name, 3: Type propertyType, 4: Type ownerType, 5: PropertyMetadata typeMetadata Obviously if you want to create cross-platform code you should use that one method all the time in WPF. No FrameworkPropertyMetadata For most WPF framework-level application development purposes, FrameworkPropertyMetadata is the type used for dependency property metadata, rather than the base metadata types PropertyMetadata or UIPropertyMetadata. from MSDN. No Value Coercion. Upload de fichier en Silverlight 2 en C# sur un serve. Les applications Silverlight n'ont pas accès aux ressources de l'ordinateur client.

Elles sont en effet exécutées dans une sandbox (bac à sable) ce qui permet notamment d'empêcher l'appel à des API du système d'exploitation, d'empêcher l'accès à la base de registre, ... Bref, de protéger l'utilisateur contre tout code malicieux. Par contre, le contrôle OpenFileDialog permet d'accéder en lecture à des fichiers (avec l'accord de l'utilisateur, puisque c'est lui qui va sélectionner un fichier). Grâce à ce contrôle, Silverlight peut donc accéder à un fichier. Cependant, ce n'est pas suffisant, nous sommes encore côté client. Pour uploader un fichier sur un serveur, on va donc devoir l'envoyer sur celui-ci. 3.2.1.NuSoap▲ NuSOAP est un ensemble de classes PHP qui permet à un développeur de créer des web services SOAP. Plus d'infos sur NuSOAP ici. Ensuite, il suffira juste de copier les classes qui sont dans le répertoire lib de l'archive sur notre serveur. var $soap_defencoding = 'ISO-8859-1'; <?

View Models: POCOs versus DependencyObjects. This post is part of a short series I am doing on MVVM infrastructure. In this series, I will share some thinking and code that has helped to produce cleaner, simpler MVVM code in my applications. Related posts: If you're leveraging the MVVM pattern in your WPF/Silverlight development, you will quickly be faced with a decision regarding the implementation of your view models: should they be DependencyObjects, or POCOs (Plain Old CLR Objects)? I've seen and worked with applications that use both of these options. This post is intended to discuss these two options. It certainly won't touch on all issues and nuances of either option, but it will cover the main ones I have found to be problematic. I will order them from least significant to most. Performance I was hesitant to even mention this one because I haven't done any measuring and haven’t found it to be a problem at all.

Lower memory usage. Property Change Notification in a Related View Model Serialization of View Models Code Readability.