First time using WPF for a real application

October 6th, 2011

Last month I was given a task to create a small application for viewing and marking up graphical data.  This data is provided by a set of web services.

This is a Windows only application, so I decided to use C# and WPF.  The C# web service support was the deciding factor; I’ve used it in the past and it’s quite painless.  If I had decided on C++, I would have spent several hours building soap wrappers.

The pleasant surprises were how quickly the WFP UI came together and the ease that background operation integrated with the UI.

I really enjoy editing the UI in XML as opposed to using the GUI.  It kind of reminded me of the dark old days when we would hand craft Dialog Boxes in the .rc files.  Overall, the development experience was very nice.

The worker thread integration was my second nice surprise.  My Click Events simply create a delegate, and then call BeginInvoke. 

The only gotcha is that updating UI Object from the BG thread is a no-no.  Here is the pattern that I used to handle it:

// Update a TextBox Message
private delegate void UpdateTextBoxDel(string strText);
private void UpdateTextBox(string strText)
{
    txtView.Text = strText;
}
private void DoUpdateTextBox(string strText)
{
    if(txtView.Dispatcher.CheckAccess())
    {
        UpdateTextBox(strText);
    }
    else
    {
        // Invocation required
        UpdateTextBoxDel del = new UpdateTextBoxDel(UpdateTextBox);
        txtView.Dispatcher.Invoke(DispatcherPriority.Normal, del, strText);
        }
    }

Not too bad, and works like a champ!

Entry Filed under: Uncategorized

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

October 2011
M T W T F S S
« Jul    
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Most Recent Posts