Matthias Shapiro

I need fewer hobbies

Triggering Events and Updating Bindings

Sorry for the extended absence… I’m been working myself to the bone on the Veracity submission to the Show Off at MIX08. We’ll have some really kicking stuff to play around with at the Open Space… you should drop by and say hi. I look something like this:


At least I look like that at 1:30 AM.

OK, so I felt the need to pipe up at this ungodly hour with a public service announcement about events and databinding. I just spent a good hour trying to figure out a workaround for this problem. I had a method being called on my “IsVisibleChanged” event. I was planning on take that item and performing some code-behind logic based on the databound Canvas.Left and Canvas.Top properties.

WPF put the smack-down on that action. The data binding wouldn’t update before the event was called. And I couldn’t make it. Not without some kind of Invoke… which, I must admit, scares the ever-loving crap out of me, so I didn’t try… also because I didn’t know how to use it.

My advice if your databinding won’t update? Find some way of going to the data itself. If you’re binding to something in the XAML, you should be able to find the object you’re binding to in the code as well. Just go straight to the source.

Anyone have a better idea or suggestion? I’m totally open to hearing it.

This entry was posted in Advanced Tutorial and tagged , , , . Bookmark the permalink.

0 Responses to Triggering Events and Updating Bindings

  1. Matthias Shapiro

    leovernazza, the problem I’m having is that my Visibility is databound to a data element (the same one that I’ve also bound to my Canvas.Left and Canvas.Top). When that visibility flips from “Collapsed” to “Visible”, I know that there is data on the object (Visible objects require that data), but it hasn’t updated through to the Canvas binding.

    The result is that the IsVisibleChanged is handled, but the Canvas bindings haven’t metriculated through to the layout. My solution involved just saying “screw it” to the layout and going to the object directly.

  2. Hey, don’t be afraid of Invoke or (BeginInvoke), it’s actually a very good friend to have sometimes. 🙂

    Email me if you want to talk about it (or we can get in touch at Mix).


  3. Mike Wolf

    being as that I havent gotten to bed before 3 am most nights the past week preping for mix and phizzpop I feel your pain brother … keep in there, a couple drinks on me next week.

  4. I don’t know if I understand your problem…

    object.Left has a databinding
    object.Top has a databinding
    object.IsVisibleChanged is handled

    What if you handle the change of the three properties? Could you?

    private void CallInAllChange()
    if (this.AllChangesWereMade)
    // do what you need