Showing posts with label XAML. Show all posts
Showing posts with label XAML. Show all posts

Tuesday, June 19, 2012

Blank Page when Publishing a Silverlight App

I just deployed a new Silverlight application to a Windows Server 2003 box as a new website and was surprised with a blank page when I launched the application. No error messages or warnings, just a completely blank page.

A quick web search and I realized I had been here before. You have to register the MIME types, .xaml and .xap, in IIS for the website. I added them for a previous website, but I didn’t add them at the server root.

Simple instructions to add the MIME types to IIS can be found on Jacqui’s Dev Blog under Deploying Silverlight Application - Why Blank?! Note the first blog post comment that suggests adding the additional .xap application/x-silverlight-app and .xbap application/x-ms-xbap MIME types. I didn’t need to add the .xbap to get my application working, but I did need the .xap.

Wednesday, June 8, 2011

Circumventing the uriMappings in Silverlight

Redirection chaosI created a Silverlight application with the Silverlight Navigation project template that needed to open a link to a PDF file located in a subfolder of the host web application directory. The  project has a convenient uriMapping process defined in the MainPage.xaml XAML to provide search engine friendly links to the various Silverlight pages. It is located in the Windows.System.Navigation namespace. It looks something like this:

<uriMapper:UriMapper>
   <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
   <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>

 

I needed to link to an absolute Url, not a uri relative to the Silverlight app, like http://www.deanwillson.com/downloads/Continuous-Improvement-professional-Org-1st-Edition.pdf, but if the uriMapper catches that link it attempts to re-map it to a resource that doesn’t exist which generates the following error:


“Content for the URI cannot be loaded. The URI may be Invalid”


Solution


In order to accomplish linking outside of the defined uriMappings, I added the link in the XAML of the HyperlinkButton NavigateUri.



<HyperlinkButton Name="lnkReport" NavigateUri="http://www.deanwillson.com/downloads/Continuous-Improvement-professional-Org-1st-Edition.pdf" Content="Click here to open your document" TargetName="_blank" Margin="116,11,184,10" Width="200" />

All this probably looks pretty obvious, but it started with me trying to open the pdf report using code-behind in the clicked event handler for the button, which kept throwing the Invalid Uri exception. I even added a special uriMapping that mapped to the same link, which also did not work.


photo credit: eirikref / CC BY 2.0

Wednesday, May 25, 2011

Creating a Windows Phone 7 app using WCF, and SQL Azure

Last night I gave a presentation with demos for fwPASS creating a Windows 7 app displaying a list of gymnasts from a SQL Azure database using WCF (Windows Communication Foundation). The WCF service used the Entity Framework and the .Net Membership provider.

The application was surprisingly easy to create despite the fact that were a lot of moving pieces with integration between all the different components.

The presentation covered the following tools:

 

All that in 70 minutes. Yes, I talk fast. This was a first time presentation. Below is the demo script I used:

Marketplace

1. Preview App Hub http://create.msdn.com

· Show app details text, iconography

Database

1. SSMS – show local ChalkChimp database

· Show script for creating additional users?

2. http://windows.azure.com SQL management interface

· No query designer

3. SQL Azure Migration tool

· Scripts out db

· Shows unsupported features

· deploys

4. Azure limitations in SSMS

· No query designer

· Admin account (other users don’t have access to the master database)

WCF

1. Create new project WCF Application

· Highlight Framework version 3.5

· Change binding to basicHTTPBinding

2. New Item à ADO.Net Entity

· Azure connection

3. Switch to finished project

4. Modify Iservice.cs, modify Service.cs implementation

5. Show .Net membership bits in web.config

6. View in browser (copy url)

WP7 client

1. Open Visual Studio (another)

2. New Project à Windows Phone 7 application

3. New item à Phone portrait page

4. Add Service reference

· Show service methods

· Advanced show generate async methods

5. Switch to finished project

· Show xaml bindings

· Show async methods and completed event handlers

· switch device to emulator

6. Run it

Optional

· Show property pages and iconography

 

Thursday, April 7, 2011

IIS is Missing XAP Mime Type for Silverlight Application

lego mimeUpon navigating to the web page hosting a newly deployed Silverlight application, I received the following error:

Error: Unhandled Error in Silverlight Application
Code: 2104   
Category: InitializeError      
Message: Could not download the Silverlight application. Check web server settings  

Thanks, but which server settings? In my case the MIME type for the .xap extension was missing in IIS7. I’m not sure why it was missing since .xaml and .xbap were already defined. I simply added the “.xap” extension and it’s corresponding MIME Type “application/x-silverlight-app” and all was well.
Xap Missing Mime Type In IIS

photo credit: e v a . p é b a r / CC BY 2.0

Tuesday, October 20, 2009

WPF Binding app.config settings in XAML

I tried several different syntaxes for exposing an app.config MySettings property (VB.Net, not C#) for databinding in the XAML. I was met with several compile and/or designer load errors like:

  1. could not create an instance of type StaticExtension
  2. ‘MemberReferenceSerializer’ ValueSerializer cannot convert from ‘System.String’
  3. A TwoWay or OneWayToSource binding cannot work on the read-only property of ‘TargetShiftCount’ of type PacingChart.MySettings

The databinding syntax that worked was:

   1: <Window x:Class="Window1"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:p="clr-namespace:PacingChart"       
   5:     Name="window1"
   6:     Title="Pacer" Height="300" Width="300">
   7:     <Grid>
   8:         <TextBox Text="{Binding Source={x:Static p:MySettings.Default}, Path=TargetShiftCount, Mode=OneWay}" Name="txtShiftTarget" Margin="126,111,32,128"   />
   9:     </Grid>
  10: </Window>

On code snippet line 3, note the clr-namespace:<project root namespace> where <project root namespace> is PacingChart in this example. It did not work in my project with clr-namespace:PacingChart.Properties as some examples suggested. Those examples also indicated that the binding source should be "{Binding Source={x:Static p:Settings.Default}, Path=TargetShiftCount}". Using p:Settings.Default, not the p:MySettings.Default which worked in my example. Also note the lack of the Mode=OneWay attribute which caused the third error message listed above.


Most of the examples I attempted to follow were from people who asked the question about the correct VB.Net syntax, but the people responding were documenting the C# syntax. The Properties.Settings (in C#) and My.Settings (in Visual Basic) are helper classes. It is important to understand the syntax differences. In the VB.Net codebehind, you would access the settings using the syntax My.Settings.TargetShiftCount where in the XAML, you would use the MySettings class.


For completeness, I created the app.config property settings by double-clicking the “My Project” entry in the Solution Explorer and switching to the “Settings” tab, which created the following snippet in the app.config file.



   1: <applicationSettings>
   2:     <PacingChart.MySettings>
   3:         <setting name="TargetShiftCount" serializeAs="String">
   4:             <value>200</value>
   5:         </setting>
   6:     </PacingChart.MySettings>
   7: </applicationSettings>

Monday, July 27, 2009

WPF controls not showing a state change

I created a dependency property in the code behind to enable/disable a button during processing.wpf code-behind

In the XAML, I bound the IsEnabled property to the dependency property. XAML button binding

The button wasn’t showing the state change. Don’t forget to add the Name property to the window or the property won’t show the state change. XAML window name