Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 497025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:44:32+00:00 2026-05-13T05:44:32+00:00

I have three tree view controls which house different (but mostly similar data), as

  • 0

I have three tree view controls which house different (but mostly similar data), as a result the actions that can be taken at each level is the same as far as the user is concerned, but different in their type (which is something I have to worry about as the developer). What I would like to do is reuse this context menu and pass in a type to it (or be able to retrieve it) and then the type would get passed through to the actual Executed function.

So that we can have a common verbage here’s some code:

<UserControl x:Class="ucControl" 
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:local="clr-namespace:LocalNamespace"
 Name="ucControl" 
 xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
 Background="LightGray">
 <UserControl.Resources>
     <ContextMenu x:Key="GroupMenu">
         <MenuItem Header="Add Group" Command="New"/>
         <MenuItem Header="Rename Group" Command="local:CustomCommands.RenameGroup"/>
         <MenuItem Header="Delete Group" Command="Delete"/>
         <Separator/>
         <MenuItem Header="Change Contents of Group" Command="local:CustomCommands.EditGroupContents"/>
     </ContextMenu>
 </UserControl.Resources> 
 <UserControl.CommandBindings>
     <CommandBinding CanExecute="CanAddGroup" Command="New" Executed="AddGroup"/>
     <CommandBinding Command="local:CustomCommands.RenameGroup" CanExecute="CanRename" Executed="RenameGroup"/>
     <CommandBinding Command="local:CustomCommands.EditGroupContents" CanExecute="CanEditGroupContents" Executed="EditGroupContents"/>
 </UserControl.CommandBindings>
 <TabControl Name="tcTabs">
     <TabItem Header="Size" Name="tiSize">
         <TreeView Name="tvSizeGroup" ContextMenu="{StaticResource GroupMenu}"/>
     </TabItem>
     <TabItem Header="Brand" Name="tiBrand">
         <TreeView Name="tvBrandGroup" ContextMenu="{StaticResource GroupMenu}"/>
     </TabItem>
     <TabItem Header="Color" Name="tiColor">
         <TreeView Name="tvColorGroup" ContextMenu="{StaticResource GroupMenu}"/>
     </TabItem>
 </TabControl>

In this example, I would like for each of Size, Brand, and Color to have the same ContextMenu, but if the Context Menu is pulled up in the Size TreeView, I will need to add a group of type Size to my table. Is this possible the way I am doing it? I am trying to avoid making three ContextMenus, which would obviously be a way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:44:32+00:00Added an answer on May 13, 2026 at 5:44 am

    There is only one way i know to achieve this,
    In the CommandHandler you need to check that which Tree has called this.

    try this in your CommandHandler:

    MenuItem mnu = sender as MenuItem;
    TreeView tv = null;
    if(mnu!=null)
    {
        tv = ((ContextMenu)mnu.Parent).PlacementTarget as TreeView;
    }
    if(tv.Name=="tvSizeGroup")
    {
        //add group of Size
    }
    if(tv.Name=="tvBrandGroup")
    {
        //add group of Brand
    }
    

    Hope this helps!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hypothetical tree view that contains this data: RootNode Leaf vein SecondRoot
I have a tree view which has a folder icon by default and once
I have a WPF application that mostly follows MVVM, which I am trying to
I have a tree view control which I have to bind a dataset with
I have dialog box with two controls: tree view and list box . I
Hello All I am using infragsitics tree view control.I have one stored procedure that
There are no controls in Android that provide Tree-like View. There is an ExpandableList
I have a web application where I am using asp.net tree view control to
I have a tree view <asp:TreeView ID=TreeView1 runat=server DataSourceID=SiteMapDataSource1 ShowExpandCollapse=False> </asp:TreeView> As you can
I have a tree view defined as follows: <HierarchicalDataTemplate x:Key=ChildTemplate ItemsSource={Binding Children}> <TextBlock Text={Binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.