Have You Checked the Children?

He says in his best maniacal voice...

I assume you know that the fairly recent movie "When a Stranger Calls" is a re-make of the 1979 original which starred Carol Kane as the babysitter.  You may remember Carol Kane as Simka, Latka Gravas' (Andy Kaufman) wife in the TV show Taxi.  Andy's dead now you know...sad really...he kind of went off the deep end when he started wrestling women...

Blog reader: What the hell are you talking about?

Sorry, my mind wanders like that from time to time.  Don't know if it's because I'm a product of the 60's or if I'm just getting old or that I'm just plain out of my FREAKIN' gourd!

Okay, I'm better now.  So anyway, I wanted to give you a heads up that there is a breaking change coming in the Crossbow API for Beta2.  There used to be a Children property on WindowsFormsHost control.  You would use the property to add your subsequent Windows Forms control to the host via the Children.Add() method.  We'll it ain't there anymore.  We replaced it with a Child property.  This was done because we felt it was kinda stupid to have a collection property that limited you to one item.  (You may remember that even though we implemented this property as a collection, we enforced a limitation of a single item in the collection).  So now there's just the single Child property and you simply assign some Windows Forms control to it.

   WindowsFormsHost host = new WindowsFormsHost();
Button wfButton = new System.Windows.Forms.Button();
   wfButton.Text =
   host.Child = wfButton;

Likewise on the ElementHost control, we used to have the Controls collection property where you added your single top-level element.  Now we have replaced that with a Child property as well.  Once again, we just wanted to remove the collection and replace it with a singleton and maintained consistency with the naming.

   ElementHost host = new ElementHost();
Button wpfButton = new System.Windows.Controls.Button();
   wpfButton.Content =
   host.Child = wpfButton;

Note that this change goes into effect in the Beta2 drop of Crossbow.

So next time when the compiler calls and tells you something's wrong...remember to check the children...


Comments (4)

  1. olivia says:

    hmmm…its all a bit uninteresting really…i want 2 hear more about the movie ‘When a Stranger Calls’!!! you knoe…sumthing INTERESTING?!

  2. Timothy Paul Narron says:

    I’m sure I am asking you to revisit something but now that you are a movie star your audience just got a lot bigger. I am your first groupie. Don’t get a big head, I am fickle and will probably be into origami tomorrow…

    but why only one child? wouldn’t it be more intuitive if it accepted more children like controls and xaml elements do?

  3. Note that I’m not saying ONE CHILD…but one TOP LEVEL CHILD.  This means that you can have many elements hosted as long as they only have one top level parent.  So for example, you could have a <Grid> element that has 100 children and you could host that <Grid> element along with its children in an ElementHost control.

    Hope this helps.

  4. Hey Olivia,

    What specifically would you like to hear?  What would be INTERESTING to you?

Skip to main content