Click here to Skip to main content
15,886,063 members
Articles / DevOps / Testing

Composite Application Reloaded

Rate me:
Please Sign up or sign in to vote.
4.88/5 (38 votes)
11 May 2011CPOL12 min read 117.8K   1.5K   95  
A much simpler composite application library.
//===================================================================================
// Microsoft patterns & practices
// Composite Application Guidance for Windows Presentation Foundation and Silverlight
//===================================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===================================================================================
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System;
using System.Windows.Controls;

namespace StockTraderRI.ChartControls
{
    public class ClipWedge : ContentControl
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
        static ClipWedge()
        {
            r = new Random();
        }

        public static void OnWedgeShapeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ClipWedge c = sender as ClipWedge;
            if(c!=null)
                c.InvalidateArrange();
        }

        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            Clip = GetClipGeometry(arrangeBounds);
            return base.ArrangeOverride(arrangeBounds);
        }

        public StreamGeometry GetClipGeometry(Size arrangeBounds)
        {
            StreamGeometry clip = new StreamGeometry();
            StreamGeometryContext clipGC = clip.Open();
            clipGC.BeginFigure(BeginFigurePoint, true, true);
            clipGC.LineTo(LineToPoint, false, true);
            Vector v = LineToPoint - BeginFigurePoint;
            RotateTransform rt = new RotateTransform(WedgeAngle, BeginFigurePoint.X, BeginFigurePoint.Y);
            bool isLargeArc = WedgeAngle >180.0;
            clipGC.ArcTo(rt.Transform(LineToPoint), new Size(v.Length, v.Length), WedgeAngle, isLargeArc, SweepDirection.Clockwise, false, true);
            clipGC.Close();
            return clip;
        }

        public double WedgeAngle
        {
            get { return (double)GetValue(WedgeAngleProperty); }
            set { SetValue(WedgeAngleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WedgeAngle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WedgeAngleProperty =
            DependencyProperty.Register("WedgeAngle", typeof(double), typeof(ClipWedge), new UIPropertyMetadata(0.0, new PropertyChangedCallback(OnWedgeShapeChanged)));


        public Point BeginFigurePoint
        {
            get { return (Point)GetValue(BeginFigurePointProperty); }
            set { SetValue(BeginFigurePointProperty, value); }
        }

        // Using a DependencyProperty as the backing store for BeginFigurePoint.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BeginFigurePointProperty =
            DependencyProperty.Register("BeginFigurePoint", typeof(Point), typeof(ClipWedge), new UIPropertyMetadata(new Point(), new PropertyChangedCallback(OnWedgeShapeChanged)));


        public Point LineToPoint
        {
            get { return (Point)GetValue(LineToPointProperty); }
            set { SetValue(LineToPointProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LineTo.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LineToPointProperty =
            DependencyProperty.Register("LineToPoint", typeof(Point), typeof(ClipWedge), new UIPropertyMetadata(new Point(), new PropertyChangedCallback(OnWedgeShapeChanged)));

        private static Random r;
    }
}

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
Software Developer (Senior) http://www.ansibleww.com.au
Australia Australia
The Australia born French man who went back to Australia later in life...
Finally got over life long (and mostly hopeless usually, yay!) chronic sicknesses.
Worked in Sydney, Brisbane, Darwin, Billinudgel, Darwin and Melbourne.

Comments and Discussions