Download Master Thesis

Transcript
Because the TreeView control does not support having a different context menu
for each item in the tree, it had to be implemented in the code behind. When the
user clicks on the TreeViewItem using the right mouse button, the event handler
in the code behind gets the associated View Model, and using the
IHasContextMenu interface reads the unique identifier of the context menu to
show from the resources.
9.1.3 Tabs
The application uses a tabbed user interface in order to provide an easy way of
displaying various content in a single window. Currently, there are two types of
tabs: a source code viewer and a localization editor. Both tabs provide a different
look on the same data, but the localization editor also allows the user to edit and
store the localization while the code viewer only constructs the Resource Script
back from the resource tree.
Tabs are implemented using Data Templates (4.6). This approach is thoroughly
described in the article WPF Apps with the Model-View-ViewModel Design
Pattern on the MSDN [16]. In XAML, there is a ContentControl with its Content
property bound to a collection of workspaces in the View Model. This collection
contains View Models of all currently visible workspaces. When the View Model
needs to display a new tab, it simply adds it to this collection and the View takes
care of displaying it. The ContentTemplate property of the ContentControl is
set to a Data Template WorkspacesTemplate defined in the resources. It contains
only the TabControl that specifies itself as an ItemsSource, but additionally it
sets the CloseableTabItemTemplate as the template for all items in the
TabControl. This template describes how to render a tab with the close button.
The View Model that will be displayed as a tab must derive from the
WorkspaceViewModel base class as shown in the Figure 18. This class contains
an implementation of the CloseCommand that closes the current tab by removing
it from the collection of active workspaces.
39