Archive

Archive for August, 2009

Updated Community Schedule

August 28, 2009 1 comment

Howdy folks,

I recently posted my fall community schedule.  Since then there have been a couple of confirmations and additions.

RDU Code Camp

This will be my first year going to Raleigh for RDU Code Camp.  RDU Code Camp is September 19th at ECPI in Raleigh, NC. I’ve heard nothing but great things, so I am really looking forward to it.

I will be presenting on “Templating and Data Binding in Expression Blend.”  I really enjoy speaking on this topic.  I find Templating and Data Binding to be the crown jewels of WPF, and as always Blend is there to smooth the way.

Richmond Code Camp

Richmond Code Camp, aka RCC2009.2, will be held October 3rd at J. Sargeant Reynolds Community College.  This is a great venue and one of my favorite events of the year.

I will be giving my presentation “Using Visual Studio and Blend to Develop WPF Applications.”  If you are new to WPF/Silverlight and or Blend, this is the presentation for you!  I will cover the basics of setting up an application, using Blend to develop the user interface, and how to use the two products simultaneously.

I will be retiring this presentation after RCC, so if you haven’t seen it yet this is your last chance!  If you have seen it, I promise it is a little different every time I give it, and of course it has been updated for Blend 3.

CapArea Silverlight Special Interest Group

I am slated to speak at the CapArea Silverlight Special Interest Group (SIG) at their October 28th meeting. We have not decided on a topic yet, but rest assured it will be Blend and Silverlight oriented!

Get out there!

As always, I really want to encourage you to get out into the community.  I promise that somewhere not so far away from you is a User Group, Code Camp, or other great event that you can take attend. 

You can always find more events all over the country at Community Megaphone, so do yourself a favor and get yourself to an event! I hope to see you around the community.

How to Center a Silverlight App in HTML

August 22, 2009 5 comments

I’ve written a lot of CSS over the years, so when I wanted to center my Silverlight App in my web page I figured it would be a piece of cake.  It is easy, but it gave me some frustration because it required one element that I normally would not specify.  Read on for the details.

Setting up the CSS

Here is the default CSS created by Visual Studio:

<style type="text/css">
html, body {
    height: 100%;
    overflow: auto;
}
body {
    padding: 0;
    margin: 0;
}
#silverlightcontrolhost {
    height: 100%;
}

To accomplish this little trick I need to define a wrapper DIV in my CSS.  This Div will then wrap the entire contents of the site, so now I only have to center that DIV.  We need to define the width of the content area: it makes sense that you want to set the size of something you want to center so it can be calculated.  To do this, I set the width property of the wrapper DIV to the pixel width of my Silverlight control.

Since not all browsers interpret things the same way, we need to add a couple of items in order to center our content.  First, add text-align: center; to the body tag.  This should handle the centering for IE browsers, at least older ones.  For Firefox and Safari, we need to add margin: 0 auto; to our wrapper DIV.

This is my typical set up in traditional HTML scenarios, but when I tried using this CSS the Silverlight object would not show.  I had some video in this particular example, and it was a good thing I did or I would have gone crazy trying to figure this out: I could hear the video playing, so I knew the Silverlight object was running, I just couldn’t see it.

It turns out that you need to specify the height property as well in the wrapper DIV.  It doesn’t have to be exact, just larger than your Silverlight control.  If you make it larger than 0 but smaller than your control, it will actually truncate the control, which could be an interesting effect in certain scenarios.  I don’t know the reason for this, perhaps it’s because the Silverlight control runs in an object tag, but I’m not sure.  Please post in the comments below if you know why this was required.

Here is the final CSS I used:

<style type="text/css">
html, body {
    height: 100%;
    overflow: auto;
}
body {
    padding: 0;
    margin: 0;
    text-align: center;
}
#wrapper
{
    margin: 0 auto;
    width: 800px;
    height: 800px;
}
#silverlightcontrolhost {
    height: 100%;
}
Categories: Silverlight

Rants and Raves #6

August 19, 2009 1 comment

Have you ever had a problem you couldn’t complain about?  Me too.  I have been so busy I haven’t had much time to post.  Between working like mad on a new project at work, learning several new technologies, traveling to Nashville for my first DevLink 2009, and a super-secret side project I’ve just been too swamped to post.

And I can’t complain: being this busy is a good thing, especially in this economy.

Rants

nHibernate – first crack

I was finally given the impetus to learn nHibernate, which I had heard about but never tried.  I’ve always assumed that cool kid tools like these are not for me since I am currently married to the AS/400 as a database.  I found at this past weekend, though, that I can in fact connect to the AS/400 using nHibernate, so I could finally have a decent OR/M tool for our database.  Getting rid of straight ADO.NET would be a dream come true!

Back at work this week, one of the first things I wanted to dive into was of course nHibernate, so I downloaded the code and began following the example touted on the nForge site.  The article is long and seemingly thorough, but it suffers from some serious organizational flaws. As I worked through it, my experience was decidedly different than the article suggested, although I was able to get it working with the help of the comments thread and a lot of Binging.

My biggest issue was the apparently recent requirement for adding a “proxyfactory.factory_class” xml element in the hibernate.cfg.xml file.  After doing so, you’ll find that you require a reference to NHibernate.ByteCode.LinFu.dll, which was not included in the SharedLibs list in the article.  After that, you’ll discover that you also require a reference to LinFu.DynamicProxy.dll, also not included in the SharedLibs list.  You can find both of these in the nHibernate subdirectory Required_For_LazyLoading/LinFu. (This can be altered to use Castle or Spring, both of which are included in the download).

I know I’m picking on one article, but if it is your go to “Hello World” demo, I expect it to be more refined.  Not to mention, it shows a lot but explains little.  I think it is especially difficult for someone with very little Unit Testing experience. There is going to be a lot of work ahead to grok the application, but so far it seems worthwhile.  Now I just need to get it hooked into my AS/400 and see if I can do some real work.

Raves

DevLink 2009

My list of “must-attend” Community Events is growing at a rapid pace, a little too rapid based on how busy I am, but what’s a geek to do?

This event was a little different than usual: my community buddy Kevin Griffin and I took our wives along to Nashville.  We had a great time, usually the two of us at conference and the two of them out sight-seeing.  I did get to go to the Gibson Showcase, where they make all the Gibson Mandolins, and the Country Music Hall of Fame.  My trip ended on a bit of a sour note: our family van of 10 years passed away and we had to get a rental for the ride home.

But the event was great!  As always, Open Spaces rocked, and I also saw some great presentations, which leads me to my next rave…

Shawn Wildermuth

Today is a first for Rants and Raves: I am raving about an individual person.

If you are remotely interested in Silverlight you’ve probably heard of Shawn Wildermuth.  C# MVP, INETA Speaker, Silverlight Insider, author, speaker, teacher, and much more: Shawn is a Tour de Force when it comes to Silverlight.

Fortunately for me, he was not only present at DevLink, but he sat in on my Open Space session about Silverlight.  I really appreciated the chance to discuss Silverlight up close and personal, and he gave me some great ideas for moving forward with my project. 

I then got to see his presentation called “Silverlight + MVVM = Easy”.  Meeting Shawn and learning at the foot of the master was the highlight of the trip for me (followed closely by getting to play a $25,000 Gibson F-5 Distressed Master Model” mandolin!)

I really admire that he is so involved in the community and that he freely shares his knowledge and skills. Thanks Shawn!

Categories: Rants and Raves

Buying Expression Studio 3

August 6, 2009 Comments off

I think Expression Studio 3 is now available: the website has switched from "pre-order" buttons to "buy" and "upgrade".

Kevin pointed out that MSDN is the way to go, which I agree with if it is an option, but I have Visual Studio Professional with MSDN Professional, which is $1,199: Expression doesn’t become downloadable until you have Visual Studio Professional with MSDN Premium which is $2,499. It’s just not worth it to me to spend an additional $1,300.

Studio Pricing

Expression Studio 3 costs $599 for the full version or $349 for an upgrade.  If you don’t have MSDN or anything like it, they have a good deal going though with "Expression Professional Subscription":

  • Expression Blend + SketchFlow
  • Expression Web
  • Expression Design
  • Expression Encoder + IIS Smooth Streaming
  • Visual Studio® Standard
  • Office Standard
  • Office Visio® Professional
  • Windows® XP
  • Windows Vista® Business Edition

All for only $999. I wonder if they’ll include Windows 7 now that it’s RTM?  And what happened to Expression Media?  It is no longer listed on the site.  No loss for me since I never used it, but I am curious.

Microsoft Action Pack Subscription

Through the Partner program, I was getting Expression Studio 2 via our Microsoft Action Pack (MAPS) subscription (specifically as part of the web solutions toolkit).  With MAPS I have to wait until they ship it to get the software, so I emailed the MAPS team the other day and asked if they knew when it would be available but they said they were not sure when the product would be released.

Today I checked the MAPS information online and they are now only advertising Expression Web, Design, and Encoder.  So it looks like I’ll probably end up buying the upgrade.  I’m a little surprised I can’t just update Blend, but apparently they aren’t selling the pieces individually except for Expression Web.

I’ve said for sometime that Microsoft should be giving Blend away if they really want to promote the adoption of WPF and Silverlight.  I wonder how many developers are sticking with Visual Studio because they don’t have access to Blend?

UPDATE:

The Luddite Developer is talking about this as well.  Seems he is in the same boat as me as far as MSDN goes.

I tried to call the MAPS team yesterday to get clarification on whether or not Expression Studio was going to continue to be part of MAPS, and also an update on when Expression 3 might ship.  The phone number given to me by Microsoft -I had called MSDN earlier and been given the number – had an interesting message:

“The number you have dialed has a new national directory service. For a charge of $3.79 please dial this new number …”

You want what?  You want me to pay to dial a new number?  Wow – if this was a rant I could fill it up… either MSDN gave me a bad number or MAPS is now charging for the privilege of calling them.

Categories: Expression

Is The Blend 3 Trial Worth The Download?

August 4, 2009 2 comments

If you’ve spoken with me at any time over the last year at a technical conference or User Group you’ll know that I can’t go more than a few minutes without mentioning Microsoft Expression Blend. 

I was first introduced to WPF in 2006 and I was stunned by the results.  I couldn’t wait to try it myself, but at the time all I saw was XAML, and frankly I had no desire to develop business apps in markup.  Fortunately, in 2007 I saw Blend 1.0 and the flood gates opened: I had to have it, and I soon did.  Since then I have become a Blend evangelist.  It is my mission to preach the rich chocolaty goodness of Blend to all the people of the land.

OK, that may seem overkill, but in all honesty I cannot see developing WPF or Silverlight apps without Blend.  If I had to code strictly in XAML I would still be a Windows Forms developer.  Don’t get me wrong, plenty of people have done meaningful work without Blend, but I would never be one of them.

Is the Blend 3 trial worth the download?

Naturally, Blend is my current topic of choice for presentations, and I get plenty of questions about Blend from fellow developers.  This morning I received a question that I thought deserved sharing:

Are the blend 3 features worth the trouble of installing the trial version? Or wait for the official release?

This is a great question!  The requestor is currently using Blend 2 and wants to know if the updates from Blend 2 to Blend 3 are so awesome that they must have them now, or can they wait until GA.

My answer is, in typically non-committal fashion, “it depends.”

If you are dabbling with Blend and WPF or Silverlight 2, then you do not need to rush out and try Blend 3.  Don’t get me wrong, you could still benefit from it, but I wouldn’t consider it urgent.  You can wait for the RTM. 

[NOTE: If you are working on Silverlight 2, be sure to read all the warning labels before moving to Silverlight 3: you can’t go backwards once you install the Silverlight Tools for VS 2008.  In your case, you need to wait for VS2010, which is supposed to allow both environments.]

If you are a dedicated WPF or Silverlight developer/designer, by which I mean the bulk of your projects fall into one of these two categories, then by all means you should be using Blend 3 already.  You can install Blend 3 alongside Blend 2 with no ill effects. 

My Favorite Features

I spend a great deal of my time in Blend, and now even more so with Blend 3.  Here are the list of features I use the most in Blend 3:

  • Vastly improved Data tab (including SampleDataSource and easier databinding)
  • VSM for WPF (mostly built in, still need to add a reference to WpfToolkit.dll)
  • Artboard integration is finally usable – you can actually click on
    the element you want to use
  • The BreadCrumb makes working with Templates a lot easier
  • Code Editor – now you can edit C# inside Blend, including Intellisense.  I don’t advocate it for serious coding, but simple changes and events are quite feasible

There are probably more, but these are the ones that seem to most enhance my daily experience.  There are, of course, some bigger fish to fry that I have yet to really take advantage of like Behaviors and SketchFlow.

Conclusion

If you are in a position to do so, I would try Blend 3.  Trial downloads of Expression Studio 3 are available for 60 days, and pre-order purchasing is currently available.

I’ll be writing more about these features in future posts.  I’d like to add some Video Tutorial too, so feel free to leave requests in the comments below.

Categories: Blend

Swatting A 6 Month Old Bug

August 4, 2009 Comments off

I began working on our first major WPF project last December.  Previously I had done a lot of playing and learning, and written a few internal utilities, but this was our first release grade project.  Things were going well and the partners were very happy with the software development… that is until “the bug”.

The Back Story

The software is an image management tool that interfaces with our legacy AS/400 application.  In short, it allows images on a network server to be linked with data records in our legacy application.  It is a replacement for an existing application written in FoxPro, so you can imagine the Oohs and Ahhs at the new UI.  The project also fills in some serious deficiencies in functionality.

As one can probably surmise, one important piece of functionality when managing groups of images is the ability to add, remove, or rename images.  With File IO such a rudimentary function, I had let it lapse until the end of the project.  Since WPF was the focus of my development, I had lost focus on the project itself.  I spent a lot of time making the application sing with animations, transitions, Visual States, drag and drop with a Visual Brush, you name it I wanted to try it.

Near the end of February I began working with the final bits, which included deleting an Image and saving an updated list of images back to the server.  As soon as I tried to perform any such action on any image, however, I would receive an IOException: "The process cannot access the file because it is being used by another process."

I worked intermittently on the issue while I continued improving the UI.  I figured it had to be something simple, so it took a little while until I began devoting serious effort to solving the problem.

Working on the Problem

Since the project was winding down, I began working on the problem in earnest about the middle of March.  I was able to determine that it was my application causing the lock, so I did a little research and found plenty of indication that opening images has a tendency to lock the file until the application ends.  With the idea that my application was holding the resource I tried to find a way to close it out until the operation was complete.

Without all the gory details, here is a list of things I tried in varying degrees, all of which failed to solve my problem:

  • Setting the ListBox.Source to null.
  • Adding a wait time before attempting the move.
  • Issuing GC.Collect().
  • Moving the operation to a different thread.

All of these were to no avail.  Eventually I posted the problem to StackOverflow and received two responses in short order.  I tried both of the solutions, but neither one seemed to solve my problem.  I asked a few friends on Twitter and email, but no one was able to help beyond what I had already tried.  By the end of April I was ready to call it quits.

Unfortunately for the project, but fortunately for my sanity, other projects became more important.  This gave me an official hiatus from the project, but I would still return to it occasionally in my spare time, always with the same results and frustrations.

Early in July my hiatus was over: the total project (the image project is a subproject of a larger effort) deadline is set at September 1st.  Panic set in: I have three applications to deliver in that time, and one of them is the Image manager.  I put it off a little while while I wrote one of the other applications, but on July 18th I returned full time to my nemesis.  The good news was there was little left to do: the bad news was that I had already spent countless hours on one stupid bug that was make or break for the entire application.

The Solution

I had little choice but to start from the beginning.  I went back to the StackOverflow discussion because it seemed to hold the most promise.  I wrote a test application that just performed the action I wanted, deleting an Image that was in the application.  By using a combination of the two methods in that thread I was able to get the feature working.

The solution that worked was to create a Value Converter that accepted the path of an image and returned a BitmapImage. 

[ValueConversion(typeof(string), typeof(BitmapImage))]
public class PathToBitmapImage : IValueConverter
{
    public static BitmapImage ConvertToImage(string path)
    {
        if (!File.Exists(path))
            return null;

        BitmapImage bitmapImage = null;
        try
        {
            bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = new FileStream(path, FileMode.Open, FileAccess.Read);
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.EndInit();
            bitmapImage.StreamSource.Dispose();
        }
        catch (IOException ioex)
        {
        }
        return bitmapImage;
    }

    #region IValueConverter Members

    public virtual object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null || !(value is string))
            return null;

        var path = value as string;

        return ConvertToImage(path);
    }

    public virtual object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

I then bound the Image source to the path of the image using the converter. While this image (or rather a local copy of the image) was on the screen, I was able to delete the file from the server.  I had tried a version of this previously, but I assumed it wasn’t working because I was still getting the error. Now I had proof that this code works.

Applying the Solution

I was able to apply the solution to the original application after some refactoring.  It’s amazing how much my coding style has changed from the last 6 months experience with WPF.  I look at the application now and cringe, especially at the code behind.  Anyway, I was able to shoe horn my solution in and the images showed correctly.  Can you imagine the anguish I felt, however, when the first time I tried to delete an image I received the same error?

I was quite dismayed, until I realized that it was not the actual image code since that had been proven: there had to be something else causing the problem, but what?  I had already gone through all the code and every reference to an image with a fine toothed comb, several times, what more could there be?  I began the process over again, but I was not a happy camper.

And then it dawned on me.  I finally knew what the problem was: I had been bitten by Data Binding.

How Can I Blame Data Binding?

To be fair, the issue is not with Data Binding per se, but my own misunderstanding of the object I was binding.  The images were bound not once, or twice, but three times:

  • ImageListBox – each item is bound to a different image, effectively a FilmStrip control
  • CurrentImage – a larger Image control showing the selected image from ImageListBox, bound to ImageListBox.SelectedItem
  • DeleteImageDialogBox – a separate Window that displays the image and prompts the user to confirm deletion, the Image is bound to the path passed in from the parent Window

For both ImageListBox and DeleteImageDialogBox I had used the new Value Converter.  CurrentImage, however was a different story.

In binding CurrentImage to the SelectedItem property of the ListBox, I was expecting the property to represent the rendered image that was the result of the Value Converter.  This is completely wrong!  The SelectedItem property is still the file path string!  CurrentImage was still executing the default behavior and retrieving the file from the path resulting in a file lock.

The Resolution

Once I understood what CurrentImage was binding to, I knew what to do: apply the same Value Converter I was using for the list box items.  Sure enough, once I applied that Value Converter everything else fell in place.

In hindsight I feel this was an “Oh Duh” sort of problem.  So many times the solution to our most frustrating problems is right in front of us, and almost always the solution is fairly simple.  As I said to a friend recently – it’s amazing sometimes that we ever get anything right!

Now I have a new issue: via the Value Converter I’m going to the file system three times to show the same image.  I’ll have to address that at some point, and I have a few ideas.  I could store the BitmapImage copy, or a byte[], or a MemoryStream locally and reuse it.  For now, however, I’m going to leave well enough alone and get on to my next application.  Hopefully it won’t take six months to finish.

Categories: WPF

Fall Community Calendar

August 3, 2009 1 comment

I was just going over my calendar and there are some great events coming up.  Here are the events I am attending or speaking at (that I know of at this time):

  • Aug 12-16th DevLink – I’ll be going to DevLink for the first time this year. The slate of presentations looks great and is full of a bunch of our finest community members.  Should be a great time!
  • Aug 20th CHODOTNET – I will be presenting on using Visual Studio and Blend together to develop WPF applications.  This is an entry level presentation intended to get developers over that initial hump of learning Blend and setting up WPF applications.  Meeting starts at 6:00.
  • Sep 10th MSDN Roadshow in Roanoke – I’ll be there with bells on to see presentations from Microsoft about Silverlight 3, Expression 3, Prism, MVVM, and RIA Services. If you can’t make this one, there are many others close by on the list.
  • Sep 10th RVNUG – What a deal!  Two for one!  After the Roadshow, G. Andrew Duthie, Microsoft Developer Evangelist extraordinaire will be presenting on lessons learned in developing real Silverlight applications.
  • Sep 17th CHODOTNET – Monthly meeting of the Charlottesville .NET User Group.  I haven’t heard yet what the presentation is, but I plan to be there regardless.
  • Sep 19th Raleigh Code Camp – I’ve submitted several presentations, so I hope to be speaking.
  • Oct 3rd Richmond Code Camp 2009.2 – I’m hoping to have something special for this event: I’ll keep you posted.

The only other item I have on my calendar is Philly Code Camp Oct 17 (no details out yet), but I don’t think I’ll be able to attend.  Just too many great events to choose from!

Of course you can always find more events all over the country at Community Megaphone, so do yourself a favor and get yourself to an event! I hope to see you around the community this fall.

Categories: .NET
Follow

Get every new post delivered to your Inbox.