Dynamic Control Layout With WPF

by jason11. June 2010 00:27

If you are even a little bit familiar with the Model-View-View Model pattern and its implementation in WPF, you have probably run into the ItemsControl control. Actually, even if you haven’t used MVVM, you may have used it. Somewhat like the Repeater control in ASP.NET, this control allows you to bind to a data source and do something in XAML for each of the items in that data source. In any case, let’s play around with the ItemsControl element in WPF a little bit.

More...

Tags: ,

Development | WPF

Using Command-line Parameters In WPF

by jason31. December 2008 01:25

If you need to read command-line parameters within your WPF application, your first inclination (if you are like me) might be to go looking for the Main method. Of course, you won't find a "Main" method in a WPF application. Instead, start looking at the App.xaml file.

By the way, for the rest of this post, I'll presume you will be using command line switches like the following:

myapplication /key1 value1 /key2 value2

To begin, you will need to add an event handler to the App.xaml file for the Startup event. After that, your App.xaml file might look something like this:

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml" Startup="AppStartup">
<Application.Resources>
</Application.Resources>
</Application>

(Notice the "Startup" attribute on line 4)

Your event handler's signature (in the App.xaml.cs) should look like this:

void AppStartup(object sender, StartupEventArgs e)
More...

Tags: , , ,

Development | WPF

Save WPF Ink Strokes To a Database

by jason20. December 2008 20:23

In my previous post about creating a bitmap from an InkCanvas in WPF, I mentioned that you could easily save the ink strokes for later. I wanted to post a code example for writing those strokes to a database and de-serialized them back into memory.

The first step in saving to a database is to get an array of bytes from the strokes in the InkCanvas. To do this, the StrokeCollection provides a convenient Save method:

byte[] signature;
using (MemoryStream ms = new MemoryStream())
{
icSignature.Strokes.Save(ms);
signature = ms.ToArray();
}
string sql = "INSERT INTO tblMyTable (mySigCol) VALUES (@Sig)";
SqlCommand comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("@Sig", signature);
comm.ExecuteNonQuery();

You can just as easily load the contents back from the database by creating a new stroke collection from the bytes save in the database:

string sql = "SELECT TOP 1 mySigCol FROM tblMyTable";
SqlCommand comm = new SqlCommand(sql, conn);
byte[] signature = (byte[])comm.ExecuteScalar();
using (MemoryStream ms = new MemoryStream(signature))
{
icSignature.Strokes = new System.Windows.Ink.StrokeCollection(ms);
ms.Close();
}

If you need to persist a signature or annotation from an InkCanvas to a database and back, the process is very simple and makes the InkCanvas even more useful.

Tags: , , ,

Development | WPF

Convert WPF InkCanvas to Bitmap

by jason9. December 2008 14:38

We live in a digital age and if you are like me, paper is only used when it is absolutely unavoidable. If you have a tablet PC, signing your name to attach it to a document may be one less thing you will need a physical sheet of paper for.

The WPF ink control can be put into your XAML to collect stylus strokes as a collection of geometry points. Of course, as the stylus moves, the movements are also shown on screen.

inktest

More...

Tags: , , ,

Development | WPF

About

Jason Williams is a .NET developer in Lincoln, Nebraska.

The name "Centrolutions" came out of a long search for a domain name. The goal was to create a name that conveyed an ideology of writing software centered (Centr--) on a solution (--olutions) for a particular problem. In other words, it was the only name in a long list that wasn't already registered on the internet.

If you're looking for the products I have for sale, you should go here.