Sunday 30 March 2008

Windows Live Style WPF Gradient Fade

I have been playing with different gradients for an application that I am writing a wpf front end for.

After a lot of experimenting, I found the two gradients below look pretty awesome.

This first one creates a metalic or reflective style effect similar to the title bar on Windows Live, the border itself has rounded corners at the top giving it a tab header like quality.

<LinearGradientBrush MappingMode="RelativeToBoundingBox"
StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#7eb2d2" />
<GradientStop Offset="0.1" Color="#7eb2d2" />
<GradientStop Offset="0.11" Color="#7aafd1" />
<GradientStop Offset=".35" Color="#5599c4" />
<GradientStop Offset=".49" Color="#3586b9" />
<GradientStop Offset=".5" Color="#005c96" />
<GradientStop Offset=".65" Color="#005c96" />
<GradientStop Offset=".75" Color="#166a9f" />
<GradientStop Offset=".99" Color="#6aa4c5" />
<GradientStop Offset="1" Color="#7eb2d2" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>


This next one creates a nice relatively light blue shadow at the top of the area, allowing you to remove the total whiteness of an area without distracting from the fields etc on it...

<LinearGradientBrush MappingMode="RelativeToBoundingBox"
StartPoint="0,0"
EndPoint="0,1"/>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="White" />
<GradientStop Offset="0.001" Color="White" />
<GradientStop Offset="0.0011" Color="#72a3d6" />
<GradientStop Offset="0.0125" Color="#aac7e5" />
<GradientStop Offset="0.025" Color="#d3e5f7" />
<GradientStop Offset="0.04" Color="#eaf3fd" />
<GradientStop Offset="1" Color="White" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>

Installing SQL Server Express With Your Application

There are a couple of ways to distribute SQL Server Express with your application.

The first and easiest way is to select it as a prerequisite in the Installer project's properties dialogue. Although this is the easiest way to deploy SQL Server Express with your application, it does require an internet connection on the client because it will download and install SQL Server Express from MS, or your own url if you want to state one....

http://www.programmers-corner.com/forums/post-15324.html

The other way is to embed the SQL Server Express installer into your application. Microsoft have moved the article about how to do this (try following the link to it from this article and you will get the generic "Article could not be found" page from MSDN)....

http://msdn2.microsoft.com/en-us/library/ms165639.aspx

I finally found the article at the following URL.... I haven't tried to follow this yet, but plan to use this method for distributing SQL Server Express with a new wpf application I am writing to calculate corporation tax....

http://msdn2.microsoft.com/en-us/library/bb264562.aspx

.NET Application Auto Update

I am currently looking to implement autoupdate functionality into a wpf .net application. There are 2 things I am looking into...

Firsthly, the following is free from Microsoft and you can use it easily to enable you to deploy autoupdates for your application...

http://msdn2.microsoft.com/en-us/library/ms978574.aspx

And, in case like me you don't have enough time to really look into how to use that patterns and practices and want to get a proof of concept prototype of your application auto updater up and running that you can polish closer to release, check out this blog post that provides really easy steps on how to get the autoupdater up and running...

http://codebetter.com/blogs/brendan.tompkins/archive/2004/06/10/16118.aspx

But, I found this required other patterns and practices to be installed before you can use this one.

Secondly, and seems the simplest one, I also found this from Microsoft that looks similar and a lot easier to set up...

http://windowsclient.net/articles//appupdater.aspx

One thing I did consider before looking into an auto updater was creating a Click Once deployment application, but decided against it because I want people without any internet connection to be able to install and use the application and Click Once would mean the user would have to have a connection at least for the first install. Also, it seems that the client would update the files and the database they connect to might not be updated etc... seems like it would work best with all clients connecting to a central database.

Sunday 16 March 2008

Redirect Subdomains with ASP.NET and C#

How to do sub domain redirection with asp.net c#

string strServerName = Request.ServerVariables["SERVER_NAME"].ToString().ToUpper();

if (strServerName.IndexOf("subdomain1.domain.com") > -1)
{
Response.Redirect("/subdomain1");
}
else if ....

Saturday 15 March 2008

Load SQL Server file at runtime without attaching the mdf file

There are situations where you want a quick and easy deployment for an application that runs from a SQL Server file and you don't want the user to have to have SQL Server client tools installed to attach to the mdf file etc. For instance if your app is a standalone desktop application where each user will use a db installed in the application folder.

In these scenarios, use the technique described in this article....

http://technet.microsoft.com/en-us/library/ms165716.aspx

It allows you to deploy an mdf file in the applications install folder and will load, or lift, that SQL Server database when the application runs without any need to attach the database .mdf file to an instance of SQL Server engine.

The user will need to have either SQL Server or the free SQL Server Express installed on their machine. Because SQL Server Express is free though and available as download from Microsoft this is usually not a problem.

One thing to consider with Vista though are the permission implications.....

http://blog.benhall.me.uk/2008/03/sql-server-and-vista-create-database.html

Friday 7 March 2008

WPF Binding Fails With Objects With Internal Properties

I created an executable Windows Presentation Foundation (WPF) assembly with a WPF window and a simple object with a couple of string properties to bind the form to.

In the window, I set the text property of a textbox to "{Binding Path=SomeValue}" where SomeValue was a property in my class called Something.

In the load event handler of the form I created a new instance of Something called something and set "DataContext = something;", which would set the data context of the window to the instance of Something.

This should have been all I needed to do to run the app and the window should open displaying the SomeValue property of something in the text box.

The app ran without any errors, no security or permission warnings or compile time errors or anything, but the text box was empty.

If I put a break on where I was setting the data context, I could see that SomeValue of something did have a value.

I eventually found out that, even though both the class and the WPF window are in the same assembly, the binding failed because the SomeValue property on Something was marked with an "internal" access modifier.

Changing the access modifier to "public" on that property got the application working, and the text box now displays the SomeValue property of something.

It did surprise me that there was no compilation or runtime error for this one, but there wasn't.

Wednesday 5 March 2008

Stock Icons

I have been looking at a number of stock icon websites. I needed to buy a good set of professional looking icons that covered all the icons I might want to display.

The best site I found by far was Glyphlab....

http://www.glyphlab.com/stock_icons/preview.html

They have a good range of icons in one set, so you don't have to buy a number of sets to get the icons you need. Also, they looked a lot more professional than most of the other companies I looked into and the icons come in all the sizes I might need.

You also get the photoshop files, so ifyou need to mix icons together (for instance to put a magnifying glass from one icon over a different icon for consistency, you have the files to do that)

The entire set cost me about £130 (UK Pounds Sterling), so they aren't the cheapest icon set, but it is cheaper than buying a number of different sets to get the whole range you need.