ContextMenu Hierarchical Data with Title

1 posts, 0 answers
  1. Farid
    Farid avatar
    2 posts
    Member since:
    Jun 2012

    Posted 24 Jun 2012 Link to this post

    Hi,

    I have to add Context menu in the page and this menu should be has the Title in the some sub menus (image attached).

    I did this:

    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu telerik:StyleManager.Theme="Windows7"
                        ItemsSource="{Binding SomeItemsSource}"
                        EventName="MouseLeftButtonUp"
                        ShowDelay="0"
                        Placement="Bottom">
            <telerik:RadContextMenu.ItemTemplate>
                <telerik:HierarchicalDataTemplate ItemsSource="{Binding SubItems}">
                    <telerik:ContainerBinding.ContainerBindings>
                        <telerik:ContainerBindingCollection>
                            <telerik:ContainerBinding PropertyName="Icon" Binding="{Binding Icon}" />
                            <telerik:ContainerBinding PropertyName="IsSeparator" Binding="{Binding IsSeparator}" />
                            <telerik:ContainerBinding PropertyName="Command" Binding="{Binding Command}" />
                            <telerik:ContainerBinding PropertyName="IsEnabled" Binding="{Binding IsEnabled}" />
                        </telerik:ContainerBindingCollection>
                    </telerik:ContainerBinding.ContainerBindings>
                    <ContentPresenter x:Name="contentPresenter" Content="{Binding Header}" />
                </telerik:HierarchicalDataTemplate>
            </telerik:RadContextMenu.ItemTemplate>
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>

    public class MenuItem : INotifyPropertyChanged
    {
        private object _header;
        private Uri _iconUrl;
        private bool _isSeparator;
        private bool _isEnabled;
        private bool _isTitle;
     
        public MenuItem()
        {
            SubItems = new ObservableCollection<MenuItem>();
            IsEnabled = true;
        }
     
        public object Header
        {
            get { return _header; }
            set
            {
                _header = value;
                OnPropertyChanged("Header");
            }
        }
     
        public Uri IconUrl
        {
            get { return _iconUrl; }
            set
            {
                _iconUrl = value;
                OnPropertyChanged("IconUrl");
            }
        }
     
        public bool IsSeparator
        {
            get { return _isSeparator; }
            set
            {
                _isSeparator = value;
                OnPropertyChanged("IsSeparator");
            }
        }
     
        public Image Icon
        {
            get
            {
                return new Image
                {
                    Source = new BitmapImage(IconUrl)
                };
            }
        }
     
        public bool IsEnabled
        {
            get { return _isEnabled; }
            set
            {
                _isEnabled = value;
                OnPropertyChanged("IsEnabled");
            }
        }
     
        public bool IsTitle
        {
            get { return _isTitle; }
            set
            {
                _isTitle = value;
                OnPropertyChanged("IsTitle");
            }
        }
     
        public ICollection<MenuItem> SubItems { get; set; }
     
        public ICommand Command { get; set; }
     
        public event PropertyChangedEventHandler PropertyChanged;
     
        protected void OnPropertyChanged(string propertyName)
        {
            if(PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    1. If I set IsEnabled property with binding it's not working correctly. For example, if I set IsEnabled property false that everything ok, but  when I'm using some Command and command canexecute method returns true that menu item still disabled.

    2. I tried to create my own custom control which inherited RadMenuItem and then I tried to use this control, but I had few problems with UI part.

    3. I tried to add my custom property with the name of IsTitle, but I have to know how I can change the default item type which used ContextMenu for create new menu item. (As I know, the default type which RadContextMenu used is RadMenuItem)

    How can I solve this problem?

    Best regards,

    Farid

Back to Top