Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum

CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • TriggerAction on databound menus

    rated by 0 users
    Answered (Verified) This post has 1 verified answer | 1 Reply | 2 Followers

    Not Ranked
    9 Posts
    Daniel Morey posted on Thu, Aug 18 2011 8:30 AM

    I have a readonly list of TaskGroups that contains a description and a readonly list of Tasks that also contain a description.

    I've bound a MenuItem to the list of Task and I'm using HierarchicalDataTemplates to display the TaskGroup Description and Task Description in the menu. So the TaskGroups appear in the first dropdown and the Tasks appear when one of the task groups is hovered over.

    The problem I now have is that I have no idea which task has been clicked on. In the XAML only the root item is available and if I use a TriggerAction on that, I get the click event, but don't now which task was clicked on. I've tried adding a TriggerAction into the HierarchicalDataTemplate and linking it to the TextBlock I have in there but this doesn't seem to work, probably as it's the menuitem getting clicked and not the textblock.

    I think I could do this with commanding but I was trying to avoid that in case I ever needed to use more than the click event.

    Does anyone know if this is possible to do with the TriggerAction, or do I need to look elsewhere (and if so where)?



    Answered (Verified) Verified Answer

    Not Ranked
    9 Posts
    Verified by Daniel Morey

       I've found out how to do this. Here is my code:

            <Menu Grid.Column="0" Grid.Row="0" Background="White">


                    <HierarchicalDataTemplate DataType="{x:Type library:TaskInfo}">


                            <TextBlock Text="{Binding DisplayName}" />


                                TargetControl="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}"


                                DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Menu}}}"


                                MethodParameter="{Binding DataContext.DisplayName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}"




                    <HierarchicalDataTemplate DataType="{x:Type library:TaskGroupInfo}" ItemsSource="{Binding Path=Tasks}">


                            <TextBlock Text="{Binding DisplayName}" />




                <MenuItem x:Name ="MainMenuItem" ItemsSource="{Binding TaskGroups}"



                        <Image Source="/BxfTest;component/Images/logo.gif" />




     The TriggerAction goes into the DataTemplate for the menuitem, and links to the menuitem by using FindAncestor.

    Page 1 of 1 (2 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems