After the employee list view is set up, you ll add an employee detail view. in Visual Basic .NET

Encoder QR-Code in Visual Basic .NET After the employee list view is set up, you ll add an employee detail view.

After the employee list view is set up, you ll add an employee detail view.
Encode QR Code In VB.NET
Using Barcode printer for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in Visual Studio .NET applications.
www.OnBarcode.com
Read QR Code In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
EMPLOYEE DETAIL VIEW
Printing Code 128 In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create Code128 image in VS .NET applications.
www.OnBarcode.com
Draw Barcode In VB.NET
Using Barcode generator for .NET framework Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
In the Views folder, add a new ChildWindow named EmployeeDetail.xaml. This will be a pop-up window used to edit a subset of the fields of the Employee object. This window, in the designer, looks like figure 16.2.
Painting Data Matrix 2d Barcode In VB.NET
Using Barcode maker for .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
www.OnBarcode.com
Printing Barcode In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
Figure 16.2 Designer view of the ChildWindow used to edit employee details
2D Barcode Maker In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create 2D image in VS .NET applications.
www.OnBarcode.com
RM4SCC Printer In VB.NET
Using Barcode drawer for VS .NET Control to generate, create RoyalMail4SCC image in VS .NET applications.
www.OnBarcode.com
Download from Wow! eBook <www.wowebook.com>
QR Code JIS X 0510 Decoder In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
QR Code ISO/IEC18004 Encoder In Java
Using Barcode printer for Java Control to generate, create QR image in Java applications.
www.OnBarcode.com
Project setup and traditional code-behind approach
Code-39 Encoder In Objective-C
Using Barcode drawer for iPad Control to generate, create Code39 image in iPad applications.
www.OnBarcode.com
Recognizing Denso QR Bar Code In VB.NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
After the button definitions in the EmployeeDetail ChildWindow XAML, add the XAML from listing 16.3.
Drawing 2D In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create 2D image in ASP.NET applications.
www.OnBarcode.com
Creating PDF-417 2d Barcode In Java
Using Barcode generation for Android Control to generate, create PDF417 image in Android applications.
www.OnBarcode.com
Listing 16.3 Employee detail ChildWindow controls additional XAML
UCC - 12 Maker In Objective-C
Using Barcode maker for iPad Control to generate, create Universal Product Code version A image in iPad applications.
www.OnBarcode.com
Encode DataMatrix In Java
Using Barcode printer for Java Control to generate, create Data Matrix ECC200 image in Java applications.
www.OnBarcode.com
<TextBlock Height="23" Margin="12,18,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="First Name"/> <TextBox Height="23" Width="140" Margin="127,14,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="FirstName" Text="{Binding Contact.FirstName, Mode=TwoWay}" /> <TextBlock Height="23" Margin="12,47,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Last Name" /> <TextBox Height="23" Width="140" Margin="127,43,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="LastName" Text="{Binding Contact.LastName, Mode=TwoWay}" /> <TextBlock Height="23" Margin="12,76,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Title"/> <TextBox Height="23" Width="239" Margin="127,72,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="TitleField" Text="{Binding Title, Mode=TwoWay}" /> <CheckBox x:Name="Salaried" Height="16" Margin="127,101,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Salaried" IsChecked="{Binding SalariedFlag, Mode=TwoWay}" /> <TextBlock Height="23" Margin="12,127,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Hire Date"/> <TextBox Height="23" Width="87" Margin="127,123,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="HireDate" Text="{Binding HireDate, Mode=TwoWay}" /> <TextBlock Height="23" Margin="12,156,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Vacation Hours"/> <TextBox Height="23" Width="33" Margin="127,152,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="VacationHours" Text="{Binding VacationHours, Mode=TwoWay}"/> <TextBlock Height="23" Margin="12,185,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Sick Leave Hours"/> <TextBox Height="23" Width="33" Margin="127,181,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="SickLeaveHours" Text="{Binding SickLeaveHours, Mode=TwoWay}"/>
Barcode Encoder In None
Using Barcode drawer for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
Decoding Barcode In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
TwoWay binding for all fields
Generate Barcode In Java
Using Barcode creation for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
Scanning PDF417 In VB.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Download from Wow! eBook <www.wowebook.com>
Structuring and testing with the MVVM/ViewModel pattern
You ll use this project for the remainder of the chapter. You may change a few binding statements later, but for the most part, the XAML will stay the same. With the UI in place, it s time to turn our attention to the code. As promised, we ll first look at a typical code-behind approach.
16.1.2 A typical code-behind solution
The first stop along the way to structuring your applications with the ViewModel pattern is to look at what, for most applications of any complexity, can be considered an antipattern: the heavy code-behind approach. Unfortunately, the tooling and information all help you fall into writing code this way. That s because it s easy for beginners to grasp, and it s perfectly acceptable for smaller applications. So far, you have XAML for two views and a service you can use to populate them. The next step is to put in some code to call the service and populate the DataGrid. Listing 16.4 shows the code-behind for the Employee List page.
Listing 16.4 Employee list code-behind
public partial class EmployeeList : Page { public EmployeeList() { InitializeComponent(); NavigationCacheMode = NavigationCacheMode.Enabled; } protected override void OnNavigatedTo(NavigationEventArgs e) { if (EmployeesGrid.ItemsSource == null) { LoadingProgress.Visibility = Visibility.Visible;
Cache this Page
var client = new EmployeeServiceClient(); client.GetEmployeesCompleted += (s, ea) => { LoadingProgress.Visibility = Visibility.Collapsed; EmployeesGrid.ItemsSource = ea.Result; }; client.GetEmployeesAsync(); } } }
Listing 16.4 includes enough code to load the DataGrid. When the page is navigated to, you first check to see whether the DataGrid already has data B. If it doesn t, you show the LoadingProgress overlay C and then call the service, loading the result into the DataGrid D. This check is done because the pages are cached (per the setting in the constructor), and you d rather not make extra service calls. When you run the application, it should look like figure 16.3.
Download from Wow! eBook <www.wowebook.com>
Project setup and traditional code-behind approach
Figure 16.3 The Employee List page shown with an item selected in the grid. Note that the scrollbar is scrolled to the right to get past the columns you don t need.
As you can see by the grid results, you haven t done anything to reduce the number of columns showing up nor to display the values from the nested class. This could be easily accomplished by manually defining columns in the DataGrid or by using a specialized purpose-built class as the return value from the service. Although you ll fix that when we talk about MVVM, it s not a deficiency with the code-behind pattern itself. Next, you need to add the code-behind for the Employee Detail window and then come back to this list page to fill out the rest of the code. The Employee Detail ChildWindow needs code to take in an Employee object and bind the UI. Listing 16.5 shows this code.
Copyright © OnBarcode.com . All rights reserved.