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 6084861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:23+00:00 2026-05-23T11:34:23+00:00

I have the following control: <UserControl x:Class=DNC_v3_0_Admin.Controls.FilterableTreeViewControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:Controls=clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls xmlns:Converters=clr-namespace:DNC_v3_0_Admin.Converters xmlns:Data=clr-namespace:System.Windows;assembly=System.Windows.Controls

  • 0

I have the following control:

<UserControl x:Class="DNC_v3_0_Admin.Controls.FilterableTreeViewControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    xmlns:Converters="clr-namespace:DNC_v3_0_Admin.Converters" 
    xmlns:Data="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:my="clr-namespace:DNC_v3_0_Admin.Controls"
    x:Name="MyFilterableTreeViewControl">

    <UserControl.Resources>
        <ImageBrush x:Key="PropertiesBrush" ImageSource="../Resources/machine.png"/>
        <Converters:ManagedObjectNodeIconConverter x:Key="TreeIconConverter"/>
        <Data:HierarchicalDataTemplate x:Key="FilterableTreeViewTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal" Height="Auto" Width="Auto" Grid.Row="0">
                <Image Source="{Binding NodeType,Converter={StaticResource TreeIconConverter}}"/>
                <TextBlock x:Name="NameTextBlock" Text="{Binding Name}" controlsInputToolkit:ContextMenuService.ContextMenu="{Binding ElementName=MyFilterableTreeViewControl, Path=ContextMenu, Mode=TwoWay}" />
            </StackPanel>
        </Data:HierarchicalDataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <Controls:TreeView Name="treeView" Style="{StaticResource MachineGroupStyle}" ItemsSource="{Binding ElementName=MyFilterableTreeViewControl, Path=ItemsSource}" SelectedItemChanged="treeView_SelectedItemChanged" />
    </Grid>
</UserControl>

The code behin:

    public ContextMenu ContextMenu {
        get {
            return ( ContextMenu )GetValue( ContextMenuProperty );
        }
        set {
            SetValue( ContextMenuProperty, value );
        }
    }

    public static readonly DependencyProperty ContextMenuProperty =
        DependencyProperty.Register( "ContextMenu", typeof( ContextMenu ), typeof( FilterableTreeViewControl ),
        new PropertyMetadata( null, new PropertyChangedCallback( FilterableTreeViewControl.OnContextMenuPropertyChange ) ) );

    private static void OnContextMenuPropertyChange( DependencyObject d, DependencyPropertyChangedEventArgs e ) {
        FilterableTreeViewControl ctrl = d as FilterableTreeViewControl;
        ctrl.OnContextMenuChange( ( ContextMenu )e.NewValue );
    }

    protected virtual void OnContextMenuChange( ContextMenu NewContextMenu ) {
        //ContextMenu = NewContextMenu;
    }

And the usage:

        <my:FilterableTreeViewControl x:Name="machineGroupTreeView" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding TreeRootNodes}" FilterCaption="Filter:" SelectedItemChanged="machineGroupTreeView_SelectedItemChanged" >
            <my:FilterableTreeViewControl.ContextMenu>
                <controlsInputToolkit:ContextMenu>
                    <controlsInputToolkit:MenuItem Header="New" Command="{Binding NewCommand}" CommandParameter="{Binding Id}" >
                        <controlsInputToolkit:MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{StaticResource PropertiesBrush}"/>
                        </controlsInputToolkit:MenuItem.Icon>
                    </controlsInputToolkit:MenuItem>
                </controlsInputToolkit:ContextMenu>
            </my:FilterableTreeViewControl.ContextMenu>
        </my:FilterableTreeViewControl>

But the ContextMenu does not appear. Any idea?

  • 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-23T11:34:23+00:00Added an answer on May 23, 2026 at 11:34 am

    I changed the ContextMenu property to

    public ObservableCollection<MenuItem> ContextMenu {
        get {
            return ( ObservableCollection<MenuItem> )GetValue( TreeContextMenuProperty );
        }
        set {
            SetValue( TreeContextMenuProperty, value );
        }
    }
    

    and everything else accordingly, and now works fine.

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

Sidebar

Related Questions

I have the following control: <UserControl x:Class=FooBar.AnnotationControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Height=400 Width=500 > <ScrollViewer Height=400
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
I have a XBAP application with the following user control: <UserControl x:Class=XXX.UsersGrid xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
The following code-behind binding works for the SmartFormView user control: View: <UserControl x:Class=CodeGenerator.Views.PageItemManageSettingsView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I have the following as a custom user control: <UserControl x:Class=TestGUI.TBorder> <Border Style={StaticResource brdListBoxItem}>
If I have the following control: public partial class MyControl : UserControl{ public string
I have the following user control that is embedded within another user control. <UserControl.Resources>
I have the following class: public class LooklessControl : Control { public List<int> IntList
I have the following code: foreach (var control in this.Controls) { } I want
i have a simple usercontrol with following properties: public partial class RichTextEditorControl : UserControl

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.