Message.Action in ListBox?

Topics: Actions & Coroutines
Apr 3, 2013 at 8:40 PM
I have templated a ListBox, and I'm having trouble getting the Action to work.

Here's a rough example of how it's templated.
<ListBox.ItemTemplate>
  <DataTemplate>
    <ToggleButton IsChecked="{Binding Path=Enabled}"
                  cal:Message.Attach="FilterEnable($dataContext)">
      <Image Source="{Binding Path=ImagePath}"/>
    </ToggleButton>
  </DataTemplate>
</ListBox.ItemTemplate>
Using Snoop, I can see that ListBoxItem.IsSelected=true, but I think what's going on is that I'm not actioning on the ToggleButton, but instead, up the visual tree on just the ListBoxItem. Should I forgo the ToggleButton and throw Message.Attach on the ItemContainerStyle setter?
Apr 11, 2013 at 6:19 PM
Edited Apr 11, 2013 at 6:35 PM
do you get any error to the FilterEnable not being found a suitable signature in the viewmodel?
Apr 11, 2013 at 6:34 PM
Edited Apr 11, 2013 at 6:50 PM
No errors that I could see. Exceptions in CM don't seem to bubble up for me, maybe that is intended. By the way, I got it working by doing this on the ItemContainerStyle. Note the use of Action.TargetWithoutContext.
<Style BasedOn="{StaticResource ActualItemContainerStyle}" TargetType="ListBoxItem">
  <Setter Property="cal:Action.TargetWithoutContext" Value="{Binding RelativeSource={RelativeSource AncestorType=ListBox}, Path=DataContext}" />
  <Setter Property="cal:Message.Attach" Value="[Event Selected] = [Action Highlight($dataContext)]" />
  <Setter Property="cal:Message.Attach" Value="[Event Unselected] = [Action Highlight($dataContext)]" />
</Style>
Apr 11, 2013 at 6:47 PM
lol :) yea :)
Apr 11, 2013 at 7:50 PM
Edited Apr 11, 2013 at 7:50 PM
yep that was the way to do it with TargetWithoutContext.

I run with a Console Logger (vs.net console) so I see what is happening with the binding.