Message.Attach Woes

Feb 15, 2011 at 3:03 PM

What types of parameters can be passed in Message.Attach? I'm trying to do a very simple show/collapse toolbar. The "show tools" button is simply a 90-degree rotated button and is x:Name "ShowTools", the "hide" button is at the top of a stackpanel (the menu) which is x:Name "Toolbar". When I pass these names via cal:Message.Attach="CollapseTools(Toolbar, ShowTools)", it always passes in the whole View (named ShellView in this case) for both parameters, rather than the Button and the StackPanel.

I don't want to used FindName on the passed parameters, that's WAY too much work; I'd just go back to code-behind in that case.

Coordinator
Feb 15, 2011 at 3:24 PM

ActionMessage parameters don't support passing controls around. You can only pass their properties.

Feb 15, 2011 at 3:34 PM

Using the standard syntax you should be able to pass a reference to a control with x:Reference (introduced in .NET 4.0) as a Parameter value.

<i:Interaction.Triggers>
       <i:EventTrigger EventName="Click">
              <cal:ActionMessage MethodName="CollapseTools">
                     <cal:Parameter Value="{x:Reference Toolbar}" />
                     <cal:Parameter Value="{x:Reference ShowTools}" />
              </cal:ActionMessage>
       </i:EventTrigger>
</i:Interaction.Triggers>

If this works, you could even considering using the modifications presented here, that should allow for something like

cal:Message.Attach="CollapseTools({x:Reference Toolbar},{x:Reference ShowTools})"

 

Feb 15, 2011 at 4:13 PM

Thanks for the replies. I've reconsidered this. I'm sure I'll get a lot of disagreement here, but I've decided that code belongs in CB (or pure XAML if I were the self-flagellating type). My reasoning is that it is "pure" UI code - its one and only purpose is to affect the presentation layer - no VM bindings, no messages, etc.

I guess another way to say it is that it's pure user interaction - the user and only the user decides when to show/hide the toolbox. When it comes time to decide which menu items are visible/enabled... then that's a whole different set of criteria that would most likely be VM related.

I'm sure I've said nothing controversial in this post, so... carry on. =c)

--Bruce P.