Designing and Developing Windows Applications Using Microsoft .NET Framework 4: Designing the Presentation Layer
- 12/17/2011
- Objective 2.1: Choose the Appropriate Windows Technology
- Objective 2.2: Design the UI Layout and Structure
- Objective 2.3: Design Application Workflow
- Objective 2.4: Design Data Presentation and Input
- Objective 2.5: Design Presentation Behavior
- Objective 2.6: Design for UI Responsiveness
- Objective 2.6: Design for UI Responsiveness
- Chapter Summary
- Answers
Answers
This section contains the answers to the Object Reviews and the Thought Experiments.
Objective 2.1: Review
Correct Answer: B
Incorrect: The WindowsFormsHost allows you to host a Windows Forms control in a WPF application.
Correct: The ElementHost allows you to host a WPF control in a Windows Forms application.
Incorrect: The Grid element is a container that hosts other controls in a WPF application, but it cannot be used independently in Windows Forms applications.
Incorrect: The Form class is the base class for Windows Forms application, but it cannot host WPF controls independently.
Correct Answer: D
Incorrect: Windows Forms lack the required responsiveness to styles for this application.
Incorrect: WPF does not have an inherent MaskedTextBox control.
Incorrect: Windows Forms lack the required responsiveness to styles, and added WPF controls would not be helpful in this instance.
Correct: A WPF application will be responsive to styles, but you can use the Windows Forms MaskedTextBox control for the specialized input.
Objective 2.1: Thought Experiment
For this application, WPF is the best choice for implementing the Presentation layer. While there are some globalization and localization concerns for which Windows Forms would offer a superior development experience, they are fairly minor, requiring no changes in the presentation language of the UI, and these concerns are outweighed by the WPF advantages in the use of Styles and multimedia presentation.
User responsiveness can be maintained by using the BackgroundWorker component to process the background tasks while the UI remains responsive. When the UI needs to be updated from the background thread, this can be done safely using this Dispatcher object.
Objective 2.2: Review
Correct Answer: C
Incorrect: It is not necessary to provide audio cues for all important information, and it is important to convey no information by sound alone.
Incorrect: An accessible application should supply support for standard system settings.
Correct: An accessible application should ensure compatibility with the high-contrast mode.
Incorrect: An accessible application should provide documented keyboard access to all important functionalities.
Correct Answer: D
Incorrect: Because these Brush objects need to be used in many different elements, defining them at the individual element level would require a great deal of redundancy.
Incorrect: Because these Brush objects need to be used in each window, defining them at the window level would be redundant.
Incorrect: Although defining these resources at the application level would enable use across the entire application, it would not facilitate reuse across multiple applications.
Correct: By defining your resources in a resource dictionary, you can share the file between applications, as well as import the resources contained therein at the window or application level as needed.
Objective 2.2: Thought Experiment
It’s a good start. However, they could simplify development and improve consistency by using styles instead.
Maybe. However, for accessibility, it’s better to use standard system settings for size, color, and font. When you use standard system settings, any changes the user makes to the operating system to better support accessibility needs will be reflected in the application. Since the organization is concerned about it, it should perform accessibility testing, as described in Objective 5.2, “Evaluate and Recommend a Test Strategy,” in Chapter 5, “Designing for Stability and Maintenance.”
Objective 2.3: Review
Correct Answer: C
Incorrect: The Page or PageFunction for the custom journal entry must implement IProvideCustomContent.
Incorrect: You must call NavigationService.AddBackEntry to create the custom back entry.
Correct: You do not need an instance of JournalEntry to create a custom back entry.
Incorrect: You must create a class that inherits from CustomContentState to store the state of the page.
Correct Answer: B
Incorrect: FragmentNavigation occurs after LoadCompleted, and NavigationProgress occurs after Navigated.
Correct: This is the correct order in which navigation events fire.
Incorrect: NavigationProgress occurs after Navigated.
Incorrect: FragmentNavigation occurs after LoadCompleted.
Objective 2.3: Thought Experiment
No, a WPF page-based application is the best choice. Page-based applications are perfect for completing straightforward, linear tasks such as data entry.
Yes. You can remove pages from the journal by calling NavigationService.RemoveBackEntry repeatedly.
Yes (though it might be confusing to the user). To accomplish this, call NavigationService.AddBackEntry and provide an instance of a class that derives from CustomContentState and contains the state information for the page that the user should return to when she clicks Back.
Objective 2.4: Review
Correct Answer: B
Incorrect: Although data type validation will validate that the input is an integer, it will not validate the allowed range of values correctly.
Correct: Range checking will validate both data type and range.
Incorrect: Lookup validation is not required because the expected data falls within a consistent range.
Incorrect: Complex validation is not required because the expected data falls within a consistent range.
Correct Answer: D
Incorrect: The <DataTemplate> tags must be enclosed in <ListBox.Item- Template> tags to set the data template to the ItemTemplate property.
Incorrect: The data template must be set to the ItemTemplate property, not the ItemsSource property.
Incorrect: The data template must be enclosed in <DataTemplate> tags.
Correct: The data template is set correctly.
Objective 2.4: Thought Experiment
Overall, the design is solid. However, it has one major flaw: all data validation occurs on the client. Client data validation is useful for improving the responsiveness of the application; however, for security and data integrity, you also must implement data validation on the server. This is particularly important because Lucerne plans to expose the web service to other clients, which might not implement proper data validation.
It might work, but it’s not a good UI design choice. First, it fails to indicate which element on a page failed to validate. Second, it provides poor accessibility because it would not be meaningful to users who could not distinguish the colors red and green.
Objective 2.5: Review
Correct Answer: C
Incorrect: A multi-trigger requires that all conditions be met before activating its Setters. In this case, Textbox1 is not focused.
Incorrect: A multi-trigger requires that all conditions be met before activating its Setters. In this case, the mouse is not over Textbox1.
Correct: A multi-trigger is active when all conditions defined in it are met.
Incorrect: A multi-trigger requires that all conditions be met before activating its Setters, and will only activate when all conditions are met.
Incorrect: When all the conditions are met, the multi-trigger activates.
Correct Answer: D
Incorrect: Although most drag-and-drop operations begin in the MouseDown event on the source control, it is not required that they begin there.
Incorrect: Although it is recommended that the DragEnter event handler be used to examine the data object and set the Effect property as appropriate, it is not required.
Incorrect: The DragLeave event is used to execute code when data is dragged out of a control, but it is not necessary for the drag-and-drop operation.
Correct: The DragDrop event is the only event that must be handled to complete a drag-and-drop operation.
Objective 2.5: Thought Experiment
There are many ways to initiate the animation. The simplest would be to use validation and validate that the file name ends in one of the acceptable image file extensions.
There are also many ways to implement the animation. However, an attached behavior would simplify adding the behavior to multiple buttons.
Not if it’s running in a partial trust environment, which most XBAP applications do. They either need to configure the application for full trust (which supports true drag-and-drop functionality) or they need to simulate drag-and-drop functionality in the partial trust environment.
Objective 2.6: Review
Correct Answers: A and B
Correct: RunWorkerAsync raises the DoWork event, which must be handled to run code on the background thread.
Correct: The DoWork event handler contains the code that will be run on the background thread.
Incorrect: Handling the ProgressChanged event is not required.
Incorrect: Setting WorkerSupportsCancellation to True is not required.
Correct Answers: A and C
Correct: The Dispatcher.BeginInvoke method will execute a method asynchronously and safely on the main thread.
Incorrect: Direct access of the UI from a background thread is not allowed.
Correct: Using the built-in mechanism of BackgroundWorker for reporting is the preferred way to report progress that can be expressed numerically.
Incorrect: Direct access of the UI from a background thread is not allowed.
Objective 2.6: Thought Experiment
Yes.
Yes, the sorting should occur on the client. Sorting by these values should happen quickly, even on lower-powered clients. In addition, because the application is connecting to public web services, the application might not have the ability to request the list to be sorted differently by the server.
Yes. They could lower the frame rate of the animations to reduce the performance impact.
Yes, the CLR Profiler is an excellent tool for identifying memory leaks, and it can be downloaded for free from Microsoft.