Click here to Skip to main content
15,897,334 members
Articles / Desktop Programming / WPF

A Silverlight Introduction for Line-of-Business Applications

Rate me:
Please Sign up or sign in to vote.
4.71/5 (15 votes)
30 Aug 2009CPOL18 min read 54.3K   660   56  
An introduction on Silverlight for developers of administrative applications. The article starts by explaining the basics of WPF and then delves deeper in the business-oriented aspects.
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;
using System.IO;
using System.Windows.Media.Imaging;
using System.Text;
using System.Xml.Serialization;

namespace CarSelector
{
    public partial class DetailPage : UserControl
    {
        public DetailPage()
        {
            InitializeComponent();
        }

        internal void SetItemId(int id)
        {
            this.DataContext = null;
            (Application.Current as App).Service.GetCarCompleted += new EventHandler<CarSelector.CarService.GetCarCompletedEventArgs>(Service_GetCarCompleted);
            (Application.Current as App).Service.GetCarAsync(id);
        }

        void Service_GetCarCompleted(object sender, CarSelector.CarService.GetCarCompletedEventArgs e)
        {
            this.DataContext = e.Result;

            BitmapImage img = new BitmapImage();
            using (MemoryStream stream = new MemoryStream(e.Result.Picture))
            {
                img.SetSource(stream);
            }
            pictureBox.Source = img;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            (Application.Current as App).NavigateToList();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            CarSelector.CarService.Car car = this.DataContext as CarSelector.CarService.Car;

            if (car != null)
            {
                //StringBuilder sb = new StringBuilder();
                //using (StringWriter writer = new StringWriter(sb))
                //{
                //    XmlSerializer serializer = new XmlSerializer(typeof(CarSelector.CarService.Car));
                //    serializer.Serialize(writer, car);
                //}

                //(Application.Current as App).Service.UpdateCarAsync(sb.ToString());
                (Application.Current as App).Service.UpdateCarAsync(car);
            }
        }
    }
}

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
CEO TRI-S bvba, Cogenius bvba
Belgium Belgium
I'm working since 1999 in an IT environment: started developing in PROGRESS 4GL, then VB6 and am working since 2003 with C#. I'm currently transitioning to HTML5, CSS3 and JavaScript for the front-end development.
I started my own company (TRI-S) in 2007 and co-founded another one (Cogenius) in 2012.
Besides being a Microsoft Certified Professional Developer (MCPD) I'm also a Microsoft Certified Trainer (MCT) and am teaching .NET and JavaScript courses.

Comments and Discussions