开发者

Where would the responsibility to handle this event be placed?

开发者_如何学运维

I have a NavigationBar.cs user control. I also have NavigationItem.cs user control.

Here's the code for both:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Uboldi.CustomUI
{
    public partial class NavigationBar : UserControl
    {
        public NavigationBar()
        {
            InitializeComponent();
        }

        public List<NavigationItem> NavigationItems { private get; set; }
        public NavigationItem SelectedItem { get; set; }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Uboldi.CustomUI
{
    public partial class NavigationItem : UserControl
    {
        public NavigationItem()
        {
            InitializeComponent();
        }

        private Image _picture = null;
        public Image Picture
        {
            get
            {
                return _picture;
            }
            set
            {
                _picture = value;
                ptbIcon.Image = _picture;
            }
        }

        private string _content = null;
        public string Content 
        {
            get
            {
                return _content;
            }
            set
            {
                _content = value;
                lblDisplayText.Text = _content;
            }
        }
    }
}

I only want a single NavigationItem in the navigationbar to be 'selected' at any given time.

When an item is selected a different color will be given to it.

My question is, where should I program this code? In the bar, or is it something a button should do and have the bar just invoke that SetYourSelfAsSelected() method?

Thanks.


I would implement this functionality in the NavigationBar for the following reason: Some other developer could use your NavigationItems in a different context where no active items are marked or marked any different. Or one wants to overload the NavigationBar to implement another behaviour for active items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜