Click here to Skip to main content
15,892,965 members
Articles / Programming Languages / C# 4.0

Silverlight Menu

Rate me:
Please Sign up or sign in to vote.
4.85/5 (71 votes)
24 Apr 2011CPOL7 min read 405.4K   10.4K   117  
A lightweight, professional-looking, MVVM-enabled dropdown menu for Silverlight
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Windows.Markup;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace SilverlightMenu.Library
{
    [ContentProperty("MenuItems")]
    public class MenuItem : ObservableCollection<MenuItem>
    {
        #region attributes
        bool isEnabled = true;
        bool isCheckable = false;
        bool isChecked = false;
        int level = 0;
        #endregion attributes

        #region Events
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            string s = "";
        }
        #endregion Events

        #region Properties

        public IList<MenuItem> MenuItems
        {
            get { return Items; }
            set
            {
                foreach (MenuItem item in value)
                {
                    Items.Add(item);
                }
            }
        }

        public string Name { get; set; }

        public string ParentName { get; set; }

        public string Text { get; set; }

        public string ImagePath { get; set; }

        public bool IsEnabled
        {
            get { return isEnabled; }
            set { isEnabled = value; }
        }

        public bool IsCheckable
        {
            get { return isCheckable; }
            set { isCheckable = value; }
        }

        public bool IsChecked
        {
            get { return isChecked; }
            set { isChecked = value; }
        }

        public Grid MenuGrid { get; set; }

        public int Level
        {
            get { return level; }
            set { level = value; }
        }

        #endregion Properties

        #region Methods
        public override string ToString()
        {
            return this.Name;
        }
        #endregion Methods
    } 

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer Alura Cursos Online
Brazil Brazil

Comments and Discussions