delegate andevent mechanisms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?R2VyaGFyZA==?=

    delegate andevent mechanisms

    Can you please give me an example showing best practices using the delegate
    and event mechanisms built into the .Net framework so that changes to a
    property would notify any interested listeners? Thanks.
  • Peter Duniho

    #2
    Re: delegate andevent mechanisms

    On Wed, 19 Nov 2008 23:07:00 -0800, Gerhard <Gerhard@commun ity.nospam>
    wrote:
    Can you please give me an example showing best practices using the
    delegate
    and event mechanisms built into the .Net framework so that changes to a
    property would notify any interested listeners? Thanks.
    A couple of quick MSDN searches turned up these articles:



    Learn about how the Windows Forms Designer interacts with control and form properties during design-time.


    Comment

    • Zhi-Xin Ye [MSFT]

      #3
      RE: delegate andevent mechanisms

      Hello Gerhard,

      Thank you for using Microsoft Managed Newsgroup Service, I'm Zhi-Xin Ye,
      it's my pleasure to work with you on this issue.

      To notify clients that a property value has changed, you can implement the
      INotifyProperty Changed interface on your classes.

      For example,

      Comment

      • Zhi-Xin Ye [MSFT]

        #4
        RE: delegate andevent mechanisms

        Hello Gerhard,

        Thank you for using Microsoft Managed Newsgroup Service, I'm Zhi-Xin Ye,
        it's my pleasure to work with you on this issue.

        To notify clients that a property value has changed, you can implement the
        INotifyProperty Changed interface on your classes.

        For example,


        ============== Code Sample =============== ==

        class Customer : INotifyProperty Changed
        {
        private int id;
        private string name;

        public Customer(int id, string name)
        {
        this.id = id;
        this.name = name;
        }

        public int ID
        {
        get { return id; }
        set
        {
        this.id = value;
        NotifyPropertyC hanged("ID");
        }
        }

        public string Name
        {
        get { return name; }
        set
        {
        this.name = value;
        NotifyPropertyC hanged("Name");
        }
        }

        #region INotifyProperty Changed Members

        public event PropertyChanged EventHandler PropertyChanged ;

        private void NotifyPropertyC hanged(String info)
        {
        if (PropertyChange d != null)
        {
        PropertyChanged (this, new PropertyChanged EventArgs(info) );
        }
        }

        #endregion
        }

        public partial class Form1: Form
        {
        public Form1()
        {
        InitializeCompo nent();

        c.PropertyChang ed += new
        PropertyChanged EventHandler(c_ PropertyChanged );
        }

        Customer c = new Customer(1, "aa");

        private void button1_Click(o bject sender, EventArgs e)
        {
        c.Name = "ff";
        }

        private void button2_Click(o bject sender, EventArgs e)
        {
        c.ID = 2;
        }

        void c_PropertyChang ed(object sender, PropertyChanged EventArgs e)
        {
        MessageBox.Show (e.PropertyName + " Changed!");
        }
        }

        =============== ===============

        For more information about the INotifyProperty Changed Interface, you can
        refer to this document:

        Gain technical skills through documentation and training, earn certifications and connect with the community

        ychanged.aspx

        If anything is unclear, please feel free to let me know.

        Have a nice day!

        Best Regards,
        Zhi-Xin Ye
        Microsoft Managed Newsgroup Support Team

        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/en-us/subs...#notifications.

        Note: MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 2 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions. Issues of this
        nature are best handled working with a dedicated Microsoft Support Engineer
        by contacting Microsoft Customer Support Services (CSS) at

        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.


        Comment

        Working...