Click here to Skip to main content
15,896,269 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 118.5K   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;
using System.Windows.Data;
using StockTraderRI.Infrastructure;
using StockTraderRI.Modules.Position.Models;

namespace StockTraderRI.Modules.Position.Orders
{
	public partial class OrderCompositePresentationModel
	{
		partial void SetTransactionInfo(TransactionInfo transactionInfo)
		{
			//This instance of TransactionInfo acts as a "shared model" between this view and the order details view.
			//The scenario says that these 2 views are decoupled, so they don't share the presentation model, they are only tied
			//with this TransactionInfo
			this.orderDetailsPresentationModel.TransactionInfo = transactionInfo;

			//Bind the CompositeOrderView header to a string representation of the TransactionInfo shared instance (we expect the details presenter to modify it from user interaction).
			MultiBinding binding = new MultiBinding();
			binding.Bindings.Add(new Binding("TransactionType") { Source = transactionInfo });
			binding.Bindings.Add(new Binding("TickerSymbol") { Source = transactionInfo });
			binding.Converter = new OrderHeaderConverter();
			BindingOperations.SetBinding(this, HeaderInfoProperty, binding);
		}

		public string HeaderInfo
		{
			get { return (string)GetValue(HeaderInfoProperty); }
			set { SetValue(HeaderInfoProperty, value); }
		}

		private class OrderHeaderConverter : IMultiValueConverter
		{
			/// <summary>
			/// Converts a <see cref="TransactionType"/> and a ticker symbol to a header that can be placed on the TabItem header
			/// </summary>
			/// <param name="values">values[0] should be of type <see cref="TransactionType"/>. values[1] should be a string with the ticker symbol</param>
			/// <param name="targetType"></param>
			/// <param name="parameter"></param>
			/// <param name="culture"></param>
			/// <returns>Returns a human readable string with the transaction type and ticker symbol</returns>
			public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
			{
				return values[0].ToString() + " " + values[1].ToString();
			}

			public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
			{
				throw new NotImplementedException();
			}
		}
	}
}

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