Designing and Developing Windows Applications Using Microsoft .NET Framework 4: Designing the Presentation Layer

  • 12/17/2011

Answers

This section contains the answers to the Object Reviews and the Thought Experiments.

Objective 2.1: Review

  1. Correct Answer: B

    1. Incorrect: The WindowsFormsHost allows you to host a Windows Forms control in a WPF application.

    2. Correct: The ElementHost allows you to host a WPF control in a Windows Forms application.

    3. 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.

    4. Incorrect: The Form class is the base class for Windows Forms application, but it cannot host WPF controls independently.

  2. Correct Answer: D

    1. Incorrect: Windows Forms lack the required responsiveness to styles for this application.

    2. Incorrect: WPF does not have an inherent MaskedTextBox control.

    3. Incorrect: Windows Forms lack the required responsiveness to styles, and added WPF controls would not be helpful in this instance.

    4. 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

  1. 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.

  2. 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

  1. Correct Answer: C

    1. Incorrect: It is not necessary to provide audio cues for all important information, and it is important to convey no information by sound alone.

    2. Incorrect: An accessible application should supply support for standard system settings.

    3. Correct: An accessible application should ensure compatibility with the high-contrast mode.

    4. Incorrect: An accessible application should provide documented keyboard access to all important functionalities.

  2. Correct Answer: D

    1. 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.

    2. Incorrect: Because these Brush objects need to be used in each window, defining them at the window level would be redundant.

    3. Incorrect: Although defining these resources at the application level would enable use across the entire application, it would not facilitate reuse across multiple applications.

    4. 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

  1. It’s a good start. However, they could simplify development and improve consistency by using styles instead.

  2. 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

  1. Correct Answer: C

    1. Incorrect: The Page or PageFunction for the custom journal entry must implement IProvideCustomContent.

    2. Incorrect: You must call NavigationService.AddBackEntry to create the custom back entry.

    3. Correct: You do not need an instance of JournalEntry to create a custom back entry.

    4. Incorrect: You must create a class that inherits from CustomContentState to store the state of the page.

  2. Correct Answer: B

    1. Incorrect: FragmentNavigation occurs after LoadCompleted, and NavigationProgress occurs after Navigated.

    2. Correct: This is the correct order in which navigation events fire.

    3. Incorrect: NavigationProgress occurs after Navigated.

    4. Incorrect: FragmentNavigation occurs after LoadCompleted.

Objective 2.3: Thought Experiment

  1. No, a WPF page-based application is the best choice. Page-based applications are perfect for completing straightforward, linear tasks such as data entry.

  2. Yes. You can remove pages from the journal by calling NavigationService.RemoveBackEntry repeatedly.

  3. 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

  1. Correct Answer: B

    1. Incorrect: Although data type validation will validate that the input is an integer, it will not validate the allowed range of values correctly.

    2. Correct: Range checking will validate both data type and range.

    3. Incorrect: Lookup validation is not required because the expected data falls within a consistent range.

    4. Incorrect: Complex validation is not required because the expected data falls within a consistent range.

  2. Correct Answer: D

    1. Incorrect: The <DataTemplate> tags must be enclosed in <ListBox.Item- Template> tags to set the data template to the ItemTemplate property.

    2. Incorrect: The data template must be set to the ItemTemplate property, not the ItemsSource property.

    3. Incorrect: The data template must be enclosed in <DataTemplate> tags.

    4. Correct: The data template is set correctly.

Objective 2.4: Thought Experiment

  1. 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.

  2. 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

  1. Correct Answer: C

    1. Incorrect: A multi-trigger requires that all conditions be met before activating its Setters. In this case, Textbox1 is not focused.

    2. Incorrect: A multi-trigger requires that all conditions be met before activating its Setters. In this case, the mouse is not over Textbox1.

    3. Correct: A multi-trigger is active when all conditions defined in it are met.

    4. Incorrect: A multi-trigger requires that all conditions be met before activating its Setters, and will only activate when all conditions are met.

    5. Incorrect: When all the conditions are met, the multi-trigger activates.

  2. Correct Answer: D

    1. Incorrect: Although most drag-and-drop operations begin in the MouseDown event on the source control, it is not required that they begin there.

    2. 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.

    3. 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.

    4. Correct: The DragDrop event is the only event that must be handled to complete a drag-and-drop operation.

Objective 2.5: Thought Experiment

  1. 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.

  2. There are also many ways to implement the animation. However, an attached behavior would simplify adding the behavior to multiple buttons.

  3. 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

  1. Correct Answers: A and B

    1. Correct: RunWorkerAsync raises the DoWork event, which must be handled to run code on the background thread.

    2. Correct: The DoWork event handler contains the code that will be run on the background thread.

    3. Incorrect: Handling the ProgressChanged event is not required.

    4. Incorrect: Setting WorkerSupportsCancellation to True is not required.

  2. Correct Answers: A and C

    1. Correct: The Dispatcher.BeginInvoke method will execute a method asynchronously and safely on the main thread.

    2. Incorrect: Direct access of the UI from a background thread is not allowed.

    3. Correct: Using the built-in mechanism of BackgroundWorker for reporting is the preferred way to report progress that can be expressed numerically.

    4. Incorrect: Direct access of the UI from a background thread is not allowed.

Objective 2.6: Thought Experiment

  1. Yes.

  2. 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.

  3. Yes. They could lower the frame rate of the animations to reduce the performance impact.

  4. Yes, the CLR Profiler is an excellent tool for identifying memory leaks, and it can be downloaded for free from Microsoft.