My continuous learning of SharePoint, XAML, Silverlight, Windows Phone 7, Windows 8, Office, VSTO, C#. (by Steve Pietrek). Instructions provided describe how to access REST services with SSL (HTTPS) enabled using the ArcGIS Silverlight API. This article has a corresponding video that can be viewed here. Resource Dictionaries are a powerful feature in WPF and Silverlight that enable developers.
Digital Camera Home > Photo Scanners > Archival Scan Formats. TWO RAW OPTIONS HDRi & RGBI-- Archival Scan Formats? By MIKE PASINI Editor The Imaging Resource Digital. Learn how to use Silverlight, from beginner basics to advanced techniques, with online video tutorials taught by industry experts.
Creating and Consuming Resource Dictionaries in WPF and Silverlight - WPF & Silverlight Designer - Site Home This article has a corresponding video that can be viewed here. Resource Dictionaries are a powerful feature in WPF and Silverlight that enable developers to organize and consume reusable resources. After completing this walk through you'll understand how to create and merge resource dictionaries in WPF and Silverlight; how to add, consume and modify resources in the dictionary using the tools provided by the WPF and Silverlight Designer in Visual Studio 2. What is a Resource?
Before diving into resource dictionaries let's first understand what the term "resource" means when used in the context of a resource dictionary or in a resources section of an object in XAML. A resource is an object declared in XAML.
Silverlight clientaccesspolicy.xml files for the Enterprise (Part 1 of 2) I decided to move this article up the chain in my backlog of articles as I have come across. The Silverlight Multi File Uploader is a free Silverlight 5 application. It can be used to upload multiple files simultaneously to your website. Includes a JavaScript.
In the below XAML we see examples of typical resources; my: is an alias for the System namespace in mscorlib.< User. Control. Resources>. Linear. Gradient. Brush x: Key="form. Background" End. Point="0.
Silverlight Resource Files Localization
Start. Point="0. 5,0">. Gradient. Stop Color="Blue" Offset="0" />. Gradient. Stop Color="#4. FF" Offset="1" />. Linear. Gradient. Brush>. < my: String x: Key="application.
Title"> Resource Dictionary Demo< /my: String>. Double x: Key="application.
Title. Font. Size"> 1. Double>. < Solid. Color. Brush x: Key="application. Title. Foreground"> Yellow< /Solid.
Color. Brush>. < /User. Control. Resources>. One reason to use resources in your applications is to promote object reuse across your application. Object reuse provides consistency across the application. Object reuse also makes it very easy to change the application; since you only need to change the resources and all consumers will pick up the change. The below XAML consumes the above resources. Grid x: Name="Layout.
Root" Background="{Static. Resource form. Background}">. Text. Block. Text="{Static.
Resource application. Title}". Foreground="{Static. Resource application. Title. Foreground}". Font. Size="{Static.
Resource application. Title. Font. Size}". Vertical. Alignment="Top"/>.
Where Can I Locate Resources? Resources are located in resource dictionaries. What I have referred to as a resources section is actually the Resources property (WPFSilverlight) which is of type Resource. Dictionary. When you add resources to the Resources property, you are actually adding them to a Resource.
Dictionary exposed by the object. The Resources property is defined on Framework. Element and is inherited from any object that has Framework. Element in its inheritance hierarchy. This means that resources can be located on Windows, User.
Controls, Grids, Buttons, Text. Boxes, List. Boxes, etc. In addition to an objects Resources property, resources can also be located in a Resource. Dictionary XAML file. How Do I Create Resources Similar To The Example? Create a new WPF or Silverlight project and add the following XAML. Grid x: Name="Layout.
Root">. < Grid. Background>. < Linear. Gradient. Brush End. Point="0. 5,1" Start. Point="0. 5,0">. Gradient. Stop Color="Blue" Offset="0" />. Gradient. Stop Color="#4.
FF" Offset="1" />. Linear. Gradient.
Brush>. < /Grid. Background>. < Text. Block. Text="Resource Dictionary Demo". Foreground="Yellow".
Font. Size="1. 8". Vertical. Alignment="Top"/>.
Using the Brush Editor to Create the Background Select the Grid on the design surface Using the Properties Window: Select the Background property Click the Gradient Brush icon Select the left gradient stop and sets its color to Blue Select the right gradient stop and sets its color to Blue Click the Horizontal Gradient Brush icon Select the right gradient stop and set the Alpha channel 7. Extracting Background Property to a Resource We will now use the "Extract Value to Resource…" feature of the Designer. To exact a property value to a resource, click on the Property Marker, this will open the below Context Menu.
Now select, "Extract Value to Resource…" When the Create Resource dialog opens, change the Key to "form. Background," leave the Destination value to whatever it defaulted to and click OK. Notice that I have chosen to name the resource by its role, as opposed to what it looks like. Adopting this Key naming convention allows a resource to be changed without causing a conflict with the Key name. For example, if the Key name was Blue.
Gradient and I assigned it to each forms Background property, then later wanted to change it to a green gradient, the name would still be Blue. Gradient but the color was now green. By naming the Key form. Background, I've not associated any color or type of brush with the name.
In the below image we can see what the Designer tool did for us. Created a Resources section in XAML for the Demo User. Control Moved the Linear. Gradient. Brush to the Resources section Added the Key to the resource Set the Grid Background property to the newly created resource Extracting the Text. Block Properties to a Resource To help us quickly locate the Text. Block properties that have been set, we will now use a very cool feature of the Designer's Properties Window, "Sort by property source." Select the Text.
Block on the design surface Using the Properties Window, click the "Sort by property source" Button (top red arrow) This groups all properties together that have been changed from their default value by setting them locally, using a binding or a resource Using the Extract to Resource feature, extract the properties indicated by the red arrows Text – application. Name Font. Size – application.
Name. Font. Size Foreground - application. Name. Foreground After extracting the above properties to resources, your XAML will look like the below image. The required root Grid and application title Text. Block properties are now set for reuse.
Notice the yellow highlighted line of XAML. This alias was added by the Designer tool.
When the Designer tool adds an alias, it names the first one, "my" the next alias, "my. For very small forms with a single alias this may be acceptable. However for most projects you'll want to use meaningful names for your aliases. You have several options open to you to change these. First, if you define the alias in the XAML file before extracting to a resource, the Designer tool will reuse the alias when referencing the same namespace and assembly. You could also edit the XAML after the Designer tool creates it.
After you have worked with WPF or Silverlight for a short time, you'll get an understanding of the aliases you use and can just add them to your new XAML files before you start adding other content to the XAML file. Resources are Declared at Different Scopes. The below image is the anatomy of a simple WPF or Silverlight application that is composed of hierarchy of objects nested within each other.
Note. Silverlight does not have system scoped resources like WPF does. When we say resources are scoped, we mean that resources can be defined at various levels of the application hierarchy. Resources defined at a certain scope are available to all elements in or below that scope. For example, we previously extracted property values to the User. Control scope and the child Grid and Text. Block could access those resources.
Now, what if we wanted to consume those same resources we extracted earlier in another User. Control; how could we accomplish this? To make the resources available, to other User. Controls or Windows in the application, we need to move the resources to the Application scope.
When moving resources to Application scope, you have several options available to you: Add the resources to the Application. VB), or App. xaml (C#) file Add the resources to a Resource. Dictionary, then merge that Resource. Dictionary at the Application scope Moving Resources to Application Scope For purposes of demonstration, I've cut the User.
Control Resources and pasted them into the Application Resources section. Noticed I also cut and pasted the alias "my: " too. You can also remove the User. Control. Resource from the User.
Control's XAML as I have done the Demo. You'll need to rebuild the application to remove the squiggles from your User. Control's XAML. The User.
Control looks exactly as it did, but is now resolving its resources from the Application scope instead of the User. Control scope. We have just enabled reuse of these resources throughout the application. You can also see how Demo. XAML file. Application. Application. xmlns="http: //schemas. Class="Resource. Dictionary. Demo. App". xmlns: my="clr- namespace: System; assembly=mscorlib">.
Application. Resources>. Linear. Gradient. Brush x: Key="form.
Background" End. Point="0. Start. Point="0. 5,0">. Gradient. Stop Color="Blue" Offset="0" />. Gradient. Stop Color="#4. FF" Offset="1" />. Linear. Gradient. Brush>. < my: String x: Key="application.
Title"> Resource Dictionary Demo< /my: String>. Double x: Key="application. Title. Font. Size"> 1. Double>. < Solid. Color. Brush x: Key="application.
Title. Foreground"> Yellow< /Solid. Color. Brush>. < /Application. Resources>. < /Application>. Demo. xaml < User.
Control. x: Class="Resource. Dictionary. Demo. Main. Page". xmlns="http: //schemas. Ignorable="d". d: Design.
Height="3. 00" d: Design. Width="4. 00". xmlns: my="clr- namespace: System; assembly=mscorlib">. Grid x: Name="Layout.
Root" Background="{Static. Resource form. Background}">. Text. Block. Text="{Static. Resource application. Title}". Foreground="{Static. Resource application. Title. Foreground}".
Font. Size="{Static. Resource application. Title. Font. Size}".
Vertical. Alignment="Top"/>. Grid>. < /User. Control>. Show me how a Resource. Dictionary Used. If your application only requires a few resources, locating them in the Application. App. xaml would be fine. However, in most applications the number of resources grows quickly and must be managed early in the application lifecycle.
Silverlight clientaccesspolicy. Enterprise (Part 1 of 2) I decided to move this article up the chain in my backlog of articles as I have come across this scenario numerous times on the http: //silverlight.
This article will give some basic information that has been covered on numerous other sites and times and give some additional insight on how to handle cross- domain issues in enterprise Silverlight service deployments. Note: This article is pretty long and doesn't really fit well into a blog format (which I find is very limited for effectivily presenting technical ideas on a larger scale). I am going to start moving some of my bigger articles into possible whitepaper format as well. Contents of this article (Part 1 of 2): Background Information about cross- domain service access in Silverlight. Deploying cross- domain policy files on Enterprise Servers Examples of Enterprise cross- domain configurations. Problems with maintaining the clientaccesspolicy.
Http. Handler solution for dynamic clientaccesspolicy. Enterprise Walkthrough - Creating a basic Http. Handler for clientaccesspolicy. Basic Clientaccesspolicy Handler Part 1 - Http. Handler basics. Basic Clientaccesspolicy Handler Part 2 - Adding some code. Deploying managed Http. Handlers on IIS 7.
Testing managed Http. Handlers (inside the browser)Trouble. Shooting. Summary Download link for Http.
Handler source code Background Information about cross- domain service access in Silverlight Silverlight 2 uses services as its primary source of retrieving data across domain boundaries. Once you enter the services and web application domain, you are exposing your content to malicious attacks. One way Silverlight prevents its applications from launching malicious attacks on other sites is through opt- in cross- domain access. This means the site has to say yes in order to receive and respond to requests from a particular domain. This opt- in feature is controlled by a clientaccesspolicy. If you have done any WCF programming with Silverlight, this should be familiar to you. If not, check the basic information on the MSDN site here. Suppose that we have a Silverlight application hosted on http: //contoso.
XAP file). This application has a service backend that retrieves data from http: //mycontososervice. These are obviously on two seperate domains and we have a cross- domain issue. By default, this scenario will not work. We need to create a clientaccesspolicy. The location of the file must be located on the root of the site (http: //mycontososervice. Here is a graphical representation of what is going on: The clientaccesspolicy. This is a very important point. Most Silverlight developers that are starting out make a mistake in that they think the clientacesspolicy.
Silverlight application is hosted. This is not true and can cause many debugging headaches. The clientacesspolicy. NEEDS to be deployed on the server hosting the WCF service so that Silverlight can properly consume it. Note: For simplicity reasons, I am not adding the crossdomain. Flash. Silverlight also uses this file in case the clientaccesspolicy. This is done for obvious reasons as Flash/Flex has a bigger install base and Silverlight is simply leveraging a possibly pre- existing cross- domain file.
Example of the format of the clientaccesspolicy. Example of the format of the clientaccesspolicy. ONLY to contoso. com: Note: Notice how the only change was to add the < domain uri="http: //contoso. This is more secure and other domains will be disallowed from making service calls. Clientaccesspolicy.
Deploying cross- domain policy files on Enterprise Servers One of the key aspects of a clientaccesspolicy. In our example above, the request is http: //mycontososervice. In order to achieve this on IIS, we would simply place the clientaccesspolicy. IIS: c: \inetpub\wwwroot folder). If you want to grant multiple domains access, an admin simply can modify the clientaccesspolicy. As mentioned above, Flash has an equivalent cross- domain configuration file to Silverlight called the crossdomain. This file has a different format; however, it serves the same purpose as the Silverlight clientaccesspolicy. Let's take look at how some of the largest companies based on services use this file. You can try this yourself by using any browser.
Examples of Enterprise cross- domain configurations: Example of the Amazon crossdomain. Example of the My. Space crossdomain. Some notes to take away from the two examples above: Root domains are different and this obviously makes the domain calls cross- domain. (i.
You need to list all the different domains Sub domains also define cross- domain calls (i. You need to list the different sub domains. Secure and unsecure (http vs. As you can see, maintaining these files can get quite complex very quickly in more advanced scenarios. These files need to be accurate and improperly formatted xml config files can cause the validation of the configuration to be invalidated. Problems with maintaining the clientaccesspolicy.
Maintaing the clientaccesspolicy. However, maintaining complex properly validated clientaccesspolicy. One single fat finger and the file can invalidate all service calls. Improperly adding or not removing a domain can cause a serious security violation. Scenarios where manually maintaining the clientaccesspolicy. You are maintaining 2 different RIAs and want to keep both XML files in sync (I know Silverlight can use Flash's file, but we want to prepare for mass Silverlight deployments) The clientaccesspolicy. You have over 1. 0- 1. The clientaccesspolicy.
The solution you offer allows clients to access the site through specialized domain (i. Architecture/hosting uses Saa.
S model (You host services others can consume) Lots of changes occur to the file and you want to eliminate the "human factor". The web service server is part of a web server farm or a cluster. The files need to be in sync almost instantaneously. Client anonymity is important (i. You don't want to expose who is consuming your services) Obviously some of these challenges can be mitigated with other security measures and designs. However, let's assume that in your scenario you have a properly working architecture/deployment and the clientaccesspolicy. What can you do? Http. Handler solution for dynamic clientaccesspolicy.
Enterprise To overcome complex cross- domain scenarios by using some of the more advanced features of ASP. NET, we can mitigate some of the manual work that comes with creating cross- domain policy files. Http. Handlers are one way to solve some of the problems I listed above. Httphandlers are a pretty powerful tool for ASP.
NET applications that extend ISAPI extensions. There are many uses for Httphandlers and one of them is to map certain web requests to specific handler functionality. (I am not going to go over handlers in detail. If you need more information, try this link: http: //www. We can create an Http. Handler that will see a request for a clientaccesspolicy. Instead of manually copying the file off of the root server, we can generate the file dynamically.
Walkthrough - Creating a basic Http. Handler for clientaccesspolicy.
We are going to create a few sample handlers and add functionality to each one. Basic Clientaccesspolicy Handler Part 1 - Http. Handler basics Open Visual Studio 2. Select "Class Library" and let's call the project "Silverlight. Cross. Domain. Handler" (Note: Do NOT create a Silverlight Class library.) Add a reference to the System. Web assembly. (We are going to be creating an ASP. NET Http. Handler which requires the IHttp.
Handler interface found in the System. Web assembly) Add a new class to the project and call it Basic. Clientaccesspolicy. Handler. cs. Navigate to the class and change its access modifier to be public. Add a using statement "using System. Web; ". (This is needed as we will be implementing the IHttp.
Handler interface.) Implement the IHttp. Handler interface by simply typing ": IHttp. Handler" after the Basic. Clientaccesspolicy. Handler class name. Right- click on the IHttp. Handler name and select Implement Interface - > Implement Interface. This will create the methods we need to implement for this handler to work.
You should have something like this now: (If not, simply just copy and paste the code from below) using System; using System. Collections. Generic; using System. Linq; using System. Text; using System. Web; namespace Silverlight.
Cross. Domain { public class Basic. Clientaccesspolicy. Handler : IHttp. Handler { #region IHttp. Handler Members public bool Is. Reusable { get { throw new Not. Implemented. Exception(); } } public void Process. Request(Http. Context context) { throw new Not.
Implemented. Exception(); } #endregion } } Basic Clientaccesspolicy Handler Part 2 - Http. Handler adding some code Change the getter for the Is.
Resusable property the exception to simply "return true; " (This allows the Handler to be pooled.) Delete the "throw new Not. Implemented. Exception(); " inside the Process. Request method. We are going to replace this with code. We are going to use LINQ in order to build the clientaccesspolicy. We can just as easily use String. Builder, Xml. Documents or other forms. (This is NOT meant for production. This is just illustrating a concept.) Add a reference to the System.
Core assembly. (This houses the LINQ methods.) Add the following using statement: "using System. Xml. Linq; " . Copy and paste the code below and insert it into the Process. Request method. The code below uses the Parse method from the XDocument class to load a string and transform it into an XDocument object.
XDocument clientaccess. Policy. Doc = XDocument. Parse(@"< ? xml version=""1. Response. Write(clientaccess. Policy. Doc. To. String()); Your class file should now look like the following: using System; using System. Collections. Generic; using System. Linq; using System.
Text; using System. Web; using System. Xml. Linq; namespace Silverlight.