Nov
17
2008
0

WPF Toolkit DataGrid, ColumnHeader Style and Blend

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:

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 }" >

Written by mark in: Uncategorized, WPF | Tags: , , ,
Nov
13
2008
0

ReSharper Tip of the Day: Put into ‘using’ construct.

There has been some debate if you need every IDisposable should be disposed. From the documentation IDisposable is used to clean up any unmanaged resource.

Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector.

OK. That’s fine. I totally agree with that until I see DataTable is derived from a class, MarshallByValueComponent, that implements IDisposable. Does that mean DataTable has unmanaged resources? Any way, on to the tip.

ReSharper notices when an object is created that implements IDisposable and it can automatically wrap the usage in a using block. Say you have the following code:

…and want to put it in a using block. Trusty ALT+Enter steps in a gives you the following options:

It is creates a nice using block around the object and all of its usages.

What would really be nice is we could create a warning when we see ourselves using an IDisposible without calling Dispose. That might be more difficult than finding one outside of a using. We could be calling Dispose in a try/finally or somewhere else.

Written by mark in: ReSharper Tip of the Day | Tags: ,
Oct
08
2008
2

ReSharper tip of the Day: Move Code Left and Right

Josh showed us how to slap around our code with CTRL+ALT+SHIFT+UP|DOWN. We can now smack around our markup a little further. In addition to the four fingered up and down bully job, we and take an attribute left or right in the pecking order of the opening tag.

CTRL+SHIFT+ALT+LEFT|RIGHT (right in this case) bumps the attribute over.

If you prefer a more vertical representation of the attributes like the following, the command still works, but less intuitive since left and right actually move it up and down, and up and down move the entire tag up and down.

<CheckBox
     Margin="0,0,0,0"
     Unchecked="DoUnchecked"
     Checked="DoChecked">
     Some Text
</CheckBox>

One last thing to note is you do not need to select the entire attribute. Having the cursor in the attribute you wish to move is enough.

Written by mark in: ReSharper Tip of the Day | Tags: , ,
Oct
06
2008
0

ReSharper Tip of the Day: Agent Smith and Agent Johnson

On the advice of a super bright coworker, I installed the Agent Smith and Agent Johnson plugins for R#. Now I’m getting all kinds of new advice and context actions.

Written by mark in: ReSharper Tip of the Day | Tags: ,
Sep
25
2008
0

ReSharper Tip of the Day:More Reminders

I’ve stalled with providing tips for a while. My development at work will pickup and I will soon lots of new tips. As we work into using C# 3.0 I am sure ReSharper will continue to impress. For today though, we have a simple reminder.

Alt+Page Up|Page Down goes to the next ReSharper gutter item.

This just saved me a ton of time. We are currently converting some .Net 2.0 code to target .Net 3.5. In so doing I am going to make use of the new language features. Our domain objects are classes with series of classic properties.

    private string fooberry;
    public string Fooberry{
        get{ return fooberry; }
        set { fooberry = value; }
    }

To convert these to automatic properties I could have copy and pasted {get;set;} after each property name and deleted the rest, but R# made it much easier. Alt+Page Down took me to the next suggest which was to convert to automatic properties. Alt + Enter opened the context window with the first action being convert to auto property. Pressing Enter one last time had it fixed.

    public string Fooberry{ get;set;  }

What made it so effective was I was able to hold down Alt the entire time and press Page Down, Enter, Enter, Page Down, Enter, Enter,etc. until my properties in that file were all changed. Total time to convert 20 properties…10 seconds. Try that with copy and paste. I bet it is a bit higher.

Written by mark in: ReSharper Tip of the Day | Tags:
Sep
19
2008
0

ReSharper Tip of the Day: Reminder, Keyboard Short-cuts Work in Other File Types

Just a quick reminder, most keyboard short-cuts work in other files types besides source code. In XML and HTML you can:

  • Ctrl + Shift + / to toggle comments
  • Ctrl + w to expand selection
  • Ctrl + Alt + Shift + Up|Down to move elements up or down.
Written by mark in: ReSharper Tip of the Day | Tags:
Sep
08
2008
0

ReSharper Tip of the Day: Add UsingTask

While working in an MSBuild file I notice ReSharper will help you out with using new tasks. If you use one it doesn’t know, it’ll offer to add its UsingTask statement to reference it.

It’ll throw this in at the top of the document.

<UsingTask TaskName="Fooberry" AssemblyName=""/>>
Sep
03
2008
0

ReSharper 4.1 Released

JetBrains released ReSharper 4.1. Read the release notes at JetBrains.

Written by mark in: ReSharper Tip of the Day | Tags:
Sep
03
2008
0

ReSharper Tip of the Day: Refactor This

In a recent post Oleg Stepanov pointed out the mother of all refactoring shortcuts. At any point, you can press Ctrl + Shift + R to see all possible refactorings available under your current context.

What I’ve lacked lately in content, I can make up in screenshots. 

As a side note, this is a the first post written with Google Chrome. So far I really like it. The one thing I’ve found that is slightly odd is that backspace will take me out of my text area and an additional backspace will go back in the browsing history.

Written by mark in: ReSharper Tip of the Day | Tags: , ,
Sep
02
2008
0

ReSharper Tip of the Day: Find Implementers

I realize I haven’t posted a new tip in a while. Maybe the day to day drudgery is leaving me temporarily uninspired. To counteract that, I’ve dug up an old tip I’ve sent out a while ago to my coworkers. 

If want to find which classes extend your class or implement your interface that currently has focus, press Ctrl + End.

This is really handy to flip between the fakes and real classes during testing. When down in the guts of methods, don’t forget that Ctrl + [ will take you back to the enclosing block. 

Sorry about the smudgy obfuscation and oversized image.  Hopefully we’ll have some fresh tips soon.

Written by mark in: ReSharper Tip of the Day | Tags:

Powered by WordPress | Kredit | TheBuckmaker