Click here to Skip to main content
15,881,898 members
Articles / Programming Languages / C#

An Introduction to the Silverlight samples in the All-In-One Framework

Rate me:
Please Sign up or sign in to vote.
5.00/5 (26 votes)
12 Dec 2009Ms-PL5 min read 55.1K   2.2K   56  
This article introduces several Silverlight samples in the All-In-One Framework.
/****************************** Module Header ******************************\
* Module Name:	MyEllipse.xaml.cs
* Project:		CSSL3Animation
* Copyright (c) Microsoft Corporation.
* 
* This module shows how to write a UserControl that basically wraps EllipseGeometry
* to "expose" its Center property.
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* History:
* * 9/8/2009 05:00 PM Allen Chen Created
\***************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CSSL3Animation
{
    public delegate void EllipseCenterChangedEventHandler(DependencyObject sender, DependencyPropertyChangedEventArgs e);
 
    public partial class MyEllipse : UserControl
    {
        public static readonly DependencyProperty EllipseCenterProperty = 
            DependencyProperty.Register("EllipseCenter", typeof(Point), typeof(MyEllipse), new PropertyMetadata(new PropertyChangedCallback((obj,e)=>{MyHandler(obj,e);})));
        EllipseCenterChangedEventHandler _mydelegate;

        public event EllipseCenterChangedEventHandler EllipseCenterChanged
        {
            add 
            {
                if (_mydelegate == null) _mydelegate = value;
                else
                {
                    Delegate.Combine(_mydelegate, value);
                }
            }
            remove
            {
              
                Delegate.Remove(_mydelegate, value); 
            }
        }


        public Point EllipseCenter
        { 
            get { return (Point)GetValue(EllipseCenterProperty); }
            set 
            {
                SetValue(EllipseCenterProperty, value); 
            }
          
        }

        public MyEllipse()
        {
            
            InitializeComponent();
            EllipseCenter= this.MyAnimatedEllipseGeometry.Center;
        }

        /// <summary>
        /// This is a callback method that triggers OnEllipseCenterChanged method of
        /// the MyEllipse object whose EllipseCenter property got changed.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        static  void MyHandler(DependencyObject obj,DependencyPropertyChangedEventArgs e)
        {
            
          MyEllipse ellipse=obj as MyEllipse;
            if(ellipse!=null){
            ellipse.OnEllipseCenterChanged(obj,e);
            }
        }

        /// <summary>
        /// This method is triggered by the callback method of EllipseCenterProperty
        /// property. It updates the Center property of the EllipseGeometry object to
        /// update UI,then it fires EllipseCenterChanged event.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        void OnEllipseCenterChanged(DependencyObject obj,DependencyPropertyChangedEventArgs e)
        {
            MyEllipse ellipse = obj as MyEllipse;
            if (ellipse != null) {
                ellipse.MyAnimatedEllipseGeometry.Center = ellipse.EllipseCenter;
            }
            if(_mydelegate!=null)
                _mydelegate(obj, e);
        }
    }
}

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 Microsoft Public License (Ms-PL)


Written By
China China
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

Comments and Discussions