Archive for the 'Uncategorized' Category


Data Annotation Validation of More Complicated Rules 0

Using Data Annotation validation is great. It’s simple. It’s declarative. It’s fine and dandy if all you need to validate is simple, single property rules.

[Required]
public string FirstName {get;set;}

The problem is, we are never that fortunate to only have simple rules like that. Even rules only slightly more complex made me scratch my head at first. For example, take the following rule:

If the address is inside the United States, then State is required.

Simple enough, but how to do it with Data Annotation. Initially I decided not to validate this rule via annotation and did something like the following in my controller action.

var additionalErrors = MyViewData.ValidateAddress(dataFromMyForm);
foreach (var errorInfo in additionalErrors)
{
    ModelState.AddModelError(errorInfo.PropertyName, errorInfo.ErrorMessage);
}

That works and all, but it feels really sloppy. Not only does it feel sloppy, but now my model validation lives in two places; the model binder and the controller action. Yuck! And what’s even worse, is I have to consider the model validation in my tests for that controller action.

It would be better to do the validation via a custom validation attribute, but how to do that on the class? First let’s create a custom validation attribute.

public class UsaAddressRequiresStateAttribute : ValidationAttribute
{
    public override string FormatErrorMessage(string name)
    {
        return "State is required.";
    }

    public override bool IsValid(object value)
    {
        var address = value as IAddress;
        if (address == null) return true;
        if (address.Country == "United States")
           return !string.IsNullOrEmpty(address.State);
        return true;
    }
}

Pretty simple right? And don’t worry. We’re not actually using "United States" in our production application. Now, decorate the class with that attribute.

[UsaAddressRequiresState]
public class MyViewData : IAddress {
}

In my particular case, my view data class implements IAddress, which lets me name my view data address fields whatever they want and still expose them to the validator. The limitation with this method is you can only validate one address on each form. There is surely a better way to do this, but I didn’t need to discover it right now.

That’s it. The model binder will now check that validation when binds the model and we’ll see the errors in the model state. if you want the to appear in JavaScript if you do client side validations, I suggest you check you the Phil Haack post about custom validation.

Pay no attention to the magic behind the curtain with Cassini 0

Cassini can be very misleading. For example, spin up web site that uses routing in Cassini and it works without a problem. Do you have to add the routing module or handler? Nope. It just works. It’s so nice and helpful, but that really gives you a false sense of security.

IIS is not so nice. We recently ran into this where things worked great in Cassini, but as soon as they were deployed to IIS, nothing routed. It turns out we were missing a bit in the web.config that enabled routing.

I just stole that section from a newly created MVC 2.0 application’s web.config.

Gigantic Steps – Taking it all in at once 6

431829356_95719fab5e We’re starting a new project at work, one that will take our web development in a new exciting direction; MVC. We’ve struggled with the lack of control ASP.Net Web Forms gives us over the markup and and felt the pains of countless update panels trying to be Web 2-point-ohy. Today marks our first step into the ASP.Net MVC, but why stop there. Why not a whole new stack.

Here is what we are considering:

Move to Visual Studio 2010 Beta 2. Since it has a go-live license, we’re in line for the RTM, whenever it drops, and are (mostly) assured the upgrade path will be mostly painless. All (three) of our developers are running triple monitors so 2010’s multi monitor support is greatly anticipated. That’s not the only benefit though, the features of VS 2010 and .Net 4.0 are well enumerated. I won’t bore you with them, but there are a few .Net 4.0 features that look enticing, although we might still target 3.5 for our production releases until .Net 4.0 goes RTM. I’m not sure we are that bleeding edge.

Shipping along with VS 2010 is ASP.Net MVC 2.0 Preview 2. We are looking at using a lot of ASP.Net MVC Contrib, and other projects in conjunction with MVC 1.0, but with MVC 2.0, we get a lot of that same benefit. The type safe views in MVC 2.0 work slicker than the fluent views in MVC Contrib. The designers will be able to work with them a lot easier and not get lost in all the C# needed to write HTML. I’m not totally sold on the ASP view engine, due to its lack of XML formatting, but making it type safe is a huge selling point for me over Spark, the other XML compliant view engine I would consider.

We are also looking at upgrading TFS 2008 to TFS 2010 Beta 2. TFS 2008 is pretty painful when dealing with work items, branches, etc. We’ve seen some promise with TFS 2010. It does a better job at visualizing the merge relationships and hopefully a better job at handling work items. We’re struggling where to house our work items now. Hopefully TFS 2010 will be a good home. This above all other upgrades is the scariest. Loosing the source repository, even though we have backups of it, is scary.

Switching to from TFS to Team City for out CI and build server is another step in order to give us more control over our build process, and hopefully, dropping MSBuild as our build script platform. Scripting in XML was a horrible concept. Team City will better report our Nunit, Xunit, MBUnit, etc test, but also let us easily start using something like Rake for our build scripts. We’re not to the point of using Rake yet, but that is the goal. Getting Team City up and running was really simple. There were some firewall issues with the build agents, but for the most part it is dirt simple. Team City also has plugins to pre-test commits and task tray build monitoring. We do loose a little integration with TFS, but not much.

Taking our first step with ASP.Net MVC 2.0 Preview 2 gives us the ability to segregate our giant application into smaller projects using areas, hopefully making our source more organized, and more modular. We are writing a new checkout and order process for our main selling tool, the huge WWW website. This site is huge, and we would like to keep the amount of change needed to minimum, not only now, but going forward. MVC 2.0 has a bunch of new features over the 1.0 release and a ton of control over Web Forms.

Starting with a new project, we’re making strives to more loosely couple our dependencies. The heart of that is using StructureMap as our DI Container. From what we’ve read, StructureMap is simpler and easier to pick up than Windsor or Unity. We’ll give it a go and as we’re not doing anything all that complicated, it should be suit us just fine.

Following the patters of DI/IoC, we have a great opportunity to start narrowing our system under test. Previously we were using Selenium to accomplish almost all of our testing, and it works perfectly. That is, it works perfectly until you accumulate 40 or so tests that take 20 minutes to run through the browser. This is too long for me to run several times a day. We are testing specific classes in isolation and mocking all the dependencies using Rhino Mocks. Our test times are dropping dramatically, but we do sacrifice testing all the javascript and AJAXy goodness. That’s OK. We’re not throwing away all of the Selenium, just limiting our dependency on it to a more appropriate level.

I hope to cover more of these topics in detail, as I find them interesting and gain more experience with them. ASP.Net MVC 2.0 and the new tag team of VS and TFS 2010 Beta 2 will surely have a lot of interesting experiences to pass on. For now, our only pain is downloading them.

St Louis Day of .Net Suggestions 0

I have a lot of praise for the St Louis Day of .Net 2009. It was by all measures a smash. For $100 you get plenty of content and 500 .Netters to network and mingle. While I have lots of good things to say about the event, I have some suggestions for next year too. Most of this was mentioned in the attendee survey they sent out after the event, but it would help to get the message out again.

Pre registration

I think it would help a lot of each session would be prefixed with both a content category and a number to indicated its level of intensity. It would help to easily identify the courses you think are appropriate and worth your time. UX101 and ARC402 both are easily identifiable as a low level user experience session and a high level architecture session. The rooms loosely highlighted the topic, but I think something more explicit would be better.

Just a minor thing with the website, but the session catalog should link to the descriptions. It felt like a bad experience to have to look up the description on a different page.

Registration

Registration moved much faster than I expected. The line was long, but it took no time to make it through. The only thing I would change would be to make it more clear the lines were divided by the first letter of your last name. It wasn’t clear and my friend and I stood in line together, but only one of us was in the right line. Not a big deal, they took care of him, but it was a minor confusion that could be avoided in the future.

The bags were nice, but I felt unnecessary. I don’t think anyone would miss the shirts, and you could even sell them for $20 or so and I think you would get plenty of takers. I didn’t like having the bag because I didn’t like carrying it around the rest of the day. Handing out a small notebook, stuffed with the vendor flyers, would have made more happier. Also, there was no pen in the notebook. Not a problem, because the vendors were handing out that stuff.

Breakfast

Breakfast was great. Plenty of coffee, plenty of pastries, just nothing else. Fruit or yogurt would be good and have less sugar for those concerned with that sort of thing.

Quick Start Sessions

I am not a fan of the quick start sessions. The one I picked the first day made getting up that early feel very disappointing. It would be great if we could get a keynote by someone even moderately famous. Or if that isn’t possible, maybe talk with 3 or 4 developers working on big projects in St Louis using .Net. (e.g. Woot.com). I like the idea of seeing all 500 people in the same room and more importantly, all leaving the room at the same time to go hit the sessions.

I wouldn’t mind the quick start if they were on a completely foreign topic, like Git, FitNesse, Windows Mobile development. Quick starts on Ajax and Silverlight don’t interest me.

Lunch

Lunch was way too long. It ended up being 95 minutes. It didn’t take near that long to eat, and the rest was spent just sitting around. It would be nice if we could make use of that time by either having areas setup for more open discussions, or even having a topic slated for each room where people could group and talk about “testing” for example. It could be moderated by a session presenter. People could eat and talk, but hopefully not at the same time. Another idea for lunch would be to do the quick start sessions. Again I would do them on interesting topics.

As far as the food goes, it was as good as boxed lunches could be. Being at the casino, it would have been nice to eat at the buffet they have there.

In between the Sessions

While not in the sessions, it would be nice to have areas where people can go and mingle with other people about a certain topic. For example you could have the testing corner were people could chat with the testing session presenters or other people who want to talk about testing. Even going as far as having Xboxes setup with Rock Band, or Halo would kill those rare times when no sessions are appealing. The games might provide enough of an ice breaker to get our highly social kind to talk amongst ourselves.

After Day One

After day one I would rather see an event where we could mingle more. I think the night club probably scared away a good amount of the attendees. It would be nice if the first night was just snacks and drinks, followed by a more killer event on the next night. It also didn’t make me want to stay and hang out very late knowing I would be getting up early the next day.

I wasn’t a fan of the night club, but I’ve already voiced my complaints about that.

Overall

Don’t let the suggestion let you think I didn’t have a great time. I would do it again in a heartbeat. It is only going to get better if we let them know what we would like to see done better.

St. Louis Day of .Net Day 2 Overview 4

Day two of St Louis Day of .Net held up the high expectations of day 1. Without the need to herd through the registration lines, we were able to jump right into the breakfast; however I missed part of the JumpStart sessions in exchange for a few more minutes of sleep.

Session 0: JumpStart: Silverlight
by Clint Edmonson

As I mentioned I intended to come a little late, and between that and running into a former colleague, I only caught the last thirty minutes of Clint’s presentation. Clint did a great jump with his presentation, style, pace and content. Silverlight 3 looks like it is a solid and extensible platform. I’m interested to see if the out of browser experience is available on multiple platforms. It might be a potential replacement to Adobe Air. It also looks like the first step to desktop applications, written with Microsoft tools, that run on all platforms. This has to be the eventual future of Silverlight.

Session 1: An Introduction to Inversion of Control
by Dru Sellers

This session, like Tim Bracz’s session, reaffirmed some of the efforts our team tried, but ultimately failed, to direct a former employer to adopting a Dependency Injection pattern. Dru had one of the most fluent presentation styles at the conference. It really helped me to pay less time reading slides, and more time listening to what he had to say. I love presentations with props, and even though Dru’s prop was as simple as a magazine cover, it brought a tactile perspective to his session that others lacked. Props go a long way in my opinion. If for nothing more than holding up the book you are talking about, I pay more attention.

This presentation would have been awesome following right behind the Tim Bracz’s. Tim’s session does just what the title says and eases you into unit test by eliminating dependencies and introducing mocking. Dru’s shows how IoC allows classes to be designed and instantiated without those hard coded dependencies. Lee Brandt’s session on BDD then breaks the stigma of tests. It feels like a full journey from no testing to living breathing specifications in code.

Session 2: n/a

I started out in one of the sessions in this time slot, but was interrupted with a phone call and felt the talk looked like it was similar to another, so I skipped out.

Lunch

Lunch was again way too long. The previous session ended at 11:40, but lunch didn’t start until 12:00? And then it ended at 1:05, but the next session does start until 1:15? That’s 95 minutes for lunch. It was made even worse since I skipped out on part of the previous session.

Session 3: Getting Started with Behavior-Driven Development (BDD)
by Lee Brandt

Lee made a great case for BDD. Whenever people have asked me what was different between TDD and BDD, I usually struggled and described TDD as the class-per-test anti-pattern and BDD as a specification focused more on what was going to be delivered to the customer. It turns out Lee agrees with me!

Lee gave a good introduction to MSpec, which I’ve seen before. MSpec looks so foreign to people, I think showing a sample of an NUnit test broken in the parts of an MSpec might ease the eyes into seeing the classes named “It”. Take for example our specification pattern.

[TestFixture]
public class When_a_specific_action_happens : Specification{
	override public void Context(){
		// Arrange
	}

	override public void Behavior(){
		//Action
	}

	[Test] public void the_specific_action_should_be_tested(){
		// Assert
	}
}

And then transform that into:

[Concern("Console runner")]
  public class When_a_specific_action_happens
  {
    Establish context = ()=>
    {
      // arrange
    };

    Because of = ()=>{
	   // action
    }

    It the_specific_action_should_be_tested = ()=>{
	   // assert
    }
  }

Classes named “It” and the extensive use of Lambda can make the MSpec look intimidating.

Another warm fuzzy I took from Lee was keeping in “User Voice” throughout the spec. I’ve written several extension method to Selenium and NUnit’s assert statements to keep the tests as readable as possible. Our Selenium test specifications have lines that look like the following.

	theBrowser.hasTextBox("firstName").WithValue("Mark");
	"errorPanel".aspNetControl().isVisibleIn(theBrowser);

It isn’t as close to English as MSpec, but is better than without it.

Session 4: Something about WPF and Surfaces

The session I saw on Microsoft Surfaces is not on the agenda via the website. Surfaces looks really attractive, but I still see little use for it, at its current price point, beyond marketing eye candy. That is a valid use, and the application they wrote for it would definitely draw people into a trade show booth.

To me though, this is still the how I see surfaces (even through this isn’t Surfaces.).

Session 5: LINQ Internals
by Keith Dahlby

The final session of the conference was by far the most in depth. This happened to me when I went to Tech Ed in 2008. The last session was on LINQ and how expressions trees worked, but I was too exhausted to stay awake through it all. Luckily for me, either STLDODN was shorter and I wasn’t as exhausted or Keith was more entertaining, but I was able to walk away with a good foundation for developing my knowledge of LINQ and Providers to the point where I can start writing my own.

Keith is another one of those presenters that I would see regardless of what they were presenting. I saw him talk at St Louis MOSS Camp, and his presentation saved the event for me. While STLDODN was good all around, Keith not only knows his stuff very well, but tries to transfer as much of that knowledge as he can in 75 minutes. In the arena of LINQ, that is a difficult task.

We have several vendor API’s that could be easily wrapped with a LINQ provider and we would be free from their tedious API calls.

Overall

Overall St Louis Day of .Net was a huge success and well worth the registration cost and time away from work. You won’t find so much knowledge, so close to home for so little money. Tomorrow, or later in the week I have a few improvements I would like to see next year.

Here are some of the photos from the event.

St Louis Day of .Net Day 1 Overview 1

Following acronymitis, today’s post, in addition to being subtitled The Return from Hiatus, will be so called SLDODNDOO. It’s been a while since my last post, but I have been hard at work, and will soon have plenty of new and exciting jQuery adventures to detail. For now, I thought I would get back in the swing of things by covering today’s events at St Louis Day of .Net. I was able to attend last year’s STLDODN while on a few days break between jobs and I am lucky enough to be attending this year’s event, packed with 100% more excitement (two days instead of one).

The Venue

This year the event has, what looks like to me, to be twice the number of attendees and the venue is a twice as nice. The Ameristar Casino and Conference Center is a great venue for a conference. Walking into a Casino at 6:30 AM on a weekday does feel a bit odd, but the facilities are beautiful, spacious and impeccably clean. Registration lines looked intimidating long at first, but they moved incredibly fast and I was through in no time.

Breakfast was delicious. I ended up showing up a bit late and there were still plenty of pastries left. There was plenty of coffee, soft drinks and water. The porcelain cups and plates highlight the elegance of the venue.

Session 0: The Jump Start Sessions

The first set of sessions in all tracks were Jump Start sessions meant to provide a brief, bird’s eye overview of a topic in each track. I am always a little skeptical of such sessions. I’m afraid they will either be full of malicious use of flashy technologies or nothing more than what I could read in a blog post. It was probably a mistake on my part, but I chose a topic I know pretty well, in hopes of getting a new angle on my problems or validation in what I was doing. If I had been more outgoing, I could have offered additional insight to the problems others in the session voiced, but not being so, I sat, gaining little, offering even less.

Being all the sessions at that time, across all tracks, were probably similar in content depth, I would have been better spent in a session I knew little to nothing about, or were willing to offer more in those where I have a well-established understanding.

Maybe instead of starting the day with sessions easy on the brain, letting everyone ease into the day, starting off with a keynote, with everyone in the same room, might fire up excitement and get people ready to absorb all the information they can the rest of the two days. The intro sessions could be moved to lunch where we could be enlightened while we eat.

Another option, for both the opening session of the day and lunch, would be to intentionally presenting topics from outside people’s comfort zone, but do so in small 15 minute slices. Sessions like showing SVN, Git, Ruby, Rails, IronPython, IronRuby, etc. would , while not directly relating to most people’s daily lives, offer some breadth to their understanding about what what else is going on in the world. I have a list of session I would like to see, and/or possibly contribute to in the future.

Session 1: Agile Iteration 0
by Ken Sipe

At my current employer we are struggling to implement an Agile process. We recognize the need for it as the business grows, but are having a hard time breaking tradition. Ken did an amazing job with not only the quality of his content, but the engaging and entertaining presentation. I suppose it is only natural that the process coach would be extroverted and outgoing. He identified the pain points we’re currently feeling and why each of the facets of an agile methodology are important. For example, he discussed why velocity is not only important for providing solid estimates, but to correlate with bug rates, and probably test coverage, to determine when teams are moving to hastily.

Session 2: Easing into Unit Testing with Mock Objects
by Tim Barcz

This session really hit home and not only validated the efforts I’m making at my current employer, but also the code I left at my previous one. While I’ve heard we were creating useless levels of abstraction, just for testing purposes. I am reassured I am not alone in believing in their concept and their importance. We were creating the same abstractions on top of those pesky static calls and are currently organizing tests in a similar fashion.

Tim prefers to separate the responsibilities of each test in a different regions of each test.

	[Test] public void Each_test_should_describe_what_it_does(){
		// Arrange

		// Action

		// Assert
	}

We are essentially doing the same thing.

[TestFixture]
public class When_a_specific_action_happens : Specification{
	override public void Context(){
		// Arrange
	}

	override public void Behavior(){
		//Action
	}

	[Test] public void the_specific_action_should_be_tested(){
		// Assert
	}
}

I actually like our method better as it provides an English readable specification of the code and its current capabilities in the build report. We’re on the same page though and it’s good to hear that from an MVP. A coworker of mine shared my enthusiasm as just this week we were attempting to unit test code that has external dependencies that are difficult to mock.

Lunch

Lunch was your typical boxed lunches. The cookies were good. The oranges were a bit awkward to eat and not make a mess or smell like orange for the rest of the day. Lunch was also pretty long (1 hour 15 minutes). Thirty minutes would have been plenty, but I’m sure some found time to make a few throws at the craps table. We are at a casino after all.

Session 3: .NET 4.0
by Muljadi Budiman

I saw Muljadi at last year’s DODN speaking about pLinq and was really impressed. His talk on what’s new in .Net 4.0 was no disappointment, although I would have rather attended his C# 4.0 talk, as it would more directly affect me. Visual Studio 2010 looks nice, but I see little improvement over what ReSharper already does, outside of the ability to pop out source to a separate monitor. There are plenty of enhancements to its support for WPF, multi-threading, etc. ,but these are all spaces that I don’t dabble in on a daily basis. Muljadi is a great presenter and I would be sure to attend any session next to his name.

Session 4: User Experience != User Interface
by Brad Nunnally

Brad has obviously read Presentation Zen, or seen enough presentations by those whom have. It was nice not having to see bullet point after bullet point, and actually listen to what he had to say. I do think the title of the presentation would better serve the audience if it described, what I felt, was the theme of the presentationL Why should you care about UX?, or: The role of a UX Engineer. The topic, maybe only to me, was ambiguous, although the material was well-prepared and direct. I have to admit, I found the animation between the slides distracting and unnecessary. They disrupted the cadence of the presentation as we all waited for them to transition.

Session 5: ASP.Net MVC
by Chris Patterson

After believing the Windows Mobile session was cancelled (it really wasn’t), I popped into the ASP.Net MVC session expecting an overview of MVC, but was presently surprised. Chris did a good job of closing the gaps on the bits of MVC that I’ve been bothered by in other demos, talks and blog posts; namely the over-dependency on strings. Chris showed how some future/contrib packages allow type safe views, view data and control actions. My next project is slated to be our first step into the MVC space, and I look forward to putting some of Chris’s wisdom into action.

The After Party

It’s late and I’ve been typing for a while. I’m getting brief, but about to get briefer. The after-party was at Home night club at the casino. It was really swank, but it might have been too swank for me. Maybe I’m unrefined, or unsophisticated, but I would have much rather preferred beer and pizza in a casual environment to fancy hors d’oeuvres and night club drink prices at 6:00 in the evening. It was nice to be able to mix with everyone, although I know I wasted the opportunity to meet several of the presenters and people I follow on Twitter.

Tomorrow

I’m looking forward to tomorrow, although I am still undecided if I’ll be there for the JumpStart sessions.

Check out my review of day 2.

I’m Wasting My Montior 4

I know I’m wasting my 24” widescreen monitor, but I don’t like the layout of the following markup.

<asp:TextBox runat="server" ID="txtPasswordExisting"
   TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"
   CssClass="error" ControlToValidate="txtPasswordExisting"
    Display="Dynamic" Text="Username is required." ValidationGroup="AssociateAccount" />
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender7" runat="server" TargetControlID="RequiredFieldValidator2"
    HighlightCssClass ="error" CssClass ="validatorCallout" />

I would prefer this.

<asp:TextBox runat="server" ID="txtPasswordExisting"
    TextMode    ="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"
    CssClass            ="error"
    ControlToValidate   ="txtPasswordExisting"
    Display             ="Dynamic"
    Text                ="Username is required."
    ValidationGroup     ="AssociateAccount" />
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender7" runat="server"
    TargetControlID     ="RequiredFieldValidator2"
    HighlightCssClass   ="error"
    CssClass            ="validatorCallout" />

…OK. It doesn’t display nicely in the syntax highlighter because of the proportional width font, but you get the idea.

I’m sure in most people’s mind it is wasted vertical space, but it makes doing diffs so much easier and my eyes easily see the grouping of controls and their attributes.

Resetting Team Build IncrementalGet Builds 0

After tinkering around with file attributes in our build’s working folder, I needed wipe the entire working directory and start with a fresh set of source. Just deleting the working directory isn’t good enough if you’re using incremental gets.

The build must store the most recent changeset it’s built and only get changesets that are greater than its current. If you try and just delete the working directory and build you’ll get the following error.

error MSB3202: The project file "…whatever.sln" was not found.

To tell the build not to do an incremental build on this one single build in the queue, add the following property to the Queue Build window.

image

Getting around UAC 4

So I never used Vista, except for the 30 minutes between un-boxing my PC and upgrading to Windows XP, until my new position. It’s pretty and glossy, but I am starting to understand the UAC headache. So here is one way I’m working around the frustration.

Pretend you want to edit a file that needs elevated rights. Usually you won’t realize it until you’ve opened it, attempted to save it, and found it doesn’t allow you to so.  Then you open Notepad, browse to the file and then make the change.

I found this helpful article about how to customize the Send To menu in Vista. I followed that and added Notepad to that folder twice. One was a regular shortcut, but I renamed the other to “Notepad as Administrator”.

image

Then right click the Notepad as Administrator, click Properties, click Advanced, and then check Run as administrator.

image

Click OK out of all the dialogs. Now when you right click a file you have a few extra options.

image

WPF Toolkit DataGrid, ColumnHeader Style and Blend 4

I’ve spent the better part of the day trying to figure out how to style the column headers of my WPF Toolkit datagrid through Microsoft Blend. Blend is a great tool and I couldn’t imagine trying to do a WPF application without it; however it is still immature and this could be why I found it so difficult to figure out. It could just be that I’m new to Blend, WPF, and XAML and still have a lot to learn.

I’ll spare you the agony I suffered this morning and jump right into the solution.

We have a pretty basic style for the datagrid at the moment. You’ll have to forgive the visual obfuscation.

Changing the the column header style looked pretty obvious in Blend. The menu walks me through the steps to create a resource for the header style.

Give the style resource a name. In this case I am going to show a pivoted set of data with a set of frozen columns on the left and columns that accept entering data on the right. I give it the name I want and choose its destination.

When the steps are complete, I have a style in the resources dictionary for my window, but something is missing.

I’m not sure if I’m missing a step, but the target type of the resource is the generic IFrameInputElement type. It doesn’t provide any properties to set in the designer.
If I look at the XAML that was created, it doesn’t give it a type.
<Style x:Key="EnterableColumnHeaderStyle"/>

The examples I’ve been seeing have a TargetType property to allow for the attached properties to work properly. I got ahead and add my TargetType property.

As you can see, I’m still learning WPF and XAML.  ReSharper steps in and offers to help out a bit. I am glad to let it. It adds the proper namespace to the resource:

<Style x:Key="EnterableColumnHeaderStyle" TargetType="primitives:DataGridColumnHeader">

It also creates the namespace directive:

I don’t really like the namespace alias, so we’ll change it with the help of ReSharper.

Blend now knows our target type and gives us all the properties we could want to style.

We can do whatever we want with the column header now.

And, just as we’d expect, we get our new style.

We can also apply a style to a particular column.

<wpfToolkit:DataGridTextColumn x:Name="FirstColumn"   Header="Something"  HeaderStyle="{StaticResource FrozenColumnHeaderStyle }" >

Next Page »