|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AmazonService;
namespace Explorer3D
{
/// <summary>
/// The event args for the AmazonItem.ItemClickedEvent. These
/// RoutedEventArgs expose a single Details (Amazon Item)
/// which is used by the subscriber of this event to to launch
/// an instance of <see cref="FlowDocumentWindow">FlowDocumentWindow
/// </see> which will show all the contained AmazonItem fields in
/// a nice FlowDocument.
/// </summary>
public class AmazonItemRoutedEventArgs : RoutedEventArgs
{
#region properties
public Details AmazonDetail { get; private set; }
#endregion
#region Ctor
public AmazonItemRoutedEventArgs(RoutedEvent routedEvent, Details amazonDetail) : base(routedEvent)
{
this.AmazonDetail = amazonDetail;
}
#endregion
}
/// <summary>
/// This UserConrtrol respresents a single item that matched the current query to
/// Amazon. The user may click on this control, to launch an instance of <see
/// cref="FlowDocumentWindow">FlowDocumentWindow</see> which will show all the
/// contained AmazonItem fields in a nice FlowDocument. This control is also
/// used as the Material of <see cref="_3dTools.InteractiveVisual3D">
/// 3d Tools, 3d element that support 2d Visuals</see>
/// </summary>
public partial class AmazonItem : UserControl
{
#region Instance fields
public Details AmazonDetail { get; private set; }
#endregion
#region Routed Events
////the event handler delegate
public delegate void AmazonItemClickedEventHandler
(object sender, AmazonItemRoutedEventArgs e);
/// <summary>
/// FriendAddedEvent event, occurs when the user clicks the add button
/// </summary>
public static readonly RoutedEvent ItemClickedEvent = EventManager.RegisterRoutedEvent(
"ItemClickedEvent", RoutingStrategy.Bubble, typeof(AmazonItemClickedEventHandler),
typeof(AmazonItem));
/// <summary>
/// Expose the ItemClickedEvent to external sources
/// </summary>
public event AmazonItemClickedEventHandler ItemClicked
{
add { AddHandler(ItemClickedEvent, value); }
remove { RemoveHandler(ItemClickedEvent, value); }
}
#endregion
#region Ctors
public AmazonItem()
{
InitializeComponent();
}
public AmazonItem(Details amazonDetail)
{
InitializeComponent();
try
{
if (amazonDetail != null)
{
AmazonDetail = amazonDetail;
if (AmazonDetail.Authors != null)
lblAuthor.Content = "Author : " + getShortenedString(AmazonDetail.Authors[0]);
lblProductName.Content = "Product Name : " + getShortenedString(AmazonDetail.ProductName);
lblReleaseDate.Content = "Release Date : " + getShortenedString(AmazonDetail.ReleaseDate);
storedImg.OriginalFileUrl = AmazonDetail.ImageUrlLarge;
}
}
catch
{
}
}
#endregion
#region Private helpers
private string getShortenedString(string input)
{
if (input.Length > 30)
return input.Substring(0, 30) + "...";
else
return input;
}
private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (AmazonDetail != null)
{
RaiseEvent(new AmazonItemRoutedEventArgs(ItemClickedEvent, AmazonDetail));
}
}
#endregion
}
}
|
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.
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
Both of these at Sussex University UK.
Award(s)
I am lucky enough to have won a few awards for Zany Crazy code articles over the years
- Microsoft C# MVP 2016
- Codeproject MVP 2016
- Microsoft C# MVP 2015
- Codeproject MVP 2015
- Microsoft C# MVP 2014
- Codeproject MVP 2014
- Microsoft C# MVP 2013
- Codeproject MVP 2013
- Microsoft C# MVP 2012
- Codeproject MVP 2012
- Microsoft C# MVP 2011
- Codeproject MVP 2011
- Microsoft C# MVP 2010
- Codeproject MVP 2010
- Microsoft C# MVP 2009
- Codeproject MVP 2009
- Microsoft C# MVP 2008
- Codeproject MVP 2008
- And numerous codeproject awards which you can see over at my blog