{"id":593,"date":"2011-04-18T02:25:00","date_gmt":"2011-04-18T02:25:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2011\/04\/18\/silverlight-4-firestarter-series-1-how-to-migrate-a-visual-basic-windows-form-application-to-silverlight\/"},"modified":"2024-07-05T12:40:03","modified_gmt":"2024-07-05T19:40:03","slug":"silverlight-4-firestarter-series-1-how-to-migrate-a-visual-basic-windows-form-application-to-silverlight","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/silverlight-4-firestarter-series-1-how-to-migrate-a-visual-basic-windows-form-application-to-silverlight\/","title":{"rendered":"Silverlight 4 Firestarter Series #1: How to migrate a Visual Basic Windows Form Application to Silverlight"},"content":{"rendered":"<p><span style=\"font-size: small\">In this walkthrough, I will demonstrate how to convert an existing Windows Forms application that consumes data from a Windows Communication Foundation (WCF) service to Silverlight. Also in the process of conversion we will ensure that the existing functionality is preserved. <\/span><\/p>\n<p><span style=\"font-size: small\">Here are some topics that we will cover: <\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\">How to use the Visual Studio 2010 Silverlight Designer<\/span><\/li>\n<li><span style=\"font-size: small\">XAML and Silverlight control concepts<\/span><\/li>\n<li><span style=\"font-size: small\">How WCF services can be integrated into Silverlight applications<\/span><\/li>\n<li><span style=\"font-size: small\">Silverlight data binding techniques<\/span><\/li>\n<li><span style=\"font-size: small\">How to make asynchronous calls to services<\/span><\/li>\n<li><span style=\"font-size: small\">How to work with cross domain services<\/span><\/li>\n<li><span style=\"font-size: small\">Similarities between Windows Forms and Silverlight applications<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small\"><i>Before you begin you need to <\/i><i>download the <\/i><\/span><a href=\"http:\/\/www.silverlight.net\/news\/events\/firestarter-labs\/\"><i><span style=\"font-size: small\">offline kit<\/span><\/i><\/a><i><span style=\"font-size: small\"> from the Firestarter Labs, to use the existing applications.<\/span><\/i><\/p>\n<p><span style=\"font-size: small\">You can migrate the Windows Forms application to Silverlight in three simple steps as follows:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Explore the Windows Forms application <\/span><\/li>\n<li><span style=\"font-size: small\">Migrate the Windows Forms application to Silverlight<\/span><\/li>\n<li><span style=\"font-size: small\">Call a WCF Service and Bind data<\/span><\/li>\n<\/ol>\n<h3>Step 1: Explore the Windows Forms Application<\/h3>\n<p><span style=\"font-size: small\">Let&rsquo;s take a look at the code that we&rsquo;ll be migrating. To start exploring the Visual Basic Windows Forms application, follow the following steps:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Open Visual Studio 2010, and from the File menu and select Open Project. The Open Project dialog box is displayed. <\/span><\/li>\n<li><span style=\"font-size: small\">Open the following Visual Studio Solution file from the downloaded offline kit: <br \/>&ldquo;FirestarterLabs\u00001 &#8211; WinFormsSourceStarting PointVBCustomerViewer.sln&rdquo;<\/span><\/li>\n<li><span style=\"font-size: small\">The following projects are available in the application: <\/span>\n<ul>\n<li><span style=\"font-size: small\">CustomerService.Model &ndash; This project contains the entities and data repository classes that are used to access the AdventureWorks LT database.<\/span><\/li>\n<li><span style=\"font-size: small\">CustomersService &ndash; This project is a WCF service application that displays the entities to various applications.<\/span><\/li>\n<li><span style=\"font-size: small\">CustomerViewer &ndash; This is a Windows Forms project that takes data from a WCF service.<\/span><\/li>\n<li><span style=\"font-size: small\">CustomerViewer.Web &ndash; This is an ASP.NET Web Forms project that uses jQuery to make RESTful calls to a WCF service<br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/6378.Solution20Explorer.gif\" border=\"0\" \/><\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-size: small\">In Solution Explorer, right-click CustomerService.svc in the CustomersService project.<\/span><\/li>\n<li><span style=\"font-size: small\">From the popup menu select View in Browser. This will start a local WCF server and show a test page.<\/span><\/li>\n<li><span style=\"font-size: small\">Go back to Visual Studio application.<\/span><\/li>\n<li><span style=\"font-size: small\">In Solution Explorer, right-click the CustomerViewer project.<\/span><\/li>\n<li><span style=\"font-size: small\">From the popup menu select Set as StartUp Project.<\/span><\/li>\n<li><span style=\"font-size: small\">Press F5 to run the application. The first time the application runs there will be short delay before data is loaded.<\/span><\/li>\n<li><span style=\"font-size: small\">Select a customer from the drop-down list. The details of the customer are displayed in the form, allowing the data to be updated or deleted.<\/span><\/li>\n<li><span style=\"font-size: small\">Go back to Visual Studio application.<\/span><\/li>\n<li><span style=\"font-size: small\">In Solution Explorer, open the CustomerForm.vb page and from the popup menu select View Code. Review the code and note the following: <\/span>\n<ul>\n<li><span style=\"font-size: small\">A WCF service proxy is used to call a service that supplies customer data<\/span><\/li>\n<li><span style=\"font-size: small\">Control data bindings are defined in the SetBindings method<\/span><\/li>\n<li><span style=\"font-size: small\">Customer data can be updated and deleted through interactions with the WCF service<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-size: small\">To see the Entity Framework 4 model, in Solution Explorer, double-click the AdventureWorksLT.edmx file in the CustomerService.Model project. <br \/><i>Note: The entity model contains several entities including Customer which is used by the Windows Forms application. The DataSets are not used in the application because the data will be exposed through a Web Service and consumed by different types of clients. This project contains strongly typed objects that work well in a Silverlight application where the DataSet class and related classes such as DataTable aren&#8217;t supported. <\/i><\/span><\/li>\n<li><span style=\"font-size: small\">From the Repository folder, open the CustomerRepository.vbpage and review the code that interacts with the entity model. The RepositoryBase class is responsible for all communication with Entity Framework and acts as a reusable repository layer in the application.<\/span><\/li>\n<li><span style=\"font-size: small\">Open the ICustomerService.vb page. The methods in the page are used to load the customer objects and handle the update and delete operations. <br \/><i>Note: The Windows Forms project currently uses a WCF service proxy object to communicate with the different service operations. The Silverlight project will need to call the same service. These service calls are forwarded to the CustomerRepository class. The WCF services work well in environments where data must be exposed to different types of clients without requiring a specific technology or framework. This application uses WCF services to promote data re use, allow different types of clients to consume data, and provide a standards compliant way to access the data.<\/i><\/span><\/li>\n<\/ol>\n<h3>Step 2: Migrate the Windows Forms Application to Silverlight<\/h3>\n<p><span style=\"font-size: small\">Now let&rsquo;s migrate the application to Silverlight. We&#8217;ll create a new Silverlight project, work with XAML, create a WCF service proxy to interact with the service, and design a user interface that mirrors the existing Windows Forms user interface.<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">To add a new Silverlight Application, right-click the application name and add a new project. The Add New Project dialog box is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">Browse to the Silverlight node and select the Silverlight Application template.<\/span><\/li>\n<li><span style=\"font-size: small\">Enter the name for the project as SilverlightCustomerViewer and click OK. The New Silverlight Application dialog box is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">Select &lt;New Web Project&gt; from the drop-down list options and confirm that the New Web project name is displayed as SilverlightCustomerViewer.Web. This project will be used to host the Silverlight application in a web page. <\/span><\/li>\n<li><span style=\"font-size: small\">Click OK to proceed. The MainPage.xaml page of the SilverlightCustomerViewer project is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">Replace the &lt;UserControl&gt; tag with the following code: \n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 94px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">UserControl<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Class<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;SilverlightCustomerViewer.MainPage&#8221;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"><span>&nbsp;<\/span>xmlns<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&#8221;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">xmlns<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&#8221;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">xmlns<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">d<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&#8243;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"><span>&nbsp;<\/span>xmlns<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">mc<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&#8243;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">mc<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Ignorable<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;d&#8221;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">d<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">DesignHeight<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;545&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> d<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">DesignWidth<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;550&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;545&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;550&#8243;&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Grid<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Name<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;LayoutRoot&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Background<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;White&#8221;&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;\/<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Grid<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;\/<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">UserControl<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><\/p>\n<\/div>\n<p><i>Note: The d:DesignHeight and d:DesignWidth attributes control the size of the design surface in the design mode. However, they don&#8217;t have any effect at runtime. The Height and Width attributes constrain the size of the Silverlight screen at runtime. If you don&#8217;t define the Height and Width attributes, Silverlight will automatically fill the entire area of its container.<s><\/s><\/i><\/span><\/li>\n<li><span style=\"font-size: small\">From the toolbox, drag and drop 9 TextBlock controls, 1 ComboBox control, 5 TextBox controls and 2 Button controls to the designer surface and arrange them as the following: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/5444.UI1_.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">Change the Text property of each TextBlock control such that it matches the user interface as shown above.<\/span><\/li>\n<li><span style=\"font-size: small\">Set the Content property of the first Button control to &ldquo;Update&rdquo; and the Content property of the second Button Control to &ldquo;Delete&rdquo;.<\/span><\/li>\n<li><span style=\"font-size: small\">Select the ComboBox control, and change the name of the control to a value of CustomersComboBox as shown in the following image: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/2783.Properties1.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">Change the DisplayMemberPath property of the ComboBox control to a value of FullName. <br \/><i>Note: The DisplayMemberPath is used to define the property that will be displayed is the ComboBox when it binds to a collection of Customer objects.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">Change the names of the update and delete buttons in the interface to &ldquo;Update&rdquo; and &ldquo;Delete&rdquo; respectively using the Properties window.<\/span><\/li>\n<li><span style=\"font-size: small\">To simulate an HTML frameset tag, from the toolbox drag and drop a Rectangle control to the designer surface.<\/span><\/li>\n<li><span style=\"font-size: small\">Right-click the Rectangle control, and from the popup menu select Order, and then select Send to Back.<\/span><\/li>\n<li><span style=\"font-size: small\">Resize and arrange the Rectangle control as shown in the following figure: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/3056.UI2_.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">From the toolbox, drag and drop a Border control to the design surface.<br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/7651.UI3_.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">Select the Border control and change its Background property to &ldquo;White&rdquo; and its BorderBrush property to &ldquo;White&rdquo;. <\/span><\/li>\n<li><span style=\"font-size: small\">From the Toolbox, drag and drop a TextBlock control into the Border control.<\/span><\/li>\n<li><span style=\"font-size: small\">Select the TextBlock control and change the Text property to a value of Customer Details. <\/span><\/li>\n<li><span style=\"font-size: small\">Right-click the Customer Details TextBlock and from the popup menu select Reset Layout, and then select Size.<\/span><\/li>\n<li><span style=\"font-size: small\">The user interface should look like the following: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/0207.UI4_.gif\" border=\"0\" \/><\/span><\/li>\n<\/ol>\n<h3>Step 3: Call a WCF Service and Bind Data<\/h3>\n<p><span style=\"font-size: small\">Now let&rsquo;s create a WCF service proxy that can be used to call an existing WCF service. You&#8217;ll also use a clientaccesspolicy.xml file to handle cross domain issues and bind data to controls.<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Right-click on the SilverlightCustomerViewer project and then select Add Service Reference. Add Service Reference dialog box is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">Click Discover to browse and locate the WCF services. <\/span><\/li>\n<li><span style=\"font-size: small\">To expand the CustomerService.svc service, click on the icon next to CustomerService.svc service. Drill down to browse to the ICustomerService contract. Click the contract name and ensure that it has several service operations available.<\/span><\/li>\n<li><span style=\"font-size: small\">Enter the namespace as CustomerService.Proxies.<\/span><\/li>\n<li><span style=\"font-size: small\">To create the WCF service proxy, click OK.<\/span><\/li>\n<li><span style=\"font-size: small\">Add a new Customer class to the SilverlightCustomerViewer project.<\/span><\/li>\n<li><span style=\"font-size: small\">Add the following namespace of the new class:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.84%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 26px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Namespace<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> CustomerService.Proxies<\/span><\/p>\n<\/div>\n<p><i>Note: This namespace is added so as to match the namespace of the new class with that of the namespace generated by the WCF proxy.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">To display the FullName property in the ComboBox control, add the following code in the Customer class:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.46%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 94px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Partial<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Public<\/span> <span style=\"color: blue\">Class<\/span> <span style=\"color: #2b91af\">Customer<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Public<\/span> <span style=\"color: blue\">ReadOnly<\/span> <span style=\"color: blue\">Property<\/span> FullName() <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Get<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Return<\/span> FirstName &amp; <span style=\"color: #a31515\">&#8221; &#8220;<\/span> &amp; LastName<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">Get<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">Property<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Class<\/span><\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">To import the proxy namespace, open the MainPage.xaml.vb page and add the following code: \n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 27px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\"><span style=\"font-family: 'Courier New';color: blue;font-size: 9pt\"><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span style=\"color: #000000\"> CustomerService.Proxies<\/span><\/span><\/p>\n<p><\/span><\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">To hook the Loaded event to an event handler, add the following code within the constructor:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 27px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">AddHandler<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> Loaded, <span style=\"color: blue\">AddressOf<\/span> MainPage_Loaded<\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">To use the WSF service proxy and make an asynchronous data request, add a MainPage_Loaded method with the following code: \n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.37%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 82px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> MainPage_Loaded(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">RoutedEventArgs<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> proxy = <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">CustomerServiceClient<\/span>()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">AddHandler<\/span> proxy.GetCustomersCompleted, <span style=\"color: blue\">AddressOf<\/span> proxy_GetCustomersCompleted<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>proxy.GetCustomersAsync()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">Add the following method and associated code to handle the asynchronous callback, which will be made when the data from the WCF service is returned to the Silverlight application:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 55px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> proxy_GetCustomersCompleted(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">GetCustomersCompletedEventArgs<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>CustomersComboBox.ItemsSource = e.Result<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<\/div>\n<p><i>Note: Once the WCF service proxy returns data it can be accessed through the GetCustomersCompletedEventArgs object&#8217;s Result property which is typed as an ObservableCollection of Customer. This collection is assigned to the ItemsSource property of the ComboBox.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">Open the MainPage.xaml page.<\/span><\/li>\n<li><span style=\"font-size: small\">Select the TextBlock control next to Customer ID and select Properties from the menu.<\/span><\/li>\n<li><span style=\"font-size: small\">Remove the text from the Text property and click on the click the icon next to the property and from the popup menu select Apply Data Binding. The Data Binding property dialog box is displayed. <\/span><\/li>\n<li><span style=\"font-size: small\">Click ElementName and then select CustomersComboBox to set the ComboBox as the data binding source as shown in the following figure: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/5810.Source.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">Click Path area and select SelectedItem from the properties as shown in the following figure: <br \/><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/1184.Path_.gif\" border=\"0\" \/><\/span><\/li>\n<li><span style=\"font-size: small\">In the XAML editor, locate the TextBlock control modified in the previous step and change the Text property value to the following:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.93%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 29px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"line-height: 115%;font-family: 'Courier New';color: red;font-size: 8.5pt\">Text<\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox, <\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: red;font-size: 8.5pt\">Path<\/span><span style=\"line-height: 115%;font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.CustomerID }&rdquo;<\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">Similarly add data bindings to all of the TextBox controls in the designer surface. For this you&#8217;ll have to modify the Text property of each control within the XAML as done in the previous step to specify the appropriate property of the SelectedItem to bind to. To set the properties for each TextBox, add the following XAML code: \n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 94px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">TextBox<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;23&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> HorizontalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Left&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Margin<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;158,225,0,0&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> VerticalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Top&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;219&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Path<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.FirstName,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Mode<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=TwoWay}&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> DataContext<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">}&#8221; \/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">TextBox<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;23&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> HorizontalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Left&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Margin<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;158,270,0,0&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> VerticalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Top&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;219&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Path<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.LastName,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Mode<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=TwoWay}&#8221; \/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">TextBox<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;23&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> HorizontalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Left&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Margin<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;158,316,0,0&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> VerticalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Top&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;219&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Path<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.CompanyName,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Mode<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=TwoWay}&#8221;\/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">TextBox<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;23&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> HorizontalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Left&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Margin<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;158,366,0,0&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> VerticalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Top&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;219&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Path<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.EmailAddress,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Mode<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=TwoWay}&#8221; \/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">TextBox<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Height<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;23&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> HorizontalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Left&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Margin<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;158,416,0,0&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> VerticalAlignment<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;Top&#8221;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Width<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;219&#8243;<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=&#8221;{<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">Binding<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> ElementName<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=CustomersComboBox,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Path<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=SelectedItem.Phone,<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Mode<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=TwoWay}&#8221; \/&gt;<\/span><\/p>\n<\/div>\n<p><i>Note: Each TextBox binding has Mode=TwoWay added to it. This allows any change made to a TextBox control to be propagated back to the bound property automatically. <\/i><\/span><\/li>\n<li><span style=\"font-size: small\">Right-click the SilverlightCustomerViewer.Web project and select Set as StartUp Project.<\/span><\/li>\n<li><span style=\"font-size: small\">To set the html page in the project as the startup page, right-click the appropriate file and select Set As Start Page.<\/span><\/li>\n<li><span style=\"font-size: small\">Press F5 to compile and run the application. <br \/><i>Note: An error will occur once the Silverlight application loads. This is due to a cross domain call that is being made from Silverlight to the WCF service. This service uses a different port than the Silverlight host Web project, which causes this cross domain exception to be thrown.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">To fix this cross domain issue, rename the existing clientaccesspolicy.exclude file in the CustomersService project to clientaccesspolicy.xml. <\/span><\/li>\n<li><span style=\"font-size: small\">Press F5 to compile and run the application again. Now the data loads in the ComboBox control.<\/span><\/li>\n<li><span style=\"font-size: small\">Select a customer from the drop-down list. The data from it is bound to the appropriate TextBlock and TextBox controls.<\/span><\/li>\n<li><span style=\"font-size: small\">Go back to Visual Studio application to add the Click event handlers.<\/span><\/li>\n<li><span style=\"font-size: small\">To add the event handler for the Update button, add the following code in the Update button&#8217;s click event handler:\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 94px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> proxy = <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">CustomerServiceClient<\/span>()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> cust = <span style=\"color: blue\">TryCast<\/span>(CustomersComboBox.SelectedItem, <span style=\"color: #2b91af\">Customer<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">cust.ChangeTracker.State = <span style=\"color: #2b91af\">ObjectState<\/span>.Modified<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">AddHandler<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> proxy.SaveCustomerCompleted, <span style=\"color: blue\">Sub<\/span>(s, args)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Dim<\/span> opStatus = args.Result<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Dim<\/span> msg <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span> = <span style=\"color: blue\">If<\/span>(opStatus.Status, <span style=\"color: #a31515\">&#8220;Customer Updated!&#8221;<\/span>, <span style=\"color: #a31515\">&#8220;Unable to update Customer: &#8220;<\/span> &amp; opStatus.Message)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">MessageBox<\/span>.Show(msg)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">proxy.SaveCustomerAsync(cust)<\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">To add the event handler for the Delete button, add the following code in the Delete button&#8217;s click event handler: \n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 94.8%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 94px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> proxy = <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">CustomerServiceClient<\/span>()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> cust = <span style=\"color: blue\">TryCast<\/span>(CustomersComboBox.SelectedItem, <span style=\"color: #2b91af\">Customer<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">cust.ChangeTracker.State = <span style=\"color: #2b91af\">ObjectState<\/span>.Deleted<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">AddHandler<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> proxy.SaveCustomerCompleted, <span style=\"color: blue\">Sub<\/span>(s, args)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Dim<\/span> opStatus <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">OperationStatus<\/span> = args.Result<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">If<\/span> opStatus.Status <span style=\"color: blue\">Then<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">CType<\/span>(CustomersComboBox.ItemsSource, <span style=\"color: #2b91af\">ObservableCollection<\/span>(<span style=\"color: blue\">Of<\/span> <span style=\"color: #2b91af\">Customer<\/span>)).Remove(cust)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">MessageBox<\/span>.Show(<span style=\"color: #a31515\">&#8220;Customer deleted!&#8221;<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Else<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">MessageBox<\/span>.Show(<span style=\"color: #a31515\">&#8220;Unable to delete Customer: &#8220;<\/span> &amp; opStatus.Message)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">If<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">proxy.SaveCustomerAsync(cust)<\/span><\/p>\n<\/div>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">Run the application and test the update and delete functionality.<\/span><\/li>\n<\/ol>\n<h3>Summary<\/h3>\n<p><span style=\"font-size: small\">Thus, in this walkthrough you have examined an existing Windows Forms application and supporting data access and service layers. You have now successfully migrated the existing functionality from the Windows Forms application to Silverlight. <\/span><\/p>\n<p><span style=\"font-size: small\">You can find the full source code for the application <\/span><a href=\"http:\/\/www.silverlight.net\/learn\/tutorials\/silverlight-4\/migrating-a-windows-forms-application-to-silverlight\/\"><span style=\"font-size: small\">here<\/span><\/a><span style=\"font-size: small\">. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this walkthrough, I will demonstrate how to convert an existing Windows Forms application that consumes data from a Windows Communication Foundation (WCF) service to Silverlight. Also in the process of conversion we will ensure that the existing functionality is preserved. Here are some topics that we will cover: How to use the Visual Studio [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[195],"tags":[137,138,167,177],"class_list":["post-593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-basic","tag-silverlight","tag-silverlight-4-firestarter","tag-vb2010","tag-wcf"],"acf":[],"blog_post_summary":"<p>In this walkthrough, I will demonstrate how to convert an existing Windows Forms application that consumes data from a Windows Communication Foundation (WCF) service to Silverlight. Also in the process of conversion we will ensure that the existing functionality is preserved. Here are some topics that we will cover: How to use the Visual Studio [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=593"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/593\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}