Welcome to MSDN Blogs Sign in | Join | Help

Update your bookmarks and blog readers--I'm moving

Lake Okoboji is freezing over indefinitely.

In an effort to unify all the random stuff I do, I've rolled my WPF blogging under my (vanity) domain.

Point your favorites and feed aggregators to work.j832.com.

See you on the other side!

Posted by okoboji | 0 Comments

Updates to 2 must-have applications! Both managed code! Both free (as in beer)!

Paint.NET ROCKS!

I can't imagine ever paying for Photoshop. Now in version 3.0. The killer new feature: MDI. Awesome.

Reflector .NET ROCKS!

(Via Chris, Via Chris.) Take a look at the PowerPoint deck for full details of v5.0. The killer new feature: Full C# v3.0 support. Awesome.

Posted by okoboji | 1 Comments

Windows Vista: What Should WebSite Hosters Do?

Check out Rob's blog on instructions for ISP's (or anyone that runs a server) on how to host WPF content (XBaps, XPS docs, etc).

If you're a WPF fan, link to this post. T'would be good to build awareness on this topic.

Posted by okoboji | 1 Comments

On ItemTemplate, ContentTemplate, DataTemplate

A recent forum post asked how one could build out ItemsControl-like functionality in a custom control.

Let me start from the basics.

ContentPresenter presents content. If you give it a UIElement (Grid, Button, Border) it will just display it. Easy enough. If you give it "data" (Customer, Order, Int32) it will display it using a DataTemplate.

DataTemplate is to data as ControlTemplate is to Control. It lets one define a tree of visuals that represent a given DataContext.

Robby and I chatted about this just over a year ago.

ContentPresenter is the "thing" that does the work to realize the DataTemplate. It has the magic.

One can give ContentPresenter a DataTemplate in two ways:

  1. Set the ContentTemplate property. This is typeof(DataTemplate)
  2. Set the ContentTemplateSelector. This is typeof(DataTemplateSelector)

The selector is used if the ContentTemplate is null. In the end, it just returns a DataTemplate.

With me so far?

Now ContentPresenter has no "chrome" to speak of. If you want to show content with some interactive chrome, use a ContentControl. This way you can show some non-data state (like selection, focus) and have non-data behavior (like checking or clicking). This is what Button, CheckBox, and ListBoxItem do.

All of these controls do very little. The own some purpose-specific state and rely on a ContentPresenter in their control template to do the work of displaying content. ContentControl also has a ContentTemplate property and ContentTemplateSelector property (as well as, you guessed it, a Content property). These are never really used directly by the Control, they are simply used to alias values down to the templated ContentPresenter.

Moving to ItemsControl (IC), we have a similar story.

IC has two analogous properties:

  1. ItemTemplate [typeof(DataTemplate)]
  2. ItemTemplateSelector [typeof(DataTemplateSelector)]

Now IC does a very specific trick. It takes data items from a list, creates wrappers (or containers) for each data item, and places them in a specified panel.

GetContainerForItemOverride is a virtual method on IC that is used to generate containers--ListBox creates ListBoxItem, TreeView creates TreeViewItem, etc.

PrepareContainerForItemOverride is another virtual method on IC. This is the method that marries the generated container to the corresponding data item. In the process, it sets up the container with the right properties from the parent IC. It sets the ContentTemplate of the container to be the ItemTemplate of the IC. Same with ItemTemplateSelector. When the container is a ContentControl, these are once again proxied to an underlying ContentPresenter.

The question on the forum asks how this can be accomplished in a custom control. Well, if one doesn't want to use IC, one can accomplish the same set of things. Create code to generate either a ContentPresenter or ContentControl for each data item. Expose Template/TemplateSelector properties on your parent control. When you generate child items, make sure you alias the properties from parent to child. That's about it.

I do this trick in the Graph control as part of the Bag-o-tricks.

I know that the ItemTemplate, ContentTemplate, DataTemplate naming thing can be confusing. Remember, at the end of the day, it all boils down to a ContentPresenter + Template to display data is a cool way.

Hope this answers the question and sheds some light on the workings of our more complicated controls.

Happy hacking!

Posted by okoboji | 0 Comments

Programmer Don't Like to Code

Forgot what link brought me here, but I was quite impressed with the analysis.

Programmer's Don't Like to Code

...they like problem solving.

If programmers liked to code, we’d all be writing in machine language to this day. You can write that stuff all day and get precious little of the real problem solved.

If programmers liked to code, they wouldn’t value a language by its libraries. If programmers liked to code, every last one of us would be overjoyed to write our own HTTP client.

Interesting stuff...

Posted by okoboji | 0 Comments
Filed under:

Updated Bag-o-Tricks for January

In celebration of the availability of the January CTP of VS "Orcas", I've updated the bag-o-tricks.

(Actually, it's because I'm stuck at home, but I wanted an excuse to mention the VS CTP.)

Download here: http://wpf.netfx3.com/files/folders/controls/entry8196.aspx

Have fun!

New: Zap Scroller

(Cleaned up my Christmas present for public consumption.)

I've seen this trick done in flash quite a bit. I wanted to play with animating the "current item" in an ItemsControl. I also wanted to model a method for exposing a preview of all of the items in an ItemsControl.

I steal and extend some of the command tricks I used it "List Pager". Let me know what you think.

Updated: Graph

A couple of bug fixes. When you set the center node to null, I clear out the lines right away. New nodes come in randomly instead of at the same spot.

This post brought to you by: Windows Live Writer, Paint .NET, and .NET Reflector

Posted by okoboji | 3 Comments

A (super rough) Christmas Present

It's 1:22 AM. I think I'm getting sick. I'm flying out for California tomorrow. Haven't packed yet.

And I'm coding.

Some ideas you just have to get working before you can put them down.

In no way is this beatiful code. The end-to-end is pretty interesting, though.

When I'm back from Cali, I'll clean it up and put it in the Bag-o-Tricks.

In the mean time, have fun playing with ZapScroller.

Playing with control templates + commands + custom animation.

Build. Run. Let me know if you think I'm crazy.

In the mean time, have a safe New Year.

See you on the other side!

Posted by okoboji | 0 Comments
Filed under:

Attachment(s): ZapScrollViewer.zip

Chat with the WPF team tomorrow

Our holiday gift to you: listening. Tomorrow (Dec 21) 12:30 - 1:30 PM Pacific Time.

Details: http://msdn.microsoft.com/chats/

Add to Calendar

(As always, Tim is much more thorough than I.)

Posted by okoboji | 1 Comments
Filed under:

Expression Web - beautiful

I'm working on an end-of-year letter as web site. (Yeah, I'm a geek. I have way more email addresses for friends than mailing addresses.)

Anyway, I've been bought into CSS for a while. The start of my projcet aligned nicely with the shipment of Expression Web, so I've been giving it a go.

Amazing. The CSS experience is really nice. Managing a site via FTP, dealing with syncing, etc. all very cool.

Give it a test run. You'll be happy.

Posted by okoboji | 0 Comments

Business Objects are cooler than you think

I think it was Paul Stovell's article on Validation in WPF that got me started. The article is amazing and has inspired a lot of my thoughts on what to do with binding in v-next.

Paul mentioned CSLA. I wasn't familiar. I dug in. Found Rockford Lhotka. Then I found Expert C# 2005 Business Objects.

Great book! (at least as of page 53).

I figured if we're going to build a foundation that allows easy use of business objects, I'd better understand them deeply.

An interesting nugget from the book: the philosophical difference between a relational model and a object model (at least according to Rockford).

Relational model: all about data. Should always strive for data normalization--reduce duplication of data.
Object model: all about behavior. Should always strive for behavior normalization--reduce duplication of behavior.

Things I rarely think about. I'll let you know if I get any other cool nuggets as I read.

Any other good resources on the topic that you know?

Hope ya'll had a good weekend.

Posted by okoboji | 3 Comments

New hotness, random musings

Interacting with 2D on 3D in WPF

Holy hotness!

Go build games for your XBOX

Too many links. A great write-up on FierceDeveloper.

Almost makes me want to buy a 360. (But then I wouldn't be coding WPF stuff, right?)

Diane: Space-of-the-week

Because Diane is female and we both work at Microsoft, I cannot legally use the word "hot" in this section. Diane and I met when we interned the summer of 2001. She's now out on the East Coast evangelizing.

Check out her blog. Send her a congrats comment and say Kevin told you to do so.

More teasing

I've made some hints about working on hotness (well, I guess I said "goodness"). I guess a more accurate description would be that I'm coordinating hotness.

Let's just leave it at this: 3DTools is just the start on CodePlex.

An aside: praise for Zune in Wired?

I love Wired, but the mag/website tend not to love my company much.

I was happily surprised to see this article: In Praise of Zune.

Yes, I'm posting a single positive article, while ignoring all of the negative articles from Wired and others. Still think it's nice to see our friends at Wired aren't myopic in their reviews.

Full disclosure, I've only played with the device briefly. But it's nice. If I wasn't so happy with my phone-as-music-player, I'd probably get one.

This post brought to you by Windows Live Writer. Yes, I made an attempt to proof-read this post. :-)

Posted by okoboji | 1 Comments
Filed under: ,

What do I love about Vista? Everything Chris loves

Mr. Sells does a great job of listing the great features of Vista. (Including some things I don't use enough.)

I had fun bringing my laptop back to Iowa for Christmas Thanksgiving. Everyone I showed just sayed said "wow". I'm proud to have shipped code on the DVD.

I had to uninstall the games because I was playing Free Cell too much. It's just too beautiful.

More WPF goodness coming soon, I promise.

Hope everyone had a good Turkey day!

(Update: I'm also thankful for co-workers who aren't shy to tell me when I make a fool of myself.)

Posted by okoboji | 3 Comments

Bag-O-Tricks : RTM Edition

Okay, I admit I should have a whole mountain of new and sexy stuff for the RTM release. I've been busy lately. Busy with fun stuff. I'm hoping I'll get to talk about it soon. (Yeah, I'm a huge tease. No, I won't be able to share anything with you even if you send me email. Just be patient.)

Anyway, the download location: http://wpf.netfx3.com/files/folders/controls/entry7094.aspx

The changes:

New: ListPager

I've heard this request a lot: how do I add paging support to ListBox? There are a number of ways to bake support into the control, but there are few ways to do it cleanly.

One of the benefits of WPF is that we have great support for data. Why not solve the problem in the data layer? More specifically, build a data component that can be used in XAML to provide paging services over any IList. Sound good?

ListPager has the magic. It takes an IList as ItemsSource property and exposes a CurrentPage that is a page of items out of the source.

UIListPager takes things a step further by exposing a set of commands that are easily bound to the UI via our command model.

The result: a very clean, extensible model for paging through data.

As a bonus, I built ListBase<T>, since I was getting sick of doing all the work to implement IList<T> and IList. One should only have to provide an indexer and a count. I tried to build this class as clean and correct as possible, but a CLR dev I am not. Let me know how it works for you.

Update: Graph

I fixed some bugs in Graph. All of the nodes should be cleanly and consistently recycled now. I also started playing with changing the location of the nodes using RenderTransform instead of via Arrange.

Now Graph is not a standard control. It has children, but the size of the Graph doesn’t affect the size of the children and vice versa. My goal: minimize the churning of layout when possible. My solution was a bit interesting. I overrode Measure and Arrange in GraphContentPresenter so they always return the same size. The effect: the parent layout is almost never invalidated (except when the number of items changes). Now this is not a 100% blessed model for layout. I need to work through some details with the really smart people on my team. In the mean time, play with caution.

Update: InfoTextBox

A couple of helpful customers pointed out a bug in my implementation. Mouse input was being taken by the “Info” and not getting to the TextBox. A simple property set (IsHitTestVisible=”false”) was all it needed.

Posted by okoboji | 1 Comments

How you can tell the bolts are tightening

I tested the latest rev of the bag-o-tricks on Vista RC1 (which included the .NET Framework 3.0 RC1) with VS 2005 RTM.

I just did an install of .NET 3.0 September CTP + Orcas tools ("Cider") September CTP + VS 2005 SP1 Beta on my XP machine at home.

All of the samples still build and run fine. "Cider" and the VS beta seem to play along nicely, too.

Hurray for locking down!

(I'm pretty sure anyone can apply to be on the beta of VS 2005 SP1. Go to connect.microsoft.com. Click on Visual Studio and .NET Framework under Available Connections. Fill out the Nomination Survey. At least that's what I did. No promises you'll get in.)

Posted by okoboji | 0 Comments

The Bag, the Blogs, the Betas

The Bag

Glad to see people are downloading the RC1 rev of the bag-o-tricks.

Thanks for the love. (Always love to hear I have "nice code".) I've already gone down another level on some of the layout tricks I use to get the animation working with layout. I plan on more updates (and hopefully a code walk-through) in the near future.

Is there a particular demo in the bag-o-tricks that you'd like me to walk through? I was thinking a screen cast would be a good place to start.

Let me know.

The Blogs

Some great blogging happening in WPF land.

  • Rob's making me look bad. Great info. Now that I sit next door to him in building 10, maybe I can distract him from his constant posting.
  • Mike Hillberg is a god. (Not the God, just a god.) Not only his he technically brilliant, he's amazingly thorough and a really nice guy. Talk about team mates that make me look bad. (Update: Yes, that's Mike, not Hike.)
  • the WPF blog. Great use of XBAP for demos. Some...uh..."interesting" content. :-)
  • The Windows Shell: Revealed. Not a WPF blog, but pretty darn cool. My buddy Vinny put it together. Great information about the face of Windows Vista.

The Betas

Happy Tuesday.

Posted by okoboji | 1 Comments
More Posts Next page »
 
Page view tracker