Click here to Skip to main content
15,886,035 members
Articles / Mobile Apps / Windows Phone 7

XAMLFinance – A Cross-platform WPF, Silverlight & WP7 Application

Rate me:
Please Sign up or sign in to vote.
4.94/5 (99 votes)
21 Sep 2011CPOL27 min read 216.7K   9.9K   251  
This article describes the development of XAML Finance, a cross-platform application which works on the desktop, using Windows Presentation Foundation (WPF), on the web, using Silverlight and on Windows Phone 7 (WP7).
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Windows.Data;

namespace System.Windows.Controls.DataVisualization
{
    /// <summary>
    /// Helper class which can extract the value from a source object using a binding path. It 
    /// creates a Binding object based on the path, and calls SetBinding to a temporary 
    /// FrameworkElement (base class) to extract the value.
    /// </summary>
    internal class BindingExtractor : FrameworkElement
    {
        #region public object Value
        /// <summary>
        /// Gets or sets a generic Value which will be the target of the binding.
        /// </summary>
        private object Value
        {
            get { return (object)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }

        /// <summary>
        /// Identifies the Value dependency property.
        /// </summary>
        private static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register(
                "Value",
                typeof(object),
                typeof(BindingExtractor),
                null);
        #endregion

        /// <summary>
        /// Returns the value of the given Binding when applied on the given object instance.
        /// It does that by making a copy of the binding, setting its source to be the object
        /// instance and the target to be the member Value property.
        /// </summary>
        /// <param name="instance">Object instance containing the property.</param>
        /// <param name="valueBinding">Binding to the property to be retrieved.</param>
        /// <returns>The value of the binding.</returns>
        public object RetrieveProperty(object instance, Binding valueBinding)
        {
            // We need to make a new instance each time because you can't change 
            // the Source of a Binding once it has been set.
            Binding binding = new Binding()
            {
                Converter = valueBinding.Converter,
                ConverterCulture = valueBinding.ConverterCulture,
                ConverterParameter = valueBinding.ConverterParameter,
                Mode = valueBinding.Mode,
                NotifyOnValidationError = valueBinding.NotifyOnValidationError,
                Path = valueBinding.Path,
                Source = instance,
                ValidatesOnExceptions = valueBinding.ValidatesOnExceptions
            };

            SetBinding(BindingExtractor.ValueProperty, binding);

            // Now this dependency property has been updated.
            return Value;
        }
    }
}

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
Architect Scott Logic
United Kingdom United Kingdom
I am CTO at ShinobiControls, a team of iOS developers who are carefully crafting iOS charts, grids and controls for making your applications awesome.

I am a Technical Architect for Visiblox which have developed the world's fastest WPF / Silverlight and WP7 charts.

I am also a Technical Evangelist at Scott Logic, a provider of bespoke financial software and consultancy for the retail and investment banking, stockbroking, asset management and hedge fund communities.

Visit my blog - Colin Eberhardt's Adventures in .NET.

Follow me on Twitter - @ColinEberhardt

-

Comments and Discussions