Relative path targeting in sketchflow / blend__ RRS feed

  • Question

  • How do I target something that's outside (usually above) the my current scope. Let's say I have a screen or component with a bunch of states in it. In it I have a user control or another nested component. I'm trying to trigger one of the states in the parent screen or component, from within that nested element. Hopefully that makes sense. Basically I'm trying to find a way of targeting the way we do parent, or parent.parent in Flash. So that I can have a control in multiple components, controlling the same things in its relative "parent".



    Friday, May 21, 2010 1:00 PM

All replies

  • There are a couple of approaches, you could traverse up the visual tree (the rough equivalent of parent.parent) and find the visual objects that way. However I would sy the preferred method would be to expose events on your usercontrol that the parent can subscribe to and handle appropriately.  This allows your usercontrol to stay general and helps with reuse.
    Friday, May 21, 2010 1:48 PM
  • ... the preferred method would be to expose events on your usercontrol that the parent can subscribe to and handle appropriately.
    Thanks Chuck. That sounds exactly like what I want to do, albeit stated more eloquently. Could you elaborate on that, or give me an example? I'm not a coder by the way.
    Friday, May 21, 2010 2:04 PM
  • Sure, could you give me an example of what you are trying to do so I can make my example more useful/illustrative for you?

    Also, are you using SL or WPF and what version?

    Friday, May 21, 2010 2:57 PM
  • I'm using WPF, Blend 4 Beta.

    I have a component screen with a few state animations, let's call it "Dad". Inside Dad is a user control: "Kid", which contains a bunch of things and a toggle button. I need the toggle button in Kid to trigger a state in Dad when toggled on, and another state when off.

    Note that I have duplicates of Dad in multiple screens and components, so it's essential for me to have him and the kid always behave consistently, without the need to duplicate code.

    In flash I would just create a Dad MovieClip, with a Kid MovieClip inside. And the kid would simply trigger a function in his parent, with "on" and "off" as its arguments, something like: MovieClip(this.parent).toggle(on) That way I would reuse Kid anywhere I want, knowing that it safely toggles something in his parent, NO MATTER WHO HIS PARENT IS.

    Hope that makes sense. Thanks,


    Friday, May 21, 2010 3:13 PM
  • OK, in WPF what you want to use are routed events, here is a good reference:



    Routed events can bubble up to their parent, no matter who the parent is.  I wrote a trivial example that uses the event they show on that page named Tap.  The name is arbitrary of course.

    I posted the code here:





    Friday, May 21, 2010 7:12 PM
  • Thanks Chuck. I think I did mention I wasn't a coder, didn't I? :)

    Your "very simple" example—which by the way was 120 lines of code—doesn't look so simple to me, especially compared to my very simple flash example. To my simpleton mind the "routed events" answer is almost as discouraging as "no you cannot do that in Blend".

    I guess I was naively expecting a built-in function. Like an expression I can enter in the ActivateStateAction>Properties>TargetScreen field which would make it target a relative component/control (a parent) instead of an absolute "screen". I can easily just go in there and enter "WpfPrototype1Screens.FrigginAbsoluteScreen" right? Why can I not simply type something like "parent" instead?

    I know I'm over simplifying this, but is it really expecting too much? After all Blend is supposed to provide an easy and visual way of doing things, right? I mean there is a check box for Grid.IsSharedSizeScope!!!

    Friday, May 21, 2010 8:33 PM