mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-06 16:06:07 +02:00
Merge branch 'master' into publish-27362
This commit is contained in:
+18
-1
@@ -13,10 +13,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 9c6a2009-9b86-4e40-8605-0a2664dc3973
|
||||
---
|
||||
# Alignment, Margins, and Padding Overview
|
||||
|
||||
The <xref:System.Windows.FrameworkElement> class exposes several properties that are used to precisely position child elements. This topic discusses four of the most important properties: <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A>, <xref:System.Windows.FrameworkElement.Margin%2A>, <xref:System.Windows.Controls.Border.Padding%2A>, and <xref:System.Windows.FrameworkElement.VerticalAlignment%2A>. The effects of these properties are important to understand, because they provide the basis for controlling the position of elements in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] applications.
|
||||
|
||||
<a name="wcpsdk_layout_amp_introduction"></a>
|
||||
|
||||
## Introduction to Element Positioning
|
||||
|
||||
There are numerous ways to position elements using [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]. However, achieving ideal layout goes beyond simply choosing the right <xref:System.Windows.Controls.Panel> element. Fine control of positioning requires an understanding of the <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A>, <xref:System.Windows.FrameworkElement.Margin%2A>, <xref:System.Windows.Controls.Border.Padding%2A>, and <xref:System.Windows.FrameworkElement.VerticalAlignment%2A> properties.
|
||||
|
||||
The following illustration shows a layout scenario that utilizes several positioning properties.
|
||||
@@ -35,14 +38,18 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||

|
||||
|
||||
<a name="wcpsdk_layout_amp_alignment_properties"></a>
|
||||
|
||||
## Understanding Alignment Properties
|
||||
|
||||
The <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A> and <xref:System.Windows.FrameworkElement.VerticalAlignment%2A> properties describe how a child element should be positioned within a parent element's allocated layout space. By using these properties together, you can position child elements precisely. For example, child elements of a <xref:System.Windows.Controls.DockPanel> can specify four different horizontal alignments: <xref:System.Windows.HorizontalAlignment.Left>, <xref:System.Windows.HorizontalAlignment.Right>, or <xref:System.Windows.HorizontalAlignment.Center>, or to <xref:System.Windows.HorizontalAlignment.Stretch> to fill available space. Similar values are available for vertical positioning.
|
||||
|
||||
> [!NOTE]
|
||||
> Explicitly-set <xref:System.Windows.FrameworkElement.Height%2A> and <xref:System.Windows.FrameworkElement.Width%2A> properties on an element take precedence over the <xref:System.Windows.HorizontalAlignment.Stretch> property value. Attempting to set <xref:System.Windows.FrameworkElement.Height%2A>, <xref:System.Windows.FrameworkElement.Width%2A>, and a <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A> value of `Stretch` results in the `Stretch` request being ignored.
|
||||
|
||||
<a name="wcpsdk_layout_amp_horizontalalignment_properties"></a>
|
||||
|
||||
### HorizontalAlignment Property
|
||||
|
||||
The <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A> property declares the horizontal alignment characteristics to apply to child elements. The following table shows each of the possible values of the <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A> property.
|
||||
|
||||
|Member|Description|
|
||||
@@ -62,7 +69,9 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||

|
||||
|
||||
<a name="wcpsdk_layout_amp_verticalalignment_properties"></a>
|
||||
|
||||
### VerticalAlignment Property
|
||||
|
||||
The <xref:System.Windows.FrameworkElement.VerticalAlignment%2A> property describes the vertical alignment characteristics to apply to child elements. The following table shows each of the possible values for the <xref:System.Windows.FrameworkElement.VerticalAlignment%2A> property.
|
||||
|
||||
|Member|Description|
|
||||
@@ -83,7 +92,9 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||

|
||||
|
||||
<a name="wcpsdk_layout_amp_margin_properties"></a>
|
||||
|
||||
## Understanding Margin Properties
|
||||
|
||||
The <xref:System.Windows.FrameworkElement.Margin%2A> property describes the distance between an element and its child or peers. <xref:System.Windows.FrameworkElement.Margin%2A> values can be uniform, by using syntax like `Margin="20"`. With this syntax, a uniform <xref:System.Windows.FrameworkElement.Margin%2A> of 20 device independent pixels would be applied to the element. <xref:System.Windows.FrameworkElement.Margin%2A> values can also take the form of four distinct values, each value describing a distinct margin to apply to the left, top, right, and bottom (in that order), like `Margin="0,10,5,25"`. Proper use of the <xref:System.Windows.FrameworkElement.Margin%2A> property enables very fine control of an element's rendering position and the rendering position of its neighbor elements and children.
|
||||
|
||||
> [!NOTE]
|
||||
@@ -104,7 +115,9 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||
[!code-xaml[MarginPaddingAlignmentSample#2](~/samples/snippets/xaml/VS_Snippets_Wpf/MarginPaddingAlignmentSample/XAML/default.xaml#2)]
|
||||
|
||||
<a name="wcpsdk_layout_amp_padding_properties"></a>
|
||||
|
||||
## Understanding the Padding Property
|
||||
|
||||
Padding is similar to <xref:System.Windows.FrameworkElement.Margin%2A> in most respects. The Padding property is exposed on only on a few classes, primarily as a convenience: <xref:System.Windows.Documents.Block>, <xref:System.Windows.Controls.Border>, <xref:System.Windows.Controls.Control>, and <xref:System.Windows.Controls.TextBlock> are samples of classes that expose a Padding property. The <xref:System.Windows.Controls.Border.Padding%2A> property enlarges the effective size of a child element by the specified <xref:System.Windows.Thickness> value.
|
||||
|
||||
The following example shows how to apply <xref:System.Windows.Controls.Border.Padding%2A> to a parent <xref:System.Windows.Controls.Border> element.
|
||||
@@ -115,7 +128,9 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||
[!code-xaml[MarginPaddingAlignmentSample#3](~/samples/snippets/xaml/VS_Snippets_Wpf/MarginPaddingAlignmentSample/XAML/default.xaml#3)]
|
||||
|
||||
<a name="wcpsdk_layout_amp_summary"></a>
|
||||
|
||||
## Using Alignment, Margins, and Padding in an Application
|
||||
|
||||
<xref:System.Windows.FrameworkElement.HorizontalAlignment%2A>, <xref:System.Windows.FrameworkElement.Margin%2A>, <xref:System.Windows.Controls.Border.Padding%2A>, and <xref:System.Windows.FrameworkElement.VerticalAlignment%2A> provide the positioning control necessary to create a complex [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)]. You can use the effects of each property to change child-element positioning, enabling flexibility in creating dynamic applications and user experiences.
|
||||
|
||||
The following example demonstrates each of the concepts that are detailed in this topic. Building on the infrastructure found in the first sample in this topic, this example adds a <xref:System.Windows.Controls.Grid> element as a child of the <xref:System.Windows.Controls.Border> in the first sample. <xref:System.Windows.Controls.Border.Padding%2A> is applied to the parent <xref:System.Windows.Controls.Border> element. The <xref:System.Windows.Controls.Grid> is used to partition space between three child <xref:System.Windows.Controls.StackPanel> elements. <xref:System.Windows.Controls.Button> elements are again used to show the various effects of <xref:System.Windows.FrameworkElement.Margin%2A> and <xref:System.Windows.FrameworkElement.HorizontalAlignment%2A>. <xref:System.Windows.Controls.TextBlock> elements are added to each <xref:System.Windows.Controls.ColumnDefinition> to better define the various properties applied to the <xref:System.Windows.Controls.Button> elements in each column.
|
||||
@@ -130,7 +145,9 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||

|
||||
|
||||
<a name="wcpsdk_layout_amp_alignment_whatsnext"></a>
|
||||
|
||||
## What's Next
|
||||
|
||||
Positioning properties defined by the <xref:System.Windows.FrameworkElement> class enable fine control of element placement within [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications. You now have several techniques you can use to better position elements using [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)].
|
||||
|
||||
Additional resources are available that explain [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] layout in greater detail. The [Panels Overview](../controls/panels-overview.md) topic contains more detail about the various <xref:System.Windows.Controls.Panel> elements. The topic [Walkthrough: My first WPF desktop application](../getting-started/walkthrough-my-first-wpf-desktop-application.md) introduces advanced techniques that use layout elements to position components and bind their actions to data sources.
|
||||
@@ -143,4 +160,4 @@ The <xref:System.Windows.FrameworkElement> class exposes several properties that
|
||||
- <xref:System.Windows.FrameworkElement.Margin%2A>
|
||||
- [Panels Overview](../controls/panels-overview.md)
|
||||
- [Layout](layout.md)
|
||||
- [WPF Layout Gallery Sample](https://go.microsoft.com/fwlink/?LinkID=160054)
|
||||
- [WPF Layout Gallery Sample](https://github.com/microsoft/WPF-Samples/tree/master/Getting%20Started/ControlsAndLayout)
|
||||
|
||||
@@ -11,12 +11,15 @@ helpviewer_keywords:
|
||||
ms.assetid: 716bf474-29bd-4c74-84a4-8e0744bdad62
|
||||
---
|
||||
# Annotations Overview
|
||||
|
||||
Writing notes or comments on paper documents is such a commonplace activity that we almost take it for granted. These notes or comments are "annotations" that we add to a document to flag information or to highlight items of interest for later reference. Although writing notes on printed documents is easy and commonplace, the ability to add personal comments to electronic documents is typically very limited, if available at all.
|
||||
|
||||
This topic reviews several common types of annotations, specifically sticky notes and highlights, and illustrates how the Microsoft Annotations Framework facilitates these types of annotations in applications through the Windows Presentation Foundation (WPF) document viewing controls. WPF document viewing controls that support annotations include <xref:System.Windows.Controls.FlowDocumentReader> and <xref:System.Windows.Controls.FlowDocumentScrollViewer>, as well as controls derived from <xref:System.Windows.Controls.Primitives.DocumentViewerBase> such as <xref:System.Windows.Controls.DocumentViewer> and <xref:System.Windows.Controls.FlowDocumentPageViewer>.
|
||||
|
||||
<a name="caf1_type_stickynotes"></a>
|
||||
|
||||
## Sticky Notes
|
||||
|
||||
A typical sticky note contains information written on a small piece of colored paper that is then "stuck" to a document. Digital sticky notes provide similar functionality for electronic documents, but with the added flexibility to include many other types of content such as typed text, handwritten notes (for example, Tablet PC "ink" strokes), or Web links.
|
||||
|
||||
The following illustration shows some examples of highlight, text sticky note, and ink sticky note annotations.
|
||||
@@ -29,7 +32,9 @@ Writing notes or comments on paper documents is such a commonplace activity that
|
||||
[!code-vb[DocViewerAnnotationsXml#DocViewXmlStartAnnotations](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DocViewerAnnotationsXml/visualbasic/window1.xaml.vb#docviewxmlstartannotations)]
|
||||
|
||||
<a name="caf1_type_callouts"></a>
|
||||
|
||||
## Highlights
|
||||
|
||||
People use creative methods to draw attention to items of interest when they mark up a paper document, such as underlining, highlighting, circling words in a sentence, or drawing marks or notations in the margin. Highlight annotations in Microsoft Annotations Framework provide a similar feature for marking up information displayed in WPF document viewing controls.
|
||||
|
||||
The following illustration shows an example of a highlight annotation.
|
||||
@@ -41,13 +46,17 @@ Writing notes or comments on paper documents is such a commonplace activity that
|
||||
[!code-xaml[DocViewerAnnotationsXps#CreateDeleteAnnotations](~/samples/snippets/csharp/VS_Snippets_Wpf/DocViewerAnnotationsXps/CSharp/Window1.xaml#createdeleteannotations)]
|
||||
|
||||
<a name="caf1_framework_data_anchoring"></a>
|
||||
|
||||
## Data Anchoring
|
||||
|
||||
The Annotations Framework binds annotations to the data that the user selects, not just to a position on the display view. Therefore, if the document view changes, such as when the user scrolls or resizes the display window, the annotation stays with the data selection to which it is bound. For example, the following graphic illustrates an annotation that the user has made on a text selection. When the document view changes (scrolls, resizes, scales, or otherwise moves), the highlight annotation moves with the original data selection.
|
||||
|
||||

|
||||
|
||||
<a name="matching_annotations_with_annotated_objects"></a>
|
||||
|
||||
## Matching Annotations with Annotated Objects
|
||||
|
||||
You can match annotations with the corresponding annotated objects. For example, consider a simple document reader application that has a comments pane. The comments pane might be a list box that displays the text from a list of annotations that are anchored to a document. If the user selects an item in the list box, then the application brings into view the paragraph in the document that the corresponding annotation object is anchored to.
|
||||
|
||||
The following example demonstrates how to implement the event handler of such a list box that serves as the comments pane.
|
||||
@@ -69,4 +78,4 @@ Writing notes or comments on paper documents is such a commonplace activity that
|
||||
- [ContextMenu Overview](../controls/contextmenu-overview.md)
|
||||
- [Commanding Overview](commanding-overview.md)
|
||||
- [Flow Document Overview](flow-document-overview.md)
|
||||
- [How to: Add a Command to a MenuItem](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms741839(v=vs.90))
|
||||
- [How to: Add a Command to a MenuItem](/previous-versions/dotnet/netframework-3.5/ms741839(v=vs.90))
|
||||
|
||||
@@ -16,6 +16,7 @@ helpviewer_keywords:
|
||||
ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
---
|
||||
# Commanding Overview
|
||||
|
||||
<a name="introduction"></a> Commanding is an input mechanism in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] which provides input handling at a more semantic level than device input. Examples of commands are the **Copy**, **Cut**, and **Paste** operations found on many applications.
|
||||
|
||||
This overview defines what commands are in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)], which classes are part of the commanding model, and how to use and create commands in your applications.
|
||||
@@ -33,7 +34,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
- [Creating Custom Commands](#creating_commands)
|
||||
|
||||
<a name="commands_at_10000_feet"></a>
|
||||
## What Are Commands?
|
||||
|
||||
## What Are Commands
|
||||
|
||||
Commands have several purposes. The first purpose is to separate the semantics and the object that invokes a command from the logic that executes the command. This allows for multiple and disparate sources to invoke the same command logic, and it allows the command logic to be customized for different targets. For example, the editing operations **Copy**, **Cut**, and **Paste**, which are found in many applications, can be invoked by using different user actions if they are implemented by using commands. An application might allow a user to cut selected objects or text by either clicking a button, choosing an item in a menu, or using a key combination, such as CTRL+X. By using commands, you can bind each type of user action to the same logic.
|
||||
|
||||
Another purpose of commands is to indicate whether an action is available. To continue the example of cutting an object or text, the action only makes sense when something is selected. If a user tries to cut an object or text without having anything selected, nothing would happen. To indicate this to the user, many applications disable buttons and menu items so that the user knows whether it is possible to perform an action. A command can indicate whether an action is possible by implementing the <xref:System.Windows.Input.ICommand.CanExecute%2A> method. A button can subscribe to the <xref:System.Windows.Input.ICommand.CanExecuteChanged> event and be disabled if <xref:System.Windows.Input.ICommand.CanExecute%2A> returns `false` or be enabled if <xref:System.Windows.Input.ICommand.CanExecute%2A> returns `true`.
|
||||
@@ -41,7 +44,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
The semantics of a command can be consistent across applications and classes, but the logic of the action is specific to the particular object acted upon. The key combination CTRL+X invokes the **Cut** command in text classes, image classes, and Web browsers, but the actual logic for performing the **Cut** operation is defined by the application that performs the cut. A <xref:System.Windows.Input.RoutedCommand> enables clients to implement the logic. A text object may cut the selected text into the clipboard, while an image object may cut the selected image. When an application handles the <xref:System.Windows.Input.CommandManager.Executed> event, it has access to the target of the command and can take appropriate action depending on the target's type.
|
||||
|
||||
<a name="simple_command"></a>
|
||||
|
||||
## Simple Command Example in WPF
|
||||
|
||||
The simplest way to use a command in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] is to use a predefined <xref:System.Windows.Input.RoutedCommand> from one of the command library classes; use a control that has native support for handling the command; and use a control that has native support for invoking a command. The <xref:System.Windows.Input.ApplicationCommands.Paste%2A> command is one of the predefined commands in the <xref:System.Windows.Input.ApplicationCommands> class. The <xref:System.Windows.Controls.TextBox> control has built in logic for handling the <xref:System.Windows.Input.ApplicationCommands.Paste%2A> command. And the <xref:System.Windows.Controls.MenuItem> class has native support for invoking commands.
|
||||
|
||||
The following example shows how to set up a <xref:System.Windows.Controls.MenuItem> so that when it is clicked it will invoke the <xref:System.Windows.Input.ApplicationCommands.Paste%2A> command on a <xref:System.Windows.Controls.TextBox>, assuming the <xref:System.Windows.Controls.TextBox> has keyboard focus.
|
||||
@@ -52,7 +57,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
[!code-vb[CommandingOverviewSnippets#CommandingOverviewCommandTargetCodeBehind](~/samples/snippets/visualbasic/VS_Snippets_Wpf/CommandingOverviewSnippets/visualbasic/window1.xaml.vb#commandingoverviewcommandtargetcodebehind)]
|
||||
|
||||
<a name="Four_main_Concepts"></a>
|
||||
|
||||
## Four Main Concepts in WPF Commanding
|
||||
|
||||
The routed command model in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] can be broken up into four main concepts: the command, the command source, the command target, and the command binding:
|
||||
|
||||
- The *command* is the action to be executed.
|
||||
@@ -66,7 +73,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
In the previous example, the <xref:System.Windows.Input.ApplicationCommands.Paste%2A> command is the command, the <xref:System.Windows.Controls.MenuItem> is the command source, the <xref:System.Windows.Controls.TextBox> is the command target, and the command binding is supplied by the <xref:System.Windows.Controls.TextBox> control. It is worth noting that it is not always the case that the <xref:System.Windows.Input.CommandBinding> is supplied by the control that is the command target class. Quite often the <xref:System.Windows.Input.CommandBinding> must be created by the application developer, or the <xref:System.Windows.Input.CommandBinding> might be attached to an ancestor of the command target.
|
||||
|
||||
<a name="Commands"></a>
|
||||
|
||||
### Commands
|
||||
|
||||
Commands in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] are created by implementing the <xref:System.Windows.Input.ICommand> interface. <xref:System.Windows.Input.ICommand> exposes two methods, <xref:System.Windows.Input.ICommand.Execute%2A>, and <xref:System.Windows.Input.ICommand.CanExecute%2A>, and an event, <xref:System.Windows.Input.ICommand.CanExecuteChanged>. <xref:System.Windows.Input.ICommand.Execute%2A> performs the actions that are associated with the command. <xref:System.Windows.Input.ICommand.CanExecute%2A> determines whether the command can execute on the current command target. <xref:System.Windows.Input.ICommand.CanExecuteChanged> is raised if the command manager that centralizes the commanding operations detects a change in the command source that might invalidate a command that has been raised but not yet executed by the command binding. The [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] implementation of <xref:System.Windows.Input.ICommand> is the <xref:System.Windows.Input.RoutedCommand> class and is the focus of this overview.
|
||||
|
||||
The main sources of input in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] are the mouse, the keyboard, ink, and routed commands. The more device-oriented inputs use a <xref:System.Windows.RoutedEvent> to notify objects in an application page that an input event has occurred. A <xref:System.Windows.Input.RoutedCommand> is no different. The <xref:System.Windows.Input.RoutedCommand.Execute%2A> and <xref:System.Windows.Input.RoutedCommand.CanExecute%2A> methods of a <xref:System.Windows.Input.RoutedCommand> do not contain the application logic for the command, but rather they raise routed events that tunnel and bubble through the element tree until they encounter an object with a <xref:System.Windows.Input.CommandBinding>. The <xref:System.Windows.Input.CommandBinding> contains the handlers for these events and it is the handlers that perform the command. For more information on event routing in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)], see [Routed Events Overview](routed-events-overview.md).
|
||||
@@ -76,7 +85,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] supplies a set of common routed commands spread across several classes: <xref:System.Windows.Input.MediaCommands>, <xref:System.Windows.Input.ApplicationCommands>, <xref:System.Windows.Input.NavigationCommands>, <xref:System.Windows.Input.ComponentCommands>, and <xref:System.Windows.Documents.EditingCommands>. These classes consist only of the <xref:System.Windows.Input.RoutedCommand> objects and not the implementation logic of the command. The implementation logic is the responsibility of the object on which the command is being executed on.
|
||||
|
||||
<a name="Command_Sources"></a>
|
||||
|
||||
### Command Sources
|
||||
|
||||
A command source is the object which invokes the command. Examples of command sources are <xref:System.Windows.Controls.MenuItem>, <xref:System.Windows.Controls.Button>, and <xref:System.Windows.Input.KeyGesture>.
|
||||
|
||||
Command sources in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] generally implement the <xref:System.Windows.Input.ICommandSource> interface.
|
||||
@@ -119,7 +130,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
[!code-vb[CommandingOverviewSnippets#CommandingOverviewKeyGestureOnCmd](~/samples/snippets/visualbasic/VS_Snippets_Wpf/CommandingOverviewSnippets/visualbasic/window1.xaml.vb#commandingoverviewkeygestureoncmd)]
|
||||
|
||||
<a name="Command_Binding"></a>
|
||||
|
||||
### CommandBinding
|
||||
|
||||
A <xref:System.Windows.Input.CommandBinding> associates a command with the event handlers that implement the command.
|
||||
|
||||
The <xref:System.Windows.Input.CommandBinding> class contains a <xref:System.Windows.Input.CommandBinding.Command%2A> property, and <xref:System.Windows.Input.CommandBinding.PreviewExecuted>, <xref:System.Windows.Input.CommandBinding.Executed>, <xref:System.Windows.Input.CommandBinding.PreviewCanExecute>, and <xref:System.Windows.Input.CommandBinding.CanExecute> events.
|
||||
@@ -146,7 +159,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
In some situations the <xref:System.Windows.Input.CommandBinding> is attached to the command target itself, such as with the <xref:System.Windows.Controls.TextBox> class and the <xref:System.Windows.Input.ApplicationCommands.Cut%2A>, <xref:System.Windows.Input.ApplicationCommands.Copy%2A>, and <xref:System.Windows.Input.ApplicationCommands.Paste%2A> commands. Quite often though, it is more convenient to attach the <xref:System.Windows.Input.CommandBinding> to an ancestor of the command target, such as the main <xref:System.Windows.Window> or the Application object, especially if the same <xref:System.Windows.Input.CommandBinding> can be used for multiple command targets. These are design decisions you will want to consider when you are creating your commanding infrastructure.
|
||||
|
||||
<a name="Commane_Target"></a>
|
||||
|
||||
### Command Target
|
||||
|
||||
The command target is the element on which the command is executed. With regards to a <xref:System.Windows.Input.RoutedCommand>, the command target is the element at which routing of the <xref:System.Windows.Input.CommandManager.Executed> and <xref:System.Windows.Input.CommandManager.CanExecute> starts. As noted previously, in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] the <xref:System.Windows.Input.ICommandSource.CommandTarget%2A> property on <xref:System.Windows.Input.ICommandSource> is only applicable when the <xref:System.Windows.Input.ICommand> is a <xref:System.Windows.Input.RoutedCommand>. If the <xref:System.Windows.Input.ICommandSource.CommandTarget%2A> is set on an <xref:System.Windows.Input.ICommandSource> and the corresponding command is not a <xref:System.Windows.Input.RoutedCommand>, the command target is ignored.
|
||||
|
||||
The command source can explicitly set the command target. If the command target is not defined, the element with keyboard focus will be used as the command target. One of the benefits of using the element with keyboard focus as the command target is that it allows the application developer to use the same command source to invoke a command on multiple targets without having to keep track of the command target. For example, if a <xref:System.Windows.Controls.MenuItem> invokes the **Paste** command in an application that has a <xref:System.Windows.Controls.TextBox> control and a <xref:System.Windows.Controls.PasswordBox> control, the target can be either the <xref:System.Windows.Controls.TextBox> or <xref:System.Windows.Controls.PasswordBox> depending on which control has keyboard focus.
|
||||
@@ -159,13 +174,17 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
[!code-vb[CommandingOverviewSnippets#CommandingOverviewCommandTargetCodeBehind](~/samples/snippets/visualbasic/VS_Snippets_Wpf/CommandingOverviewSnippets/visualbasic/window1.xaml.vb#commandingoverviewcommandtargetcodebehind)]
|
||||
|
||||
<a name="Command_Manager"></a>
|
||||
|
||||
### The CommandManager
|
||||
|
||||
The <xref:System.Windows.Input.CommandManager> serves a number of command related functions. It provides a set of static methods for adding and removing <xref:System.Windows.Input.CommandManager.PreviewExecuted>, <xref:System.Windows.Input.CommandManager.Executed>, <xref:System.Windows.Input.CommandManager.PreviewCanExecute>, and <xref:System.Windows.Input.CommandManager.CanExecute> event handlers to and from a specific element. It provides a means to register <xref:System.Windows.Input.CommandBinding> and <xref:System.Windows.Input.InputBinding> objects onto a specific class. The <xref:System.Windows.Input.CommandManager> also provides a means, through the <xref:System.Windows.Input.CommandManager.RequerySuggested> event, to notify a command when it should raise the <xref:System.Windows.Input.ICommand.CanExecuteChanged> event.
|
||||
|
||||
The <xref:System.Windows.Input.CommandManager.InvalidateRequerySuggested%2A> method forces the <xref:System.Windows.Input.CommandManager> to raise the <xref:System.Windows.Input.CommandManager.RequerySuggested> event. This is useful for conditions that should disable/enable a command but are not conditions that the <xref:System.Windows.Input.CommandManager> is aware of.
|
||||
|
||||
<a name="Command_Library"></a>
|
||||
|
||||
## Command Library
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides a set of predefined commands. The command library consists of the following classes: <xref:System.Windows.Input.ApplicationCommands>, <xref:System.Windows.Input.NavigationCommands>, <xref:System.Windows.Input.MediaCommands>, <xref:System.Windows.Documents.EditingCommands>, and the <xref:System.Windows.Input.ComponentCommands>. These classes provide commands such as <xref:System.Windows.Input.ApplicationCommands.Cut%2A>, <xref:System.Windows.Input.NavigationCommands.BrowseBack%2A> and <xref:System.Windows.Input.NavigationCommands.BrowseForward%2A>, <xref:System.Windows.Input.MediaCommands.Play%2A>, <xref:System.Windows.Input.MediaCommands.Stop%2A>, and <xref:System.Windows.Input.MediaCommands.Pause%2A>.
|
||||
|
||||
Many of these commands include a set of default input bindings. For example, if you specify that your application handles the copy command, you automatically get the keyboard binding "CTRL+C" You also get bindings for other input devices, such as Tablet PC pen gestures and speech information.
|
||||
@@ -173,7 +192,9 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
When you reference commands in the various command libraries using [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)], you can usually omit the class name of the library class that exposes the static command property. Generally, the command names are unambiguous as strings, and the owning types exist to provide a logical grouping of commands but are not necessary for disambiguation. For instance, you can specify `Command="Cut"` rather than the more verbose `Command="ApplicationCommands.Cut"`. This is a convenience mechanism that is built in to the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] processor for commands (more precisely, it is a type converter behavior of <xref:System.Windows.Input.ICommand>, which the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] processor references at load time).
|
||||
|
||||
<a name="creating_commands"></a>
|
||||
|
||||
## Creating Custom Commands
|
||||
|
||||
If the commands in the command library classes do not meet your needs, then you can create your own commands. There are two ways to create a custom command. The first is to start from the ground up and implement the <xref:System.Windows.Input.ICommand> interface. The other way, and the more common approach, is to create a <xref:System.Windows.Input.RoutedCommand> or a <xref:System.Windows.Input.RoutedUICommand>.
|
||||
|
||||
For an example of creating a custom <xref:System.Windows.Input.RoutedCommand>, see [Create a Custom RoutedCommand Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Input%20and%20Commands/CustomRoutedCommand).
|
||||
@@ -187,5 +208,5 @@ ms.assetid: bc208dfe-367d-426a-99de-52b7e7511e81
|
||||
- [Input Overview](input-overview.md)
|
||||
- [Routed Events Overview](routed-events-overview.md)
|
||||
- [Implement ICommandSource](how-to-implement-icommandsource.md)
|
||||
- [How to: Add a Command to a MenuItem](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms741839(v=vs.90))
|
||||
- [How to: Add a Command to a MenuItem](/previous-versions/dotnet/netframework-3.5/ms741839(v=vs.90))
|
||||
- [Create a Custom RoutedCommand Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Input%20and%20Commands/CustomRoutedCommand)
|
||||
|
||||
@@ -16,6 +16,7 @@ helpviewer_keywords:
|
||||
ms.assetid: c31f3a67-cb3f-4ded-af9e-ed21f6575b26
|
||||
---
|
||||
# Creating an Ink Input Control
|
||||
|
||||
You can create a custom control that dynamically and statically renders ink. That is, render ink as a user draws a stroke, causing the ink to appear to "flow" from the tablet pen, and display ink after it is added to the control, either via the tablet pen, pasted from the Clipboard, or loaded from a file. To dynamically render ink, your control must use a <xref:System.Windows.Input.StylusPlugIns.DynamicRenderer>. To statically render ink, you must override the stylus event methods (<xref:System.Windows.UIElement.OnStylusDown%2A>, <xref:System.Windows.UIElement.OnStylusMove%2A>, and <xref:System.Windows.UIElement.OnStylusUp%2A>) to collect <xref:System.Windows.Input.StylusPoint> data, create strokes, and add them to an <xref:System.Windows.Controls.InkPresenter> (which renders the ink on the control).
|
||||
|
||||
This topic contains the following subsections:
|
||||
@@ -31,7 +32,9 @@ You can create a custom control that dynamically and statically renders ink. Tha
|
||||
- [Conclusion](#AdvancedInkHandling_Conclusion)
|
||||
|
||||
<a name="CollectingStylusPointDataAndCreatingInkStrokes"></a>
|
||||
|
||||
## How to: Collect Stylus Point Data and Create Ink Strokes
|
||||
|
||||
To create a control that collects and manages ink strokes do the following:
|
||||
|
||||
1. Derive a class from <xref:System.Windows.Controls.Control> or one of the classes derived from <xref:System.Windows.Controls.Control>, such as <xref:System.Windows.Controls.Label>.
|
||||
@@ -62,7 +65,9 @@ You can create a custom control that dynamically and statically renders ink. Tha
|
||||
[!code-csharp[AdvancedInkTopicsSamples#10](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/StylusControl.cs#10)]
|
||||
|
||||
<a name="EnablingYourControlToAcceptInputTromTheMouse"></a>
|
||||
|
||||
## How to: Enable Your Control to Accept Input from the Mouse
|
||||
|
||||
If you add the preceding control to your application, run it, and use the mouse as an input device, you will notice that the strokes are not persisted. To persist the strokes when the mouse is used as the input device do the following:
|
||||
|
||||
1. Override the <xref:System.Windows.UIElement.OnMouseLeftButtonDown%2A> and create a new <xref:System.Windows.Input.StylusPointCollection> Get the position of the mouse when the event occurred and create a <xref:System.Windows.Input.StylusPoint> using the point data and add the <xref:System.Windows.Input.StylusPoint> to the <xref:System.Windows.Input.StylusPointCollection>.
|
||||
@@ -78,21 +83,27 @@ You can create a custom control that dynamically and statically renders ink. Tha
|
||||
[!code-csharp[AdvancedInkTopicsSamples#13](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/StylusControl.cs#13)]
|
||||
|
||||
<a name="PuttingItTogether"></a>
|
||||
|
||||
## Putting it together
|
||||
|
||||
The following example is a custom control that collects ink when the user uses either the mouse or the pen.
|
||||
|
||||
[!code-csharp[AdvancedInkTopicsSamples#20](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/StylusControl.cs#20)]
|
||||
[!code-csharp[AdvancedInkTopicsSamples#6](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/StylusControl.cs#6)]
|
||||
|
||||
<a name="UsingAdditionalPluginsAndDynamicRenderers"></a>
|
||||
|
||||
## Using Additional Plug-ins and DynamicRenderers
|
||||
|
||||
Like the InkCanvas, your custom control can have custom <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> and additional <xref:System.Windows.Input.StylusPlugIns.DynamicRenderer> objects. Add these to the <xref:System.Windows.UIElement.StylusPlugIns%2A> collection. The order of the <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> objects in the <xref:System.Windows.Input.StylusPlugIns.StylusPlugInCollection> affects the appearance of the ink when it is rendered. Suppose you have a <xref:System.Windows.Input.StylusPlugIns.DynamicRenderer> called `dynamicRenderer` and a custom <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> called `translatePlugin` that offsets the ink from the tablet pen. If `translatePlugin` is the first <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> in the <xref:System.Windows.Input.StylusPlugIns.StylusPlugInCollection>, and `dynamicRenderer` is the second, the ink that "flows" will be offset as the user moves the pen. If `dynamicRenderer` is first, and `translatePlugin` is second, the ink will not be offset until the user lifts the pen.
|
||||
|
||||
<a name="AdvancedInkHandling_Conclusion"></a>
|
||||
|
||||
## Conclusion
|
||||
|
||||
You can create a control that collects and renders ink by overriding the stylus event methods. By creating your own control, deriving your own <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> classes, and inserting them the into <xref:System.Windows.Input.StylusPlugIns.StylusPlugInCollection>, you can implement virtually any behavior imaginable with digital ink. You have access to the <xref:System.Windows.Input.StylusPoint> data as it is generated, giving you the opportunity to customize <xref:System.Windows.Input.Stylus> input and render it on the screen as appropriate for your application. Because you have such low-level access to the <xref:System.Windows.Input.StylusPoint> data, you can implement ink collection and render it with optimal performance for your application.
|
||||
|
||||
## See also
|
||||
|
||||
- [Advanced Ink Handling](advanced-ink-handling.md)
|
||||
- [Accessing and Manipulating Pen Input](https://docs.microsoft.com/previous-versions/ms818317(v=msdn.10))
|
||||
- [Accessing and Manipulating Pen Input](/previous-versions/ms818317(v=msdn.10))
|
||||
|
||||
@@ -8,9 +8,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 7bf37ccb-5d09-4eae-9661-929582aeb259
|
||||
---
|
||||
# Documents
|
||||
|
||||
[!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] provides a versatile set of components that enable developers to build applications with advanced document features and an improved reading experience. In addition to enhanced capabilities and quality, [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] also provides simplified management services for document packaging, security, and storage.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Documents in WPF](documents-in-wpf.md)
|
||||
[Document Serialization and Storage](document-serialization-and-storage.md)
|
||||
[Annotations](annotations.md)
|
||||
@@ -23,4 +25,4 @@ ms.assetid: 7bf37ccb-5d09-4eae-9661-929582aeb259
|
||||
- <xref:System.Windows.Controls.DocumentViewer>
|
||||
- <xref:System.Windows.Documents.FlowDocument>
|
||||
- <xref:System.Windows.Xps>
|
||||
- [isXPS.exe (isXPS Conformance Tool)](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100))
|
||||
- [isXPS.exe (isXPS Conformance Tool)](/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100))
|
||||
|
||||
@@ -12,9 +12,11 @@ helpviewer_keywords:
|
||||
ms.assetid: b1d851c1-331c-4814-9964-6fe769db6f1f
|
||||
---
|
||||
# Drawing Formatted Text
|
||||
|
||||
This topic provides an overview of the features of the <xref:System.Windows.Media.FormattedText> object. This object provides low-level control for drawing text in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] applications.
|
||||
|
||||
## Technology Overview
|
||||
|
||||
The <xref:System.Windows.Media.FormattedText> object allows you to draw multi-line text, in which each character in the text can be individually formatted. The following example shows text that has several formats applied to it.
|
||||
|
||||

|
||||
@@ -23,6 +25,7 @@ This topic provides an overview of the features of the <xref:System.Windows.Medi
|
||||
> For those developers migrating from the Win32 API, the table in the [Win32 Migration](#win32_migration) section lists the Win32 DrawText flags and the approximate equivalent in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)].
|
||||
|
||||
### Reasons for Using Formatted Text
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] includes multiple controls for drawing text to the screen. Each control is targeted to a different scenario and has its own list of features and limitations. In general, the <xref:System.Windows.Controls.TextBlock> element should be used when limited text support is required, such as a brief sentence in a [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)]. <xref:System.Windows.Controls.Label> can be used when minimal text support is required. For more information, see [Documents in WPF](documents-in-wpf.md).
|
||||
|
||||
The <xref:System.Windows.Media.FormattedText> object provides greater text formatting features than [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] text controls, and can be useful in cases where you want to use text as a decorative element. For more information, see the following section [Converting Formatted Text to a Geometry](#converting_formatted_text).
|
||||
@@ -30,6 +33,7 @@ This topic provides an overview of the features of the <xref:System.Windows.Medi
|
||||
In addition, the <xref:System.Windows.Media.FormattedText> object is useful for creating text-oriented <xref:System.Windows.Media.DrawingVisual>-derived objects. <xref:System.Windows.Media.DrawingVisual> is a lightweight drawing class that is used to render shapes, images, or text. For more information, see [Hit Test Using DrawingVisuals Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Visual%20Layer/DrawingVisual).
|
||||
|
||||
## Using the FormattedText Object
|
||||
|
||||
To create formatted text, call the <xref:System.Windows.Media.FormattedText.%23ctor%2A> constructor to create a <xref:System.Windows.Media.FormattedText> object. Once you have created the initial formatted text string, you can apply a range of formatting styles.
|
||||
|
||||
Use the <xref:System.Windows.Media.FormattedText.MaxTextWidth%2A> property to constrain the text to a specific width. The text will automatically wrap to avoid exceeding the specified width. Use the <xref:System.Windows.Media.FormattedText.MaxTextHeight%2A> property to constrain the text to a specific height. The text will display an ellipsis, "…" for the text that exceeds the specified height.
|
||||
@@ -44,13 +48,16 @@ This topic provides an overview of the features of the <xref:System.Windows.Medi
|
||||
[!code-vb[FormattedTextSnippets#FormattedTextSnippets1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FormattedTextSnippets/visualbasic/window1.xaml.vb#formattedtextsnippets1)]
|
||||
|
||||
### Font Size Unit of Measure
|
||||
|
||||
As with other text objects in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] applications, the <xref:System.Windows.Media.FormattedText> object uses device-independent pixels as the unit of measure. However, most Win32 applications use points as the unit of measure. If you want to use display text in units of points in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] applications, you need to convert device-independent units (1/96th inch per unit) to points. The following code example shows how to perform this conversion.
|
||||
|
||||
[!code-csharp[FormattedTextSnippets#FormattedTextSnippets2](~/samples/snippets/csharp/VS_Snippets_Wpf/FormattedTextSnippets/CSharp/Window1.xaml.cs#formattedtextsnippets2)]
|
||||
[!code-vb[FormattedTextSnippets#FormattedTextSnippets2](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FormattedTextSnippets/visualbasic/window1.xaml.vb#formattedtextsnippets2)]
|
||||
|
||||
<a name="converting_formatted_text"></a>
|
||||
|
||||
### Converting Formatted Text to a Geometry
|
||||
|
||||
You can convert formatted text into <xref:System.Windows.Media.Geometry> objects, allowing you to create other types of visually interesting text. For example, you could create a <xref:System.Windows.Media.Geometry> object based on the outline of a text string.
|
||||
|
||||

|
||||
@@ -72,14 +79,16 @@ This topic provides an overview of the features of the <xref:System.Windows.Medi
|
||||

|
||||
Sphere following the path geometry of text
|
||||
|
||||
For more information, see [How to: Create a PathGeometry Animation for Text](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ms743610(v=vs.100)).
|
||||
For more information, see [How to: Create a PathGeometry Animation for Text](/previous-versions/dotnet/netframework-4.0/ms743610(v=vs.100)).
|
||||
|
||||
You can create other interesting uses for formatted text once it has been converted to a <xref:System.Windows.Media.PathGeometry> object. For example, you can clip video to display inside it.
|
||||
|
||||

|
||||
|
||||
<a name="win32_migration"></a>
|
||||
|
||||
## Win32 Migration
|
||||
|
||||
The features of <xref:System.Windows.Media.FormattedText> for drawing text are similar to the features of the Win32 DrawText function. For those developers migrating from the Win32 API, the following table lists the Win32 DrawText flags and the approximate equivalent in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)].
|
||||
|
||||
|DrawText flag|WPF equivalent|Notes|
|
||||
@@ -115,4 +124,4 @@ Sphere following the path geometry of text
|
||||
- [Documents in WPF](documents-in-wpf.md)
|
||||
- [Typography in WPF](typography-in-wpf.md)
|
||||
- [Create Outlined Text](how-to-create-outlined-text.md)
|
||||
- [How to: Create a PathGeometry Animation for Text](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ms743610(v=vs.100))
|
||||
- [How to: Create a PathGeometry Animation for Text](/previous-versions/dotnet/netframework-4.0/ms743610(v=vs.100))
|
||||
|
||||
@@ -10,10 +10,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 08dd1606-02a2-4122-9351-c0afd2ec3a70
|
||||
---
|
||||
# Graphics Rendering Tiers
|
||||
|
||||
A rendering tier defines a level of graphics hardware capability and performance for a device that runs a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application.
|
||||
|
||||
<a name="graphics_hardware"></a>
|
||||
|
||||
## Graphics Hardware
|
||||
|
||||
The features of the graphics hardware that most impact the rendering tier levels are:
|
||||
|
||||
- **Video RAM** The amount of video memory on the graphics hardware determines the size and number of buffers that can be used for compositing graphics.
|
||||
@@ -25,7 +28,9 @@ A rendering tier defines a level of graphics hardware capability and performance
|
||||
- **Multitexture Support** Multitexture support refers to the ability to apply two or more distinct textures during a blending operation on a 3D graphics object. The degree of multitexture support is determined by the number of multitexture units on the graphics hardware.
|
||||
|
||||
<a name="rendering_tier_definitions"></a>
|
||||
|
||||
## Rendering Tier Definitions
|
||||
|
||||
The features of the graphics hardware determine the rendering capability of a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application. The [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] system defines three rendering tiers:
|
||||
|
||||
- **Rendering Tier 0** No graphics hardware acceleration. All graphics features use software acceleration. The DirectX version level is less than version 9.0.
|
||||
@@ -37,6 +42,7 @@ A rendering tier defines a level of graphics hardware capability and performance
|
||||
The <xref:System.Windows.Media.RenderCapability.Tier%2A?displayProperty=nameWithType> property allows you to retrieve the rendering tier at application run time. You use the rendering tier to determine whether the device supports certain hardware-accelerated graphics features. Your application can then take different code paths at run time depending on the rendering tier supported by the device.
|
||||
|
||||
### Rendering Tier 0
|
||||
|
||||
A rendering tier value of 0 means that there is no graphics hardware acceleration available for the application on the device. At this tier level, you should assume that all graphics will be rendered by software with no hardware acceleration. This tier's functionality corresponds to a DirectX version that is less than 9.0.
|
||||
|
||||
### Rendering Tier 1 and Rendering Tier 2
|
||||
@@ -82,14 +88,17 @@ A rendering tier defines a level of graphics hardware capability and performance
|
||||
|Rasterized content that uses <xref:System.Windows.Media.Imaging.RenderTargetBitmap>|Any content rendered by using the <xref:System.Windows.Media.Imaging.RenderTargetBitmap.Render%2A> method of <xref:System.Windows.Media.Imaging.RenderTargetBitmap>.|
|
||||
|Tiled content that uses <xref:System.Windows.Media.TileBrush>|Any tiled content in which the <xref:System.Windows.Media.TileBrush.TileMode%2A> property of the <xref:System.Windows.Media.TileBrush> is set to <xref:System.Windows.Media.TileMode.Tile>.|
|
||||
|Surfaces that exceed the maximum texture size of the graphics hardware|For most graphics hardware, large surfaces are 2048x2048 or 4096x4096 pixels in size.|
|
||||
|Any operation whose video RAM requirement exceeds the memory of the graphics hardware|You can monitor application video RAM usage by using the Perforator tool that is included in the [WPF Performance Suite](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100)) in the Windows SDK.|
|
||||
|Any operation whose video RAM requirement exceeds the memory of the graphics hardware|You can monitor application video RAM usage by using the Perforator tool that is included in the [WPF Performance Suite](/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100)) in the Windows SDK.|
|
||||
|Layered windows|Layered windows allow [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications to render content to the screen in a non-rectangular window. On operating systems that support Windows Display Driver Model (WDDM), such as Windows Vista and Windows 7, layered windows are hardware accelerated. On other systems, such as Windows XP, layered windows are rendered by software with no hardware acceleration.<br /><br /> You can enable layered windows in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] by setting the following <xref:System.Windows.Window> properties:<br /><br /> - <xref:System.Windows.Window.WindowStyle%2A> = <xref:System.Windows.WindowStyle.None><br />- <xref:System.Windows.Window.AllowsTransparency%2A> = `true`<br />- <xref:System.Windows.Controls.Control.Background%2A> = <xref:System.Windows.Media.Brushes.Transparent%2A>|
|
||||
|
||||
<a name="other_resources"></a>
|
||||
|
||||
## Other Resources
|
||||
|
||||
The following resources can help you analyze the performance characteristics of your [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application.
|
||||
|
||||
### Graphics Rendering Registry Settings
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides four registry settings for controlling [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] rendering:
|
||||
|
||||
|Setting|Description|
|
||||
@@ -102,6 +111,7 @@ A rendering tier defines a level of graphics hardware capability and performance
|
||||
These settings can be accessed by any external configuration utility that knows how to reference the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] registry settings. These settings can also be created or modified by accessing the values directly by using the Windows Registry Editor. For more information, see [Graphics Rendering Registry Settings](../graphics-multimedia/graphics-rendering-registry-settings.md).
|
||||
|
||||
### WPF Performance Profiling Tools
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides a suite of performance profiling tools that allow you to analyze the run-time behavior of your application and determine the types of performance optimizations you can apply. The following table lists the performance profiling tools that are included in the Windows SDK tool, WPF Performance Suite:
|
||||
|
||||
|Tool|Description|
|
||||
@@ -109,9 +119,10 @@ A rendering tier defines a level of graphics hardware capability and performance
|
||||
|Perforator|Use for analyzing rendering behavior.|
|
||||
|Visual Profiler|Use for profiling the use of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] services, such as layout and event handling, by elements in the visual tree.|
|
||||
|
||||
The WPF Performance Suite provides a rich, graphical view of performance data. For more information about WPF performance tools, see [WPF Performance Suite](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100)).
|
||||
The WPF Performance Suite provides a rich, graphical view of performance data. For more information about WPF performance tools, see [WPF Performance Suite](/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100)).
|
||||
|
||||
### DirectX Diagnostic Tool
|
||||
|
||||
The DirectX Diagnostic Tool, Dxdiag.exe, is designed to help you troubleshoot DirectX-related issues. The default installation folder for the DirectX Diagnostic Tool is:
|
||||
|
||||
`~\Windows\System32`
|
||||
@@ -126,6 +137,6 @@ DirectX Diagnostic Tool main window
|
||||
- <xref:System.Windows.Media.RenderCapability>
|
||||
- <xref:System.Windows.Media.RenderOptions>
|
||||
- [Optimizing WPF Application Performance](optimizing-wpf-application-performance.md)
|
||||
- [WPF Performance Suite](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100))
|
||||
- [WPF Performance Suite](/previous-versions/dotnet/netframework-4.0/aa969767(v=vs.100))
|
||||
- [Graphics Rendering Registry Settings](../graphics-multimedia/graphics-rendering-registry-settings.md)
|
||||
- [Animation Tips and Tricks](../graphics-multimedia/animation-tips-and-tricks.md)
|
||||
|
||||
@@ -10,10 +10,12 @@ helpviewer_keywords:
|
||||
ms.assetid: f4e8576d-e731-4bac-9818-22e2ae636636
|
||||
---
|
||||
# Handwriting Recognition
|
||||
|
||||
This section discusses the fundamentals of recognition as it pertains to digital ink in the WPF platform.
|
||||
|
||||
## Recognition Solutions
|
||||
The following example shows how to recognize ink using the [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) class.
|
||||
|
||||
The following example shows how to recognize ink using the [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) class.
|
||||
|
||||
> [!NOTE]
|
||||
> This sample requires that handwriting recognizers be installed on the system.
|
||||
@@ -29,4 +31,4 @@ This section discusses the fundamentals of recognition as it pertains to digital
|
||||
|
||||
## See also
|
||||
|
||||
- [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90))
|
||||
- [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90))
|
||||
|
||||
+4
-2
@@ -12,10 +12,12 @@ helpviewer_keywords:
|
||||
ms.assetid: d4421ed4-77f5-4640-829e-9f1de50b2ff2
|
||||
---
|
||||
# How to: Analyze Ink with Analysis Hints
|
||||
An [System.Windows.Ink.AnalysisHintNode](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) provides a hint for the [System.Windows.Ink.InkAnalyzer](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms616754(v=vs.90)) to which it is attached. The hint applies to the area specified by the [System.Windows.Ink.ContextNode.Location%2A](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms594508(v=vs.90)) property of the [System.Windows.Ink.AnalysisHintNode](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) and provides extra context to the ink analyzer to improve recognition accuracy. The [System.Windows.Ink.InkAnalyzer](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms616754(v=vs.90)) applies this context information when analyzing ink obtained from within the hint's area.
|
||||
|
||||
An [System.Windows.Ink.AnalysisHintNode](/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) provides a hint for the [System.Windows.Ink.InkAnalyzer](/previous-versions/dotnet/netframework-3.5/ms616754(v=vs.90)) to which it is attached. The hint applies to the area specified by the [System.Windows.Ink.ContextNode.Location%2A](/previous-versions/dotnet/netframework-3.5/ms594508(v=vs.90)) property of the [System.Windows.Ink.AnalysisHintNode](/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) and provides extra context to the ink analyzer to improve recognition accuracy. The [System.Windows.Ink.InkAnalyzer](/previous-versions/dotnet/netframework-3.5/ms616754(v=vs.90)) applies this context information when analyzing ink obtained from within the hint's area.
|
||||
|
||||
## Example
|
||||
The following example is an application that uses multiple [System.Windows.Ink.AnalysisHintNode](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) objects on a form that accepts ink input. The application uses the [System.Windows.Ink.AnalysisHintNode.Factoid%2A](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms594341(v=vs.90)) property to provide context information for each entry on the form. The application uses background analysis to analyze the ink and clears the form of all ink five seconds after the user stops adding ink.
|
||||
|
||||
The following example is an application that uses multiple [System.Windows.Ink.AnalysisHintNode](/previous-versions/dotnet/netframework-3.5/ms610344(v=vs.90)) objects on a form that accepts ink input. The application uses the [System.Windows.Ink.AnalysisHintNode.Factoid%2A](/previous-versions/dotnet/netframework-3.5/ms594341(v=vs.90)) property to provide context information for each entry on the form. The application uses background analysis to analyze the ink and clears the form of all ink five seconds after the user stops adding ink.
|
||||
|
||||
[!code-xaml[HowToAnalyzeInk#1](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToAnalyzeInk/CSharp/FormAnalyzer.xaml#1)]
|
||||
|
||||
|
||||
+3
-1
@@ -10,11 +10,12 @@ helpviewer_keywords:
|
||||
ms.assetid: 95de9b9c-d804-405c-b2d1-49a88c1e0fe1
|
||||
---
|
||||
# How to: Enable Visual Styles in a Hybrid Application
|
||||
|
||||
This topic shows how to enable visual styles on a Windows Forms control hosted in a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]-based application.
|
||||
|
||||
If your application calls the <xref:System.Windows.Forms.Application.EnableVisualStyles%2A> method, most of your Windows Forms controls will automatically use visual styles. For more information, see [Rendering Controls with Visual Styles](/dotnet/framework/winforms/controls/rendering-controls-with-visual-styles).
|
||||
|
||||
For a complete code listing of the tasks illustrated in this topic, see [Enabling Visual Styles in a Hybrid Application Sample](https://go.microsoft.com/fwlink/?LinkID=159986).
|
||||
For a complete code listing of the tasks illustrated in this topic, see [Enabling Visual Styles in a Hybrid Application Sample](https://github.com/microsoft/WPF-Samples/tree/master/Migration%20and%20Interoperability/HostingWfWithVisualStyles).
|
||||
|
||||
## Enabling Windows Forms Visual Styles
|
||||
|
||||
@@ -48,6 +49,7 @@ This topic shows how to enable visual styles on a Windows Forms control hosted i
|
||||
The Windows Forms control is painted with visual styles.
|
||||
|
||||
## Disabling Windows Forms Visual Styles
|
||||
|
||||
To disable visual styles, simply remove the call to the <xref:System.Windows.Forms.Application.EnableVisualStyles%2A> method.
|
||||
|
||||
#### To disable Windows Forms visual styles
|
||||
|
||||
+5
-5
@@ -13,7 +13,7 @@ ms.assetid: 0b1c0a3f-b19e-43d6-bcc9-eb3ec4e555ad
|
||||
|
||||
You can use one overload of the <xref:System.Printing.PrintQueue.AddJob%2A> method to print XML Paper Specification (XPS) files without opening a <xref:System.Windows.Controls.PrintDialog> or, in principle, any [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)] at all.
|
||||
|
||||
You can also print XPS files using the many <xref:System.Windows.Xps.XpsDocumentWriter.Write%2A?displayProperty=nameWithType> and <xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A?displayProperty=nameWithType> methods. For more information, see [Printing an XPS Document](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms771525(v=vs.90)).
|
||||
You can also print XPS files using the many <xref:System.Windows.Xps.XpsDocumentWriter.Write%2A?displayProperty=nameWithType> and <xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A?displayProperty=nameWithType> methods. For more information, see [Printing an XPS Document](/previous-versions/dotnet/netframework-3.5/ms771525(v=vs.90)).
|
||||
|
||||
Another way of printing XPS is to use the <xref:System.Windows.Controls.PrintDialog.PrintDocument%2A?displayProperty=nameWithType> or <xref:System.Windows.Controls.PrintDialog.PrintVisual%2A?displayProperty=nameWithType> methods. See [Invoke a Print Dialog](how-to-invoke-a-print-dialog.md).
|
||||
|
||||
@@ -53,7 +53,7 @@ where *\<PseudoXPSPrinter>* is any print queue. The machine must then be reboote
|
||||
This disguise will enable you to pass `true` as the final parameter of <xref:System.Printing.PrintQueue.AddJob%28System.String%2CSystem.String%2CSystem.Boolean%29> without causing an exception, but since *\<PseudoXPSPrinter>* is not really an XPSDrv printer, only garbage will print.
|
||||
|
||||
> [!NOTE]
|
||||
> For simplicity, the example above uses the presence of an \*.xps extension as its test that a file is XPS. However, XPS files do not have to have this extension. The [isXPS.exe (isXPS Conformance Tool)](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100)) is one way of testing a file for XPS validity.
|
||||
> For simplicity, the example above uses the presence of an \*.xps extension as its test that a file is XPS. However, XPS files do not have to have this extension. The [isXPS.exe (isXPS Conformance Tool)](/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100)) is one way of testing a file for XPS validity.
|
||||
|
||||
## See also
|
||||
|
||||
@@ -62,8 +62,8 @@ This disguise will enable you to pass `true` as the final parameter of <xref:Sys
|
||||
- <xref:System.Threading.ApartmentState>
|
||||
- <xref:System.STAThreadAttribute>
|
||||
- [XPS Documents](/windows/desktop/printdocs/documents)
|
||||
- [Printing an XPS Document](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms771525(v=vs.90))
|
||||
- [Managed and Unmanaged Threading](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/5s8ee185(v=vs.100))
|
||||
- [isXPS.exe (isXPS Conformance Tool)](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100))
|
||||
- [Printing an XPS Document](/previous-versions/dotnet/netframework-3.5/ms771525(v=vs.90))
|
||||
- [Managed and Unmanaged Threading](/previous-versions/dotnet/netframework-4.0/5s8ee185(v=vs.100))
|
||||
- [isXPS.exe (isXPS Conformance Tool)](/previous-versions/dotnet/netframework-4.0/aa348104(v=vs.100))
|
||||
- [Documents in WPF](documents-in-wpf.md)
|
||||
- [Printing Overview](printing-overview.md)
|
||||
|
||||
+4
-2
@@ -10,7 +10,9 @@ helpviewer_keywords:
|
||||
ms.assetid: 52682194-d7fd-499c-8005-73fcc84e7b2c
|
||||
---
|
||||
# How to: Use a ThicknessConverter Object
|
||||
|
||||
## Example
|
||||
|
||||
This example shows how to create an instance of <xref:System.Windows.ThicknessConverter> and use it to change the thickness of a border.
|
||||
|
||||
The example defines a custom method called `changeThickness`; this method first converts the contents of a <xref:System.Windows.Controls.ListBoxItem>, as defined in a separate [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] file, to an instance of <xref:System.Windows.Thickness>, and later converts the content into a <xref:System.String>. This method passes the <xref:System.Windows.Controls.ListBoxItem> to a <xref:System.Windows.ThicknessConverter> object, which converts the <xref:System.Windows.Controls.ContentControl.Content%2A> of a <xref:System.Windows.Controls.ListBoxItem> to an instance of <xref:System.Windows.Thickness>. This value is then passed back as the value of the <xref:System.Windows.Controls.Border.BorderThickness%2A> property of the <xref:System.Windows.Controls.Border>.
|
||||
@@ -25,6 +27,6 @@ ms.assetid: 52682194-d7fd-499c-8005-73fcc84e7b2c
|
||||
- <xref:System.Windows.Thickness>
|
||||
- <xref:System.Windows.ThicknessConverter>
|
||||
- <xref:System.Windows.Controls.Border>
|
||||
- [How to: Change the Margin Property](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms750561(v=vs.90))
|
||||
- [How to: Convert a ListBoxItem to a new Data Type](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms749147(v=vs.90))
|
||||
- [How to: Change the Margin Property](/previous-versions/dotnet/netframework-3.5/ms750561(v=vs.90))
|
||||
- [How to: Convert a ListBoxItem to a new Data Type](/previous-versions/dotnet/netframework-3.5/ms749147(v=vs.90))
|
||||
- [Panels Overview](../controls/panels-overview.md)
|
||||
|
||||
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 791bb2f0-4e5c-4569-ac3c-211996808d44
|
||||
---
|
||||
# Intercepting Input from the Stylus
|
||||
|
||||
The <xref:System.Windows.Input.StylusPlugIns> architecture provides a mechanism for implementing low-level control over <xref:System.Windows.Input.Stylus> input and the creation of digital ink <xref:System.Windows.Ink.Stroke> objects. The <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> class provides a mechanism for you to implement custom behavior and apply it to the stream of data coming from the stylus device for the optimal performance.
|
||||
|
||||
This topic contains the following subsections:
|
||||
@@ -25,15 +26,19 @@ The <xref:System.Windows.Input.StylusPlugIns> architecture provides a mechanism
|
||||
- [Conclusion](#Conclusion)
|
||||
|
||||
<a name="Architecture"></a>
|
||||
|
||||
## Architecture
|
||||
The <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> is the evolution of the [StylusInput](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms574861(v=vs.90)) APIs, described in [Accessing and Manipulating Pen Input](https://docs.microsoft.com/previous-versions/ms818317(v%3dmsdn.10)).
|
||||
|
||||
The <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> is the evolution of the [StylusInput](/previous-versions/dotnet/netframework-3.5/ms574861(v=vs.90)) APIs, described in [Accessing and Manipulating Pen Input](/previous-versions/ms818317(v%3dmsdn.10)).
|
||||
|
||||
Each <xref:System.Windows.UIElement> has a <xref:System.Windows.UIElement.StylusPlugIns%2A> property that is a <xref:System.Windows.Input.StylusPlugIns.StylusPlugInCollection>. You can add a <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> to an element's <xref:System.Windows.UIElement.StylusPlugIns%2A> property to manipulate <xref:System.Windows.Input.StylusPoint> data as it is generated. <xref:System.Windows.Input.StylusPoint> data consists of all the properties supported by the system digitizer, including the <xref:System.Windows.Input.StylusPoint.X%2A> and <xref:System.Windows.Input.StylusPoint.Y%2A> point data, as well as <xref:System.Windows.Input.StylusPoint.PressureFactor%2A> data.
|
||||
|
||||
Your <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> objects are inserted directly into the stream of data coming from the <xref:System.Windows.Input.Stylus> device when you add the <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> to the <xref:System.Windows.UIElement.StylusPlugIns%2A> property. The order in which plug-ins are added to the <xref:System.Windows.UIElement.StylusPlugIns%2A> collection dictates the order in which they will receive <xref:System.Windows.Input.StylusPoint> data. For example, if you add a filter plug-in that restricts input to a particular region, and then add a plug-in that recognizes gestures as they are written, the plug-in that recognizes gestures will receive filtered <xref:System.Windows.Input.StylusPoint> data.
|
||||
|
||||
<a name="ImplementingStylusPlugins"></a>
|
||||
|
||||
## Implementing Stylus Plug-ins
|
||||
|
||||
To implement a plug-in, derive a class from <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn>. This class is applied o the stream of data as it comes in from the <xref:System.Windows.Input.Stylus>. In this class you can modify the values of the <xref:System.Windows.Input.StylusPoint> data.
|
||||
|
||||
> [!CAUTION]
|
||||
@@ -47,7 +52,9 @@ The <xref:System.Windows.Input.StylusPlugIns> architecture provides a mechanism
|
||||
[!code-vb[AdvancedInkTopicsSamples#3](~/samples/snippets/visualbasic/VS_Snippets_Wpf/AdvancedInkTopicsSamples/VisualBasic/DynamicRenderer.vb#3)]
|
||||
|
||||
<a name="AddingYourPluginToAnInkCanvas"></a>
|
||||
|
||||
## Adding Your Plug-in to an InkCanvas
|
||||
|
||||
The easiest way to use your custom plug-in is to implement a class that derives from InkCanvas and add it to the <xref:System.Windows.UIElement.StylusPlugIns%2A> property.
|
||||
|
||||
The following example demonstrates a custom <xref:System.Windows.Controls.InkCanvas> that filters the ink.
|
||||
@@ -61,10 +68,12 @@ The <xref:System.Windows.Input.StylusPlugIns> architecture provides a mechanism
|
||||
[!code-csharp[AdvancedInkTopicsSamples#5](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/Window1.xaml.cs#5)]
|
||||
|
||||
<a name="Conclusion"></a>
|
||||
|
||||
## Conclusion
|
||||
|
||||
By deriving your own <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> classes and inserting them into <xref:System.Windows.Input.StylusPlugIns.StylusPlugInCollection> collections, you can greatly enhance the behavior of your digital ink. You have access to the <xref:System.Windows.Input.StylusPoint> data as it is generated, giving you the opportunity to customize the <xref:System.Windows.Input.Stylus> input. Because you have such low-level access to the <xref:System.Windows.Input.StylusPoint> data, you can implement ink collection and rendering with optimal performance for your application.
|
||||
|
||||
## See also
|
||||
|
||||
- [Advanced Ink Handling](advanced-ink-handling.md)
|
||||
- [Accessing and Manipulating Pen Input](https://docs.microsoft.com/previous-versions/ms818317(v%3dmsdn.10))
|
||||
- [Accessing and Manipulating Pen Input](/previous-versions/ms818317(v%3dmsdn.10))
|
||||
|
||||
@@ -7,6 +7,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 2689b2c8-b4dc-4b71-b9bd-f95e619122d7
|
||||
---
|
||||
# mc:ProcessContent Attribute
|
||||
|
||||
Specifies which [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] elements should still have content processed by relevant parent elements, even if the immediate parent element may be ignored by a [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] processor due to specifying [mc:Ignorable Attribute](mc-ignorable-attribute.md). The `mc:ProcessContent` attribute supports markup compatibility both for custom namespace mapping and for [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] versioning.
|
||||
|
||||
## XAML Attribute Usage
|
||||
@@ -34,11 +35,12 @@ Specifies which [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.
|
||||
|*[content]*|*ThisElementCanBeIgnored* is marked ignorable. If the processor ignores that element, *[content]* is processed by *object*.|
|
||||
|
||||
## Remarks
|
||||
|
||||
By default, a [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] processor will ignore content within an ignored element. You can specify a specific element by `mc:ProcessContent`, and a [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] processor will continue to process the content within the ignored element. This would typically be used if the content is nested within several tags, at least one of which is ignorable and at least one of which is not ignorable.
|
||||
|
||||
Multiple prefixes may be specified in the attribute, using a space separator, for example: `mc:ProcessContent="ignore:Element1 ignore:Element2"`.
|
||||
|
||||
The `http://schemas.openxmlformats.org/markup-compatibility/2006` namespace defines other elements and attributes that are not documented within this area of the SDK. For more information, see [XML Markup Compatibility Specification](https://docs.microsoft.com/office/open-xml/introduction-to-markup-compatibility#markup-compatibility-in-the-open-xml-file-formats-specification).
|
||||
The `http://schemas.openxmlformats.org/markup-compatibility/2006` namespace defines other elements and attributes that are not documented within this area of the SDK. For more information, see [XML Markup Compatibility Specification](/office/open-xml/introduction-to-markup-compatibility#markup-compatibility-in-the-open-xml-file-formats-specification).
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ ms.assetid: 4061a9d1-fe8b-4921-9e17-18ec7d2e3ea2
|
||||
This topic provides an overview of some of the key features of OpenType font technology in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)].
|
||||
|
||||
<a name="overview"></a>
|
||||
|
||||
## OpenType Font Format
|
||||
|
||||
The OpenType font format is an extension of the TrueType® font format, adding support for PostScript font data. The OpenType font format was developed jointly by Microsoft and Adobe Corporation. OpenType fonts and the operating system services which support OpenType fonts provide users with a simple way to install and use fonts, whether the fonts contain TrueType outlines or CFF (PostScript) outlines.
|
||||
|
||||
The OpenType font format addresses the following developer challenges:
|
||||
@@ -33,9 +35,10 @@ This topic provides an overview of some of the key features of OpenType font tec
|
||||
> [!NOTE]
|
||||
> The Windows SDK contains a set of sample OpenType fonts that you can use with [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] applications. These fonts provide most of the features illustrated in the rest of this topic. For more information, see [Sample OpenType Font Pack](sample-opentype-font-pack.md).
|
||||
|
||||
For details of the OpenType font format, see the [OpenType specification](https://docs.microsoft.com/typography/opentype/spec/).
|
||||
For details of the OpenType font format, see the [OpenType specification](/typography/opentype/spec/).
|
||||
|
||||
### Advanced Typographic Extensions
|
||||
|
||||
The Advanced Typographic tables (OpenType Layout tables) extend the functionality of fonts with either TrueType or CFF outlines. OpenType Layout fonts contain additional information that extends the capabilities of the fonts to support high-quality international typography. Most OpenType fonts expose only a subset of the total OpenType features available. OpenType fonts provide the following features.
|
||||
|
||||
- Rich mapping between characters and glyphs that support ligatures, positional forms, alternates, and other font substitutions.
|
||||
@@ -49,10 +52,13 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
The remainder of this overview introduces the breadth and flexibility of some of the visually-interesting OpenType features that are exposed by the properties of the <xref:System.Windows.Documents.Typography> object. For more information on this object, see [Typography Class](#typography_class).
|
||||
|
||||
<a name="variants"></a>
|
||||
|
||||
## Variants
|
||||
|
||||
Variants are used to render different typographic styles, such as superscripts and subscripts.
|
||||
|
||||
### Superscripts and Subscripts
|
||||
|
||||
The <xref:System.Windows.Documents.Typography.Variants%2A> property allows you to set superscript and subscript values for an OpenType font.
|
||||
|
||||
The following text displays superscripts for the Palatino Linotype font.
|
||||
@@ -72,6 +78,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#13](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#13)]
|
||||
|
||||
### Decorative Uses of Superscripts and Subscripts
|
||||
|
||||
You can also use superscripts and subscripts to create decorative effects of mixed case text. The following text displays superscript and subscript text for the Palatino Linotype font. Note that the capitals are not affected.
|
||||
|
||||

|
||||
@@ -81,7 +88,9 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#14](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#14)]
|
||||
|
||||
<a name="capitals"></a>
|
||||
|
||||
## Capitals
|
||||
|
||||
Capitals are a set of typographical forms that render text in capital-styled glyphs. Typically, when text is rendered as all capitals, the spacing between letters can appear too tight, and the weight and proportion of the letters too heavy. OpenType supports a number of styling formats for capitals, including small capitals, petite capitals, titling, and capital spacing. These styling formats allow you to control the appearance of capitals.
|
||||
|
||||
The following text displays standard capital letters for the Pescadero font, followed by the letters styled as "SmallCaps" and "AllSmallCaps". In this case, the same font size is used for all three words.
|
||||
@@ -93,6 +102,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#9](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#9)]
|
||||
|
||||
### Titling Capitals
|
||||
|
||||
Titling capitals are lighter in weight and proportion and designed to give a more elegant look than normal capitals. Titling capitals are typically used in larger font sizes as headings. The following text displays normal and titling capitals for the Pescadero font. Notice the narrower stem widths of the text on the second line.
|
||||
|
||||

|
||||
@@ -102,6 +112,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet17](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#opentypefontsnippet17)]
|
||||
|
||||
### Capital Spacing
|
||||
|
||||
Capital spacing is a feature that allows you to provide more spacing when using all capitals in text. Capital letters are typically designed to blend with lowercase letters. Spacing that appears attractive between and a capital letter and a lowercase letter may look too tight when all capital letters are used. The following text displays normal and capital spacing for the Pescadero font.
|
||||
|
||||

|
||||
@@ -111,7 +122,9 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet18](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#opentypefontsnippet18)]
|
||||
|
||||
<a name="ligatures"></a>
|
||||
|
||||
## Ligatures
|
||||
|
||||
Ligatures are two or more glyphs that are formed into a single glyph in order to create more readable or attractive text. OpenType fonts support four types of ligatures:
|
||||
|
||||
- **Standard ligatures**. Designed to enhance readability. Standard ligatures include "fi", "fl", and "ff".
|
||||
@@ -151,7 +164,9 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#6](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#6)]
|
||||
|
||||
<a name="swashes"></a>
|
||||
|
||||
## Swashes
|
||||
|
||||
Swashes are decorative glyphs that use elaborate ornamentation often associated with calligraphy. The following text displays standard and swash glyphs for the Pescadero font.
|
||||
|
||||

|
||||
@@ -165,6 +180,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#7](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#7)]
|
||||
|
||||
### Contextual Swashes
|
||||
|
||||
Certain combinations of swash glyphs can cause an unattractive appearance, such as overlapping descenders on adjacent letters. Using a contextual swash allows you to use a substitute swash glyph that produces a better appearance. The following text shows the same word before and after a contextual swash is applied.
|
||||
|
||||

|
||||
@@ -174,7 +190,9 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet16](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#opentypefontsnippet16)]
|
||||
|
||||
<a name="alternates"></a>
|
||||
|
||||
## Alternates
|
||||
|
||||
Alternates are glyphs that can be substituted for a standard glyph. OpenType fonts, such as the Pericles font used in the following examples, can contain alternate glyphs that you can use to create different appearances for text. The following text displays standard glyphs for the Pericles font.
|
||||
|
||||

|
||||
@@ -196,6 +214,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#3](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#3)]
|
||||
|
||||
### Random Contextual Alternates
|
||||
|
||||
Random contextual alternates provide multiple substitute glyphs for a single character. When implemented with script-type fonts, this feature can simulate handwriting by using of a set of randomly chosen glyphs with slight differences in appearance. The following text uses random contextual alternates for the Lindsey font. Notice that the letter "a" varies slightly in appearance
|
||||
|
||||

|
||||
@@ -205,6 +224,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet20](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/Window1.xaml#opentypefontsnippet20)]
|
||||
|
||||
### Historical Forms
|
||||
|
||||
Historical forms are typographic conventions that were common in the past. The following text displays the phrase, "Boston, Massachusetts", using an historical form of glyphs for the Palatino Linotype font.
|
||||
|
||||

|
||||
@@ -214,10 +234,13 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#8](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#8)]
|
||||
|
||||
<a name="numerical_styles"></a>
|
||||
|
||||
## Numerical Styles
|
||||
|
||||
OpenType fonts support a large number of features that can be used with numerical values in text.
|
||||
|
||||
### Fractions
|
||||
|
||||
OpenType fonts support styles for fractions, including slashed and stacked.
|
||||
|
||||
The following text displays fraction styles for the Palatino Linotype font.
|
||||
@@ -229,6 +252,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#10](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#10)]
|
||||
|
||||
### Old Style Numerals
|
||||
|
||||
OpenType fonts support an old style numeral format. This format is useful for displaying numerals in styles that are no longer standard. The following text displays an 18th century date in standard and old style numeral formats for the Palatino Linotype font.
|
||||
|
||||

|
||||
@@ -242,6 +266,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#11](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#11)]
|
||||
|
||||
### Proportional and Tabular Figures
|
||||
|
||||
OpenType fonts support a proportional and tabular figure feature to control the alignment of widths when using numerals. Proportional figures treat each numeral as having a different width—"1" is narrower than "5". Tabular figures are treated as equal-width numerals so that they align vertically, which increases the readability of financial type information.
|
||||
|
||||
The following text displays two proportional figures in the first column using the Miramonte font. Note the difference in width between the numerals "5" and "1". The second column shows the same two numeric values with the widths adjusted by using the tabular figure feature.
|
||||
@@ -253,6 +278,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet19](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/Window1.xaml#opentypefontsnippet19)]
|
||||
|
||||
### Slashed Zero
|
||||
|
||||
OpenType fonts support a slashed zero numeral format to emphasize the difference between the letter "O" and the numeral "0". The slashed zero numeral is often used for identifiers in financial and business information.
|
||||
|
||||
The following text displays a sample order identifier using the Miramonte font. The first line uses standard numerals. The second line used slashed zero numerals to provide better contrast with the uppercase "O" letter.
|
||||
@@ -264,7 +290,9 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-xaml[OpenTypeFontSamples#OpenTypeFontSnippet15](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontSamples/CS/PageOne.xaml#opentypefontsnippet15)]
|
||||
|
||||
<a name="typography_class"></a>
|
||||
|
||||
## Typography Class
|
||||
|
||||
The <xref:System.Windows.Documents.Typography> object exposes the set of features that an OpenType font supports. By setting the properties of <xref:System.Windows.Documents.Typography> in markup, you can easily author documents that take advantage of OpenType features.
|
||||
|
||||
The following text displays standard capital letters for the Pescadero font, followed by the letters styled as "SmallCaps" and "AllSmallCaps". In this case, the same font size is used for all three words.
|
||||
@@ -281,6 +309,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
[!code-vb[TypographyCodeSnippets#TypographyCodeSnippet1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/TypographyCodeSnippets/visualbasic/page1.xaml.vb#typographycodesnippet1)]
|
||||
|
||||
### Typography Class Properties
|
||||
|
||||
The following table lists the properties, values, and default settings of the <xref:System.Windows.Documents.Typography> object.
|
||||
|
||||
|Property|Value(s)|Default Value|
|
||||
@@ -332,7 +361,7 @@ For details of the OpenType font format, see the [OpenType specification](https:
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.Documents.Typography>
|
||||
- [OpenType specification](https://docs.microsoft.com/typography/opentype/spec/)
|
||||
- [OpenType specification](/typography/opentype/spec/)
|
||||
- [Typography in WPF](typography-in-wpf.md)
|
||||
- [Sample OpenType Font Pack](sample-opentype-font-pack.md)
|
||||
- [Packaging Fonts with Applications](packaging-fonts-with-applications.md)
|
||||
|
||||
+16
-1
@@ -13,39 +13,51 @@ helpviewer_keywords:
|
||||
ms.assetid: 73aa2f47-1d73-439a-be1f-78dc4ba2b5bd
|
||||
---
|
||||
# Optimizing Performance: Object Behavior
|
||||
|
||||
Understanding the intrinsic behavior of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] objects will help you make the right tradeoffs between functionality and performance.
|
||||
|
||||
<a name="Not_Removing_Event_Handlers"></a>
|
||||
|
||||
## Not Removing Event Handlers on Objects may Keep Objects Alive
|
||||
|
||||
The delegate that an object passes to its event is effectively a reference to that object. Therefore, event handlers can keep objects alive longer than expected. When performing clean up of an object that has registered to listen to an object's event, it is essential to remove that delegate before releasing the object. Keeping unneeded objects alive increases the application's memory usage. This is especially true when the object is the root of a logical tree or a visual tree.
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] introduces a weak event listener pattern for events that can be useful in situations where the object lifetime relationships between source and listener are difficult to keep track of. Some existing [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] events use this pattern. If you are implementing objects with custom events, this pattern may be of use to you. For details, see [Weak Event Patterns](weak-event-patterns.md).
|
||||
|
||||
There are several tools, such as the CLR Profiler and the Working Set Viewer, that can provides information on the memory usage of a specified process. The CLR Profiler includes a number of very useful views of the allocation profile, including a histogram of allocated types, allocation and call graphs, a time line showing garbage collections of various generations and the resulting state of the managed heap after those collections, and a call tree showing per-method allocations and assembly loads. For more information, see [Performance](https://docs.microsoft.com/previous-versions/aa497289(v=msdn.10)).
|
||||
There are several tools, such as the CLR Profiler and the Working Set Viewer, that can provides information on the memory usage of a specified process. The CLR Profiler includes a number of very useful views of the allocation profile, including a histogram of allocated types, allocation and call graphs, a time line showing garbage collections of various generations and the resulting state of the managed heap after those collections, and a call tree showing per-method allocations and assembly loads. For more information, see [Performance](/previous-versions/aa497289(v=msdn.10)).
|
||||
|
||||
<a name="DPs_and_Objects"></a>
|
||||
|
||||
## Dependency Properties and Objects
|
||||
|
||||
In general, accessing a dependency property of a <xref:System.Windows.DependencyObject> is not slower than accessing a CLR property. While there is a small performance overhead for setting a property value, getting a value is as fast as getting the value from a CLR property. Offsetting the small performance overhead is the fact that dependency properties support robust features, such as data binding, animation, inheritance, and styling. For more information, see [Dependency Properties Overview](dependency-properties-overview.md).
|
||||
|
||||
### DependencyProperty Optimizations
|
||||
|
||||
You should define dependency properties in your application very carefully. If your <xref:System.Windows.DependencyProperty> affects only render type metadata options, rather than other metadata options such as <xref:System.Windows.FrameworkPropertyMetadata.AffectsMeasure%2A>, you should mark it as such by overriding its metadata. For more information about overriding or obtaining property metadata, see [Dependency Property Metadata](dependency-property-metadata.md).
|
||||
|
||||
It may be more efficient to have a property change handler invalidate the measure, arrange, and render passes manually if not all property changes actually affect measure, arrange, and render. For instance, you might decide to re-render a background only when a value is greater than a set limit. In this case, your property change handler would only invalidate render when the value exceeds the set limit.
|
||||
|
||||
### Making a DependencyProperty Inheritable is Not Free
|
||||
|
||||
By default, registered dependency properties are non-inheritable. However, you can explicitly make any property inheritable. While this is a useful feature, converting a property to be inheritable impacts performance by increasing the length of time for property invalidation.
|
||||
|
||||
### Use RegisterClassHandler Carefully
|
||||
|
||||
While calling <xref:System.Windows.EventManager.RegisterClassHandler%2A> allows you to save your instance state, it is important to be aware that the handler is called on every instance, which can cause performance problems. Only use <xref:System.Windows.EventManager.RegisterClassHandler%2A> when your application requires that you save your instance state.
|
||||
|
||||
### Set the Default Value for a DependencyProperty during Registration
|
||||
|
||||
When creating a <xref:System.Windows.DependencyProperty> that requires a default value, set the value using the default metadata passed as a parameter to the <xref:System.Windows.DependencyProperty.Register%2A> method of the <xref:System.Windows.DependencyProperty>. Use this technique rather than setting the property value in a constructor or on each instance of an element.
|
||||
|
||||
### Set the PropertyMetadata Value using Register
|
||||
|
||||
When creating a <xref:System.Windows.DependencyProperty>, you have the option of setting the <xref:System.Windows.PropertyMetadata> using either the <xref:System.Windows.DependencyProperty.Register%2A> or <xref:System.Windows.DependencyProperty.OverrideMetadata%2A> methods. Although your object could have a static constructor to call <xref:System.Windows.DependencyProperty.OverrideMetadata%2A>, this is not the optimal solution and will impact performance. For best performance, set the <xref:System.Windows.PropertyMetadata> during the call to <xref:System.Windows.DependencyProperty.Register%2A>.
|
||||
|
||||
<a name="Freezable_Objects"></a>
|
||||
|
||||
## Freezable Objects
|
||||
|
||||
A <xref:System.Windows.Freezable> is a special type of object that has two states: unfrozen and frozen. Freezing objects whenever possible improves the performance of your application and reduces its working set. For more information, see [Freezable Objects Overview](freezable-objects-overview.md).
|
||||
|
||||
Each <xref:System.Windows.Freezable> has a <xref:System.Windows.Freezable.Changed> event that is raised whenever it changes. However, change notifications are costly in terms of application performance.
|
||||
@@ -70,6 +82,7 @@ Understanding the intrinsic behavior of [!INCLUDE[TLA2#tla_winclient](../../../i
|
||||
[!code-vb[Performance#PerformanceSnippet3](~/samples/snippets/visualbasic/VS_Snippets_Wpf/Performance/visualbasic/window1.xaml.vb#performancesnippet3)]
|
||||
|
||||
### Changed Handlers on Unfrozen Freezables may Keep Objects Alive
|
||||
|
||||
The delegate that an object passes to a <xref:System.Windows.Freezable> object's <xref:System.Windows.Freezable.Changed> event is effectively a reference to that object. Therefore, <xref:System.Windows.Freezable.Changed> event handlers can keep objects alive longer than expected. When performing clean up of an object that has registered to listen to a <xref:System.Windows.Freezable> object's <xref:System.Windows.Freezable.Changed> event, it is essential to remove that delegate before releasing the object.
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] also hooks up <xref:System.Windows.Freezable.Changed> events internally. For example, all dependency properties which take <xref:System.Windows.Freezable> as a value will listen to <xref:System.Windows.Freezable.Changed> events automatically. The <xref:System.Windows.Shapes.Shape.Fill%2A> property, which takes a <xref:System.Windows.Media.Brush>, illustrates this concept.
|
||||
@@ -90,7 +103,9 @@ Understanding the intrinsic behavior of [!INCLUDE[TLA2#tla_winclient](../../../i
|
||||
[!code-vb[Performance#PerformanceSnippet6](~/samples/snippets/visualbasic/VS_Snippets_Wpf/Performance/visualbasic/window1.xaml.vb#performancesnippet6)]
|
||||
|
||||
<a name="User_Interface_Virtualization"></a>
|
||||
|
||||
## User Interface Virtualization
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] also provides a variation of the <xref:System.Windows.Controls.StackPanel> element that automatically "virtualizes" data-bound child content. In this context, the word virtualize refers to a technique by which a subset of objects are generated from a larger number of data items based upon which items are visible on-screen. It is intensive, both in terms of memory and processor, to generate a large number of UI elements when only a few may be on the screen at a given time. <xref:System.Windows.Controls.VirtualizingStackPanel> (through functionality provided by <xref:System.Windows.Controls.VirtualizingPanel>) calculates visible items and works with the <xref:System.Windows.Controls.ItemContainerGenerator> from an <xref:System.Windows.Controls.ItemsControl> (such as <xref:System.Windows.Controls.ListBox> or <xref:System.Windows.Controls.ListView>) to only create elements for visible items.
|
||||
|
||||
As a performance optimization, visual objects for these items are only generated or kept alive if they are visible on the screen. When they are no longer in the viewable area of the control, the visual objects may be removed. This is not to be confused with data virtualization, where data objects are not all present in the local collection- rather streamed in as needed.
|
||||
|
||||
@@ -13,21 +13,26 @@ helpviewer_keywords:
|
||||
ms.assetid: db15ee48-4d24-49f5-8b9d-a64460865286
|
||||
---
|
||||
# Packaging Fonts with Applications
|
||||
|
||||
This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] application.
|
||||
|
||||
> [!NOTE]
|
||||
> As with most types of software, font files are licensed, rather than sold. Licenses that govern the use of fonts vary from vendor to vendor but in general most licenses, including those covering the fonts Microsoft supplies with applications and Windows, do not allow the fonts to be embedded within applications or otherwise redistributed. Therefore, as a developer it is your responsibility to ensure that you have the required license rights for any font you embed within an application or otherwise redistribute.
|
||||
|
||||
<a name="introduction_to_packaging_fonts"></a>
|
||||
|
||||
## Introduction to Packaging Fonts
|
||||
|
||||
You can easily package fonts as resources within your [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications to display user interface text and other types of text based content. The fonts can be separate from or embedded within the application's assembly files. You can also create a resource-only font library, which your application can reference.
|
||||
|
||||
OpenType and TrueType® fonts contain a type flag, fsType, that indicates font embedding licensing rights for the font. However, this type flag only refers to embedded fonts stored in a document–it does not refer to fonts embedded in an application. You can retrieve the font embedding rights for a font by creating a <xref:System.Windows.Media.GlyphTypeface> object and referencing its <xref:System.Windows.Media.GlyphTypeface.EmbeddingRights%2A> property. Refer to the "OS/2 and Windows Metrics" section of the [OpenType Specification](https://www.microsoft.com/typography/otspec/os2.htm) for more information on the fsType flag.
|
||||
|
||||
The [Microsoft Typography](https://docs.microsoft.com/typography/) Web site includes contact information that can help you locate a particular font vendor or find a font vendor for custom work.
|
||||
The [Microsoft Typography](/typography/) Web site includes contact information that can help you locate a particular font vendor or find a font vendor for custom work.
|
||||
|
||||
<a name="adding_fonts_as_content_items"></a>
|
||||
|
||||
## Adding Fonts as Content Items
|
||||
|
||||
You can add fonts to your application as project content items that are separate from the application's assembly files. This means that content items are not embedded as resources within an assembly. The following project file example shows how to define content items.
|
||||
|
||||
```xml
|
||||
@@ -60,7 +65,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-xaml[FontSnippets#FontPackageSnippet8](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml#fontpackagesnippet8)]
|
||||
|
||||
<a name="adding_fonts_as_resource_items"></a>
|
||||
|
||||
## Adding Fonts as Resource Items
|
||||
|
||||
You can add fonts to your application as project resource items that are embedded within the application's assembly files. Using a separate subdirectory for resources helps to organize the application's project files. The following project file example shows how to define fonts as resource items in a separate subdirectory.
|
||||
|
||||
```xml
|
||||
@@ -83,6 +90,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-xaml[FontSnippets#FontPackageSnippet1](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml#fontpackagesnippet1)]
|
||||
|
||||
### Referencing Font Resource Items from Code
|
||||
|
||||
In order to reference font resource items from code, you must supply a two-part font resource reference: the base uniform resource identifier (URI); and the font location reference. These values are used as the parameters for the <xref:System.Windows.Media.FontFamily.%23ctor%2A> method. The following code example shows how to reference the application's font resources in the project subdirectory called `resources`.
|
||||
|
||||
[!code-csharp[FontSnippets#FontPackageSnippet2](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml.cs#fontpackagesnippet2)]
|
||||
@@ -94,6 +102,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontPackageSnippet5](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/fontpackagesnippets.xaml.vb#fontpackagesnippet5)]
|
||||
|
||||
### Referencing Fonts from the Same Application Subdirectory
|
||||
|
||||
You can place both application content and resource files within the same user-defined subdirectory of your application project. The following project file example shows a content page and font resources defined in the same subdirectory.
|
||||
|
||||
```xml
|
||||
@@ -114,6 +123,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontPackageSnippet4](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/pages/homepage.xaml.vb#fontpackagesnippet4)]
|
||||
|
||||
### Enumerating Fonts in an Application
|
||||
|
||||
To enumerate fonts as resource items in your application, use either the <xref:System.Windows.Media.Fonts.GetFontFamilies%2A> or <xref:System.Windows.Media.Fonts.GetTypefaces%2A> method. The following example shows how to use the <xref:System.Windows.Media.Fonts.GetFontFamilies%2A> method to return the collection of <xref:System.Windows.Media.FontFamily> objects from the application font location. In this case, the application contains a subdirectory named "resources".
|
||||
|
||||
[!code-csharp[FontSnippets#FontsSnippet3](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontFamilySnippets.xaml.cs#fontssnippet3)]
|
||||
@@ -125,7 +135,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontsSnippet7](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/fontfamilysnippets.xaml.vb#fontssnippet7)]
|
||||
|
||||
<a name="creating_a_font_resource_library"></a>
|
||||
|
||||
## Creating a Font Resource Library
|
||||
|
||||
You can create a resource-only library that contains only fonts—no code is part of this type of library project. Creating a resource-only library is a common technique for decoupling resources from the application code that uses them. This also allows the library assembly to be included with multiple application projects. The following project file example shows the key portions of a resource-only library project.
|
||||
|
||||
```xml
|
||||
@@ -142,6 +154,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
```
|
||||
|
||||
### Referencing a Font in a Resource Library
|
||||
|
||||
To reference a font in a resource library from your application, you must prefix the font reference with the name of the library assembly. In this case, the font resource assembly is "FontLibrary". To separate the assembly name from the reference within the assembly, use a ';' character. Adding the "Component" keyword followed by the reference to the font name completes the full reference to the font library's resource. The following code example shows how to reference a font in a resource library assembly.
|
||||
|
||||
[!code-xaml[OpenTypeFontsSample#OpenTypeFontsSample1](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontsSample/CS/Kootenay.xaml#opentypefontssample1)]
|
||||
@@ -150,7 +163,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
> This SDK contains a set of sample OpenType fonts that you can use with [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications. The fonts are defined in a resource-only library. For more information, see [Sample OpenType Font Pack](sample-opentype-font-pack.md).
|
||||
|
||||
<a name="limitations_on_font_usage"></a>
|
||||
|
||||
## Limitations on Font Usage
|
||||
|
||||
The following list describes several limitations on the packaging and use of fonts in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications:
|
||||
|
||||
- **Font embedding permission bits:** [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications do not check or enforce any font embedding permission bits. See the [Introduction_to_Packing Fonts](#introduction_to_packaging_fonts) section for more information.
|
||||
@@ -169,7 +184,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
|
||||
- <xref:System.Windows.Documents.Typography>
|
||||
- <xref:System.Windows.Media.FontFamily>
|
||||
- [Microsoft Typography: Links, News, and Contacts](https://docs.microsoft.com/typography/)
|
||||
- [Microsoft Typography: Links, News, and Contacts](/typography/)
|
||||
- [OpenType Specification](https://www.microsoft.com/typography/otspec/)
|
||||
- [OpenType Font Features](opentype-font-features.md)
|
||||
- [Sample OpenType Font Pack](sample-opentype-font-pack.md)
|
||||
|
||||
+18
-13
@@ -19,7 +19,8 @@ ms.assetid: 577835be-b145-4226-8570-1d309e9b3901
|
||||
There are essentially three platforms that support digital ink: the Tablet PC Windows Forms platform, the Tablet PC COM platform, and the Windows Presentation Foundation (WPF) platform. The Windows Forms and COM platforms share a similar object model, but the object model for the WPF platform is substantially different. This topic discusses the differences at a high-level so that developers that have worked with one object model can better understand the other.
|
||||
|
||||
## Enabling Ink in an Application
|
||||
All three platforms ship objects and controls that enable an application to receive input from a tablet pen. The Windows Forms and COM platforms ship with [Microsoft.Ink.InkPicture](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)), [Microsoft.Ink.InkEdit](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)), [Microsoft.Ink.InkOverlay](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) and [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) classes. [Microsoft.Ink.InkPicture](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) and [Microsoft.Ink.InkEdit](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)) are controls that you can add to an application to collect ink. The [Microsoft.Ink.InkOverlay](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) and [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) can be attached to an existing window to ink-enable windows and custom controls.
|
||||
|
||||
All three platforms ship objects and controls that enable an application to receive input from a tablet pen. The Windows Forms and COM platforms ship with [Microsoft.Ink.InkPicture](/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)), [Microsoft.Ink.InkEdit](/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)), [Microsoft.Ink.InkOverlay](/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) and [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) classes. [Microsoft.Ink.InkPicture](/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) and [Microsoft.Ink.InkEdit](/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)) are controls that you can add to an application to collect ink. The [Microsoft.Ink.InkOverlay](/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) and [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) can be attached to an existing window to ink-enable windows and custom controls.
|
||||
|
||||
The WPF platform includes the <xref:System.Windows.Controls.InkCanvas> control. You can add an <xref:System.Windows.Controls.InkCanvas> to your application and begin collecting ink immediately. With the <xref:System.Windows.Controls.InkCanvas>, the user can copy, select, and resize ink. You can add other controls to the <xref:System.Windows.Controls.InkCanvas>, and the user can handwrite over those controls, too. You can create an ink-enabled custom control by adding an <xref:System.Windows.Controls.InkPresenter> to it and collecting its stylus points.
|
||||
|
||||
@@ -31,11 +32,12 @@ There are essentially three platforms that support digital ink: the Tablet PC Wi
|
||||
|Enable ink on a custom control|See [Creating an Ink Input Control](creating-an-ink-input-control.md).|See [Ink Clipboard Sample](/windows/desktop/tablet/ink-clipboard-sample).|
|
||||
|
||||
## Ink Data
|
||||
On the Windows Forms and COM platforms, [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)), [Microsoft.Ink.InkOverlay](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)), [Microsoft.Ink.InkEdit](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)), and [Microsoft.Ink.InkPicture](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) each expose a [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object. The [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object contains the data for one or more [Microsoft.Ink.Stroke](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) objects and exposes common methods and properties to manage and manipulate those strokes. The [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object manages the lifetime of the strokes it contains; the [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object creates and deletes the strokes that it owns. Each [Microsoft.Ink.Stroke](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) has an identifier that is unique within its parent [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object.
|
||||
|
||||
On the Windows Forms and COM platforms, [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)), [Microsoft.Ink.InkOverlay](/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)), [Microsoft.Ink.InkEdit](/previous-versions/dotnet/netframework-3.5/ms552265(v=vs.90)), and [Microsoft.Ink.InkPicture](/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) each expose a [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object. The [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object contains the data for one or more [Microsoft.Ink.Stroke](/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) objects and exposes common methods and properties to manage and manipulate those strokes. The [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object manages the lifetime of the strokes it contains; the [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object creates and deletes the strokes that it owns. Each [Microsoft.Ink.Stroke](/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) has an identifier that is unique within its parent [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object.
|
||||
|
||||
On the WPF platform, the <xref:System.Windows.Ink.Stroke?displayProperty=nameWithType> class owns and manages its own lifetime. A group of <xref:System.Windows.Ink.Stroke> objects can be collected together in a <xref:System.Windows.Ink.StrokeCollection>, which provides methods for common ink data management operations such as hit testing, erasing, transforming, and serializing the ink. A <xref:System.Windows.Ink.Stroke> can belong to zero, one, or more <xref:System.Windows.Ink.StrokeCollection> objects at any give time. Instead of having a [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object, the <xref:System.Windows.Controls.InkCanvas> and <xref:System.Windows.Controls.InkPresenter> contain a <xref:System.Windows.Ink.StrokeCollection?displayProperty=nameWithType>.
|
||||
On the WPF platform, the <xref:System.Windows.Ink.Stroke?displayProperty=nameWithType> class owns and manages its own lifetime. A group of <xref:System.Windows.Ink.Stroke> objects can be collected together in a <xref:System.Windows.Ink.StrokeCollection>, which provides methods for common ink data management operations such as hit testing, erasing, transforming, and serializing the ink. A <xref:System.Windows.Ink.Stroke> can belong to zero, one, or more <xref:System.Windows.Ink.StrokeCollection> objects at any give time. Instead of having a [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object, the <xref:System.Windows.Controls.InkCanvas> and <xref:System.Windows.Controls.InkPresenter> contain a <xref:System.Windows.Ink.StrokeCollection?displayProperty=nameWithType>.
|
||||
|
||||
The following pair of illustrations compares the ink data object models. On the Windows Forms and COM platforms, the [Microsoft.Ink.Ink](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object constrains the lifetime of the [Microsoft.Ink.Stroke](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) objects, and the stylus packets belong to the individual strokes. Two or more strokes can reference the same [Microsoft.Ink.DrawingAttributes](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583636(v=vs.90)) object, as shown in the following illustration.
|
||||
The following pair of illustrations compares the ink data object models. On the Windows Forms and COM platforms, the [Microsoft.Ink.Ink](/previous-versions/dotnet/netframework-3.5/ms583670(v=vs.90)) object constrains the lifetime of the [Microsoft.Ink.Stroke](/previous-versions/dotnet/netframework-3.5/ms552692(v=vs.90)) objects, and the stylus packets belong to the individual strokes. Two or more strokes can reference the same [Microsoft.Ink.DrawingAttributes](/previous-versions/dotnet/netframework-3.5/ms583636(v=vs.90)) object, as shown in the following illustration.
|
||||
|
||||

|
||||
|
||||
@@ -47,14 +49,15 @@ There are essentially three platforms that support digital ink: the Tablet PC Wi
|
||||
|
||||
|Task|Windows Presentation Foundation|Windows Forms and COM|
|
||||
|----------|-------------------------------------|---------------------------|
|
||||
|Save Ink|<xref:System.Windows.Ink.StrokeCollection.Save%2A>|[Microsoft.Ink.Ink.Save](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms571335(v=vs.90))|
|
||||
|Load Ink|Create a <xref:System.Windows.Ink.StrokeCollection> with the <xref:System.Windows.Ink.StrokeCollection.%23ctor%2A> constructor.|[Microsoft.Ink.Ink.Load](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms569609(v=vs.90))|
|
||||
|Hit test|<xref:System.Windows.Ink.StrokeCollection.HitTest%2A>|[Microsoft.Ink.Ink.HitTest](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms571330(v=vs.90))|
|
||||
|Copy Ink|<xref:System.Windows.Controls.InkCanvas.CopySelection%2A>|[Microsoft.Ink.Ink.ClipboardCopy](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms571316(v=vs.90))|
|
||||
|Paste Ink|<xref:System.Windows.Controls.InkCanvas.Paste%2A>|[Microsoft.Ink.Ink.ClipboardPaste](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms571318(v=vs.90))|
|
||||
|Access custom properties on a collection of strokes|<xref:System.Windows.Ink.StrokeCollection.AddPropertyData%2A> (the properties are stored internally and accessed via <xref:System.Windows.Ink.StrokeCollection.AddPropertyData%2A>, <xref:System.Windows.Ink.StrokeCollection.RemovePropertyData%2A>, and <xref:System.Windows.Ink.StrokeCollection.ContainsPropertyData%2A>)|Use [Microsoft.Ink.Ink.ExtendedProperties](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms582214(v=vs.90))|
|
||||
|Save Ink|<xref:System.Windows.Ink.StrokeCollection.Save%2A>|[Microsoft.Ink.Ink.Save](/previous-versions/dotnet/netframework-3.5/ms571335(v=vs.90))|
|
||||
|Load Ink|Create a <xref:System.Windows.Ink.StrokeCollection> with the <xref:System.Windows.Ink.StrokeCollection.%23ctor%2A> constructor.|[Microsoft.Ink.Ink.Load](/previous-versions/dotnet/netframework-3.5/ms569609(v=vs.90))|
|
||||
|Hit test|<xref:System.Windows.Ink.StrokeCollection.HitTest%2A>|[Microsoft.Ink.Ink.HitTest](/previous-versions/dotnet/netframework-3.5/ms571330(v=vs.90))|
|
||||
|Copy Ink|<xref:System.Windows.Controls.InkCanvas.CopySelection%2A>|[Microsoft.Ink.Ink.ClipboardCopy](/previous-versions/dotnet/netframework-3.5/ms571316(v=vs.90))|
|
||||
|Paste Ink|<xref:System.Windows.Controls.InkCanvas.Paste%2A>|[Microsoft.Ink.Ink.ClipboardPaste](/previous-versions/dotnet/netframework-3.5/ms571318(v=vs.90))|
|
||||
|Access custom properties on a collection of strokes|<xref:System.Windows.Ink.StrokeCollection.AddPropertyData%2A> (the properties are stored internally and accessed via <xref:System.Windows.Ink.StrokeCollection.AddPropertyData%2A>, <xref:System.Windows.Ink.StrokeCollection.RemovePropertyData%2A>, and <xref:System.Windows.Ink.StrokeCollection.ContainsPropertyData%2A>)|Use [Microsoft.Ink.Ink.ExtendedProperties](/previous-versions/dotnet/netframework-3.5/ms582214(v=vs.90))|
|
||||
|
||||
### Sharing ink between platforms
|
||||
|
||||
Although the platforms have different object models for the ink data, sharing the data between the platforms is very easy. The following examples save ink from a Windows Forms application and load the ink into a Windows Presentation Foundation application.
|
||||
|
||||
[!code-csharp[WinFormWPFInk#UsingWinforms](~/samples/snippets/csharp/VS_Snippets_Wpf/WinformWPFInk/CSharp/Program.cs#usingwinforms)]
|
||||
@@ -78,9 +81,10 @@ There are essentially three platforms that support digital ink: the Tablet PC Wi
|
||||
[!code-vb[WinFormWPFInk#UsingWinforms](~/samples/snippets/visualbasic/VS_Snippets_Wpf/WinformWPFInk/VisualBasic/Module1.vb#usingwinforms)]
|
||||
[!code-csharp[WinFormWPFInk#LoadWinforms](~/samples/snippets/csharp/VS_Snippets_Wpf/WinformWPFInk/CSharp/Program.cs#loadwinforms)]
|
||||
[!code-vb[WinFormWPFInk#LoadWinforms](~/samples/snippets/visualbasic/VS_Snippets_Wpf/WinformWPFInk/VisualBasic/Module1.vb#loadwinforms)]
|
||||
|
||||
## Events from the Tablet Pen
|
||||
|
||||
The [Microsoft.Ink.InkOverlay](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)), [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)), and [Microsoft.Ink.InkPicture](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) on the Windows Forms and COM platforms receive events when the user inputs pen data. The [Microsoft.Ink.InkOverlay](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) or [Microsoft.Ink.InkCollector](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) is attached to a window or a control, and can subscribe to the events raised by the tablet input data. The thread on which these events occurs depends on whether the events are raised with a pen, a mouse, or programmatically. For more information about threading in relation to these events, see [General Threading Considerations](/windows/desktop/tablet/general-threading-considerations) and [Threads on Which an Event Can Fire](/windows/desktop/tablet/threads-on-which-an-event-can-fire).
|
||||
The [Microsoft.Ink.InkOverlay](/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)), [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)), and [Microsoft.Ink.InkPicture](/previous-versions/dotnet/netframework-3.5/ms583740(v=vs.90)) on the Windows Forms and COM platforms receive events when the user inputs pen data. The [Microsoft.Ink.InkOverlay](/previous-versions/dotnet/netframework-3.5/ms552322(v=vs.90)) or [Microsoft.Ink.InkCollector](/previous-versions/dotnet/netframework-3.5/ms583683(v=vs.90)) is attached to a window or a control, and can subscribe to the events raised by the tablet input data. The thread on which these events occurs depends on whether the events are raised with a pen, a mouse, or programmatically. For more information about threading in relation to these events, see [General Threading Considerations](/windows/desktop/tablet/general-threading-considerations) and [Threads on Which an Event Can Fire](/windows/desktop/tablet/threads-on-which-an-event-can-fire).
|
||||
|
||||
On the Windows Presentation Foundation platform, the <xref:System.Windows.UIElement> class has events for pen input. This means that every control exposes the full set of stylus events. The stylus events have tunneling/bubbling event pairs and always occur on the application thread. For more information, see [Routed Events Overview](routed-events-overview.md).
|
||||
|
||||
@@ -89,9 +93,10 @@ There are essentially three platforms that support digital ink: the Tablet PC Wi
|
||||

|
||||
|
||||
## Pen Data
|
||||
All three platforms provide you with ways to intercept and manipulate the data that comes in from a tablet pen. On the Windows Forms and COM Platforms, this is achieved by creating a [Microsoft.StylusInput.RealTimeStylus](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)), attaching a window or control to it, and creating a class that implements the [Microsoft.StylusInput.IStylusSyncPlugin](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms575201(v=vs.90)) or [Microsoft.StylusInput.IStylusAsyncPlugin](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms575194(v=vs.90)) interface. The custom plug-in is then added to the plug-in collection of the [Microsoft.StylusInput.RealTimeStylus](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)). For more information about this object model, see [Architecture of the StylusInput APIs](/windows/desktop/tablet/architecture-of-the-stylusinput-apis).
|
||||
|
||||
All three platforms provide you with ways to intercept and manipulate the data that comes in from a tablet pen. On the Windows Forms and COM Platforms, this is achieved by creating a [Microsoft.StylusInput.RealTimeStylus](/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)), attaching a window or control to it, and creating a class that implements the [Microsoft.StylusInput.IStylusSyncPlugin](/previous-versions/dotnet/netframework-3.5/ms575201(v=vs.90)) or [Microsoft.StylusInput.IStylusAsyncPlugin](/previous-versions/dotnet/netframework-3.5/ms575194(v=vs.90)) interface. The custom plug-in is then added to the plug-in collection of the [Microsoft.StylusInput.RealTimeStylus](/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)). For more information about this object model, see [Architecture of the StylusInput APIs](/windows/desktop/tablet/architecture-of-the-stylusinput-apis).
|
||||
|
||||
On the WPF platform, the <xref:System.Windows.UIElement> class exposes a collection of plug-ins, similar in design to the [Microsoft.StylusInput.RealTimeStylus](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)). To intercept pen data, create a class that inherits from <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> and add the object to the <xref:System.Windows.UIElement.StylusPlugIns%2A> collection of the <xref:System.Windows.UIElement>. For more information about this interaction, see [Intercepting Input from the Stylus](intercepting-input-from-the-stylus.md).
|
||||
On the WPF platform, the <xref:System.Windows.UIElement> class exposes a collection of plug-ins, similar in design to the [Microsoft.StylusInput.RealTimeStylus](/previous-versions/dotnet/netframework-3.5/ms585724(v=vs.90)). To intercept pen data, create a class that inherits from <xref:System.Windows.Input.StylusPlugIns.StylusPlugIn> and add the object to the <xref:System.Windows.UIElement.StylusPlugIns%2A> collection of the <xref:System.Windows.UIElement>. For more information about this interaction, see [Intercepting Input from the Stylus](intercepting-input-from-the-stylus.md).
|
||||
|
||||
On all platforms, a thread pool receives the ink data via stylus events and sends it to the application thread. For more information about threading on the COM and Windows Platforms, see [Threading Considerations for the StylusInput APIs](/windows/desktop/tablet/threading-considerations-for-the-stylusinput-apis). For more information about threading on the Windows Presentation Software, see [The Ink Threading Model](the-ink-threading-model.md).
|
||||
|
||||
|
||||
@@ -8,10 +8,13 @@ helpviewer_keywords:
|
||||
ms.assetid: e83f25e5-d66b-4fc7-92d2-50130c9a6649
|
||||
---
|
||||
# Trees in WPF
|
||||
|
||||
In many technologies, elements and components are organized in a tree structure where developers directly manipulate the object nodes in the tree to affect the rendering or behavior of an application. [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] also uses several tree structure metaphors to define relationships between program elements. For the most part WPF developers can create an application in code or define portions of the application in XAML while thinking conceptually about the object tree metaphor, but will be calling specific API or using specific markup to do so rather than some general object tree manipulation API such as you might use in XML DOM. WPF exposes two helper classes that provide a tree metaphor view, <xref:System.Windows.LogicalTreeHelper> and <xref:System.Windows.Media.VisualTreeHelper>. The terms visual tree and logical tree are also used in the WPF documentation because these same trees are useful for understanding the behavior of certain key WPF features. This topic defines what the visual tree and logical tree represent, discusses how such trees relate to an overall object tree concept, and introduces <xref:System.Windows.LogicalTreeHelper> and <xref:System.Windows.Media.VisualTreeHelper>s.
|
||||
|
||||
<a name="element_tree"></a>
|
||||
|
||||
## Trees in WPF
|
||||
|
||||
The most complete tree structure in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] is the object tree. If you define an application page in [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] and then load the [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)], the tree structure is created based on the nesting relationships of the elements in the markup. If you define an application or a portion of the application in code, then the tree structure is created based on how you assign property values for properties that implement the content model for a given object. In [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)], there are two ways that the complete object tree is conceptualized and can be reported to its public API: as the logical tree and as the visual tree. The distinctions between logical tree and visual tree are not always necessarily important, but they can occasionally cause issues with certain [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] subsystems and affect choices you make in markup or code.
|
||||
|
||||
Even though you do not always manipulate either the logical tree or the visual tree directly, understanding the concepts of how the trees interact is useful for understanding WPF as a technology. Thinking of WPF as a tree metaphor of some kind is also crucial to understanding how property inheritance and event routing work in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)].
|
||||
@@ -20,8 +23,10 @@ In many technologies, elements and components are organized in a tree structure
|
||||
> Because the object tree is more of a concept than an actual API, another way to think of the concept is as an object graph. In practice, there are relationships between objects at run time where the tree metaphor will break down. Nevertheless, particularly with XAML-defined UI, the tree metaphor is relevant enough that most WPF documentation will use the term object tree when referencing this general concept.
|
||||
|
||||
<a name="logical_tree"></a>
|
||||
|
||||
## The Logical Tree
|
||||
In [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)], you add content to UI elements by setting properties of the objects that back those elements. For example, you add items to a <xref:System.Windows.Controls.ListBox> control by manipulating its <xref:System.Windows.Controls.ItemsControl.Items%2A> property. By doing this, you are placing items into the <xref:System.Windows.Controls.ItemCollection> that is the <xref:System.Windows.Controls.ItemsControl.Items%2A> property value. Similarly, to add objects to a <xref:System.Windows.Controls.DockPanel>, you manipulate its <xref:System.Windows.Controls.Panel.Children%2A> property value. Here, you are adding objects to the <xref:System.Windows.Controls.UIElementCollection>. For a code example, see [How to: Add an Element Dynamically](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ms752374(v=vs.100)).
|
||||
|
||||
In [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)], you add content to UI elements by setting properties of the objects that back those elements. For example, you add items to a <xref:System.Windows.Controls.ListBox> control by manipulating its <xref:System.Windows.Controls.ItemsControl.Items%2A> property. By doing this, you are placing items into the <xref:System.Windows.Controls.ItemCollection> that is the <xref:System.Windows.Controls.ItemsControl.Items%2A> property value. Similarly, to add objects to a <xref:System.Windows.Controls.DockPanel>, you manipulate its <xref:System.Windows.Controls.Panel.Children%2A> property value. Here, you are adding objects to the <xref:System.Windows.Controls.UIElementCollection>. For a code example, see [How to: Add an Element Dynamically](/previous-versions/dotnet/netframework-4.0/ms752374(v=vs.100)).
|
||||
|
||||
In [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)], when you place list items in a <xref:System.Windows.Controls.ListBox> or controls or other UI elements in a <xref:System.Windows.Controls.DockPanel>, you also use the <xref:System.Windows.Controls.ItemsControl.Items%2A> and <xref:System.Windows.Controls.Panel.Children%2A> properties, either explicitly or implicitly, as in the following example.
|
||||
|
||||
@@ -34,33 +39,47 @@ In many technologies, elements and components are organized in a tree structure
|
||||
For more information about how [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] syntax maps to the created object graph, and implicit syntax in XAML, see [XAML Syntax In Detail](xaml-syntax-in-detail.md) or [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml).
|
||||
|
||||
<a name="tree_property_inheritance_event_routing"></a>
|
||||
|
||||
### The Purpose of the Logical Tree
|
||||
|
||||
The logical tree exists so that content models can readily iterate over their possible child objects, and so that content models can be extensible. Also, the logical tree provides a framework for certain notifications, such as when all objects in the logical tree are loaded. Basically, the logical tree is an approximation of a run time object graph at the framework level, which excludes visuals, but is adequate for many querying operations against your own run time application's composition.
|
||||
|
||||
In addition, both static and dynamic resource references are resolved by looking upwards through the logical tree for <xref:System.Windows.FrameworkElement.Resources%2A> collections on the initial requesting object, and then continuing up the logical tree and checking each <xref:System.Windows.FrameworkElement> (or <xref:System.Windows.FrameworkContentElement>) for another `Resources` value that contains a <xref:System.Windows.ResourceDictionary>, possibly containing that key. The logical tree is used for resource lookup when both the logical tree and the visual tree are present. For more information on resource dictionaries and lookup, see [XAML Resources](/dotnet/desktop-wpf/fundamentals/xaml-resources-define).
|
||||
|
||||
<a name="composition"></a>
|
||||
|
||||
### Composition of the Logical Tree
|
||||
|
||||
The logical tree is defined at the WPF framework-level, which means that the WPF base element that is most relevant for logical tree operations is either <xref:System.Windows.FrameworkElement> or <xref:System.Windows.FrameworkContentElement>. However, as you can see if you actually use the <xref:System.Windows.LogicalTreeHelper> API, the logical tree sometimes contains nodes that are not either <xref:System.Windows.FrameworkElement> or <xref:System.Windows.FrameworkContentElement>. For instance, the logical tree reports the <xref:System.Windows.Controls.TextBlock.Text%2A> value of a <xref:System.Windows.Controls.TextBlock>, which is a string.
|
||||
|
||||
<a name="override_logical_tree"></a>
|
||||
|
||||
### Overriding the Logical Tree
|
||||
|
||||
Advanced control authors can override the logical tree by overriding several APIs that define how a general object or content model adds or removes objects within the logical tree. For an example of how to override the logical tree, see [Override the Logical Tree](how-to-override-the-logical-tree.md).
|
||||
|
||||
<a name="pvi"></a>
|
||||
|
||||
### Property Value Inheritance
|
||||
|
||||
Property value inheritance operates through a hybrid tree. The actual metadata that contains the <xref:System.Windows.FrameworkPropertyMetadata.Inherits%2A> property that enables property inheritance is the WPF framework-level <xref:System.Windows.FrameworkPropertyMetadata> class. Therefore, both the parent that holds the original value and the child object that inherits that value must both be <xref:System.Windows.FrameworkElement> or <xref:System.Windows.FrameworkContentElement>, and they must both be part of some logical tree. However, for existing WPF properties that support property inheritance, property value inheritance is able to perpetuate through an intervening object that is not in the logical tree. Mainly this is relevant for having template elements use any inherited property values set either on the instance that is templated, or at still higher levels of page-level composition and therefore higher in the logical tree. In order for property value inheritance to work consistently across such a boundary, the inheriting property must be registered as an attached property, and you should follow this pattern if you intend to define a custom dependency property with property inheritance behavior. The exact tree used for property inheritance cannot be entirely anticipated by a helper class utility method, even at run time. For more information, see [Property Value Inheritance](property-value-inheritance.md).
|
||||
|
||||
<a name="two_trees"></a>
|
||||
|
||||
## The Visual Tree
|
||||
|
||||
In addition to the concept of the logical tree, there is also the concept of the visual tree in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]. The visual tree describes the structure of visual objects, as represented by the <xref:System.Windows.Media.Visual> base class. When you write a template for a control, you are defining or redefining the visual tree that applies for that control. The visual tree is also of interest to developers who want lower-level control over drawing for performance and optimization reasons. One exposure of the visual tree as part of conventional [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application programming is that event routes for a routed event mostly travel along the visual tree, not the logical tree. This subtlety of routed event behavior might not be immediately apparent unless you are a control author. Routing events through the visual tree enables controls that implement composition at the visual level to handle events or create event setters.
|
||||
|
||||
<a name="trees_content"></a>
|
||||
|
||||
## Trees, Content Elements, and Content Hosts
|
||||
|
||||
Content elements (classes that derive from <xref:System.Windows.ContentElement>) are not part of the visual tree; they do not inherit from <xref:System.Windows.Media.Visual> and do not have a visual representation. In order to appear in a UI at all, a <xref:System.Windows.ContentElement> must be hosted in a content host that is both a <xref:System.Windows.Media.Visual> and a logical tree participant. Usually such an object is a <xref:System.Windows.FrameworkElement>. You can conceptualize that the content host is somewhat like a "browser" for the content and chooses how to display that content within the screen region that the host controls. When the content is hosted, the content can be made a participant in certain tree processes that are normally associated with the visual tree. Generally, the <xref:System.Windows.FrameworkElement> host class includes implementation code that adds any hosted <xref:System.Windows.ContentElement> to the event route through subnodes of the content logical tree, even though the hosted content is not part of the true visual tree. This is necessary so that a <xref:System.Windows.ContentElement> can source a routed event that routes to any element other than itself.
|
||||
|
||||
<a name="tree_traversal"></a>
|
||||
|
||||
## Tree Traversal
|
||||
|
||||
The <xref:System.Windows.LogicalTreeHelper> class provides the <xref:System.Windows.LogicalTreeHelper.GetChildren%2A>, <xref:System.Windows.LogicalTreeHelper.GetParent%2A>, and <xref:System.Windows.LogicalTreeHelper.FindLogicalNode%2A> methods for logical tree traversal. In most cases, you should not have to traverse the logical tree of existing controls, because these controls almost always expose their logical child elements as a dedicated collection property that supports collection access such as `Add`, an indexer, and so on. Tree traversal is mainly a scenario that is used by control authors who choose not to derive from intended control patterns such as <xref:System.Windows.Controls.ItemsControl> or <xref:System.Windows.Controls.Panel> where collection properties are already defined, and who intend to provide their own collection property support.
|
||||
|
||||
The visual tree also supports a helper class for visual tree traversal, <xref:System.Windows.Media.VisualTreeHelper>. The visual tree is not exposed as conveniently through control-specific properties, so the <xref:System.Windows.Media.VisualTreeHelper> class is the recommended way to traverse the visual tree if that is necessary for your programming scenario. For more information, see [WPF Graphics Rendering Overview](../graphics-multimedia/wpf-graphics-rendering-overview.md).
|
||||
@@ -69,11 +88,15 @@ In many technologies, elements and components are organized in a tree structure
|
||||
> Sometimes it is necessary to examine the visual tree of an applied template. You should be careful when using this technique. Even if you are traversing a visual tree for a control where you define the template, consumers of your control can always change the template by setting the <xref:System.Windows.Controls.Control.Template%2A> property on instances, and even the end user can influence the applied template by changing the system theme.
|
||||
|
||||
<a name="routes"></a>
|
||||
|
||||
## Routes for Routed Events as a "Tree"
|
||||
|
||||
As mentioned before, the route of any given routed event travels along a single and predetermined path of a tree that is a hybrid of the visual and logical tree representations. The event route can travel either in the up or down directions within the tree depending on whether it is a tunneling or bubbling routed event. The event route concept does not have a directly supporting helper class that could be used to "walk" the event route independently of raising an event that actually routes. There is a class that represents the route, <xref:System.Windows.EventRoute>, but the methods of that class are generally for internal use only.
|
||||
|
||||
<a name="resourcesandtrees"></a>
|
||||
|
||||
## Resource Dictionaries and Trees
|
||||
|
||||
Resource dictionary lookup for all `Resources` defined in a page traverses basically the logical tree. Objects that are not in the logical tree can reference keyed resources, but the resource lookup sequence begins at the point where that object is connected to the logical tree. In WPF, only logical tree nodes can have a `Resources` property that contains a <xref:System.Windows.ResourceDictionary>, therefore there is no benefit in traversing the visual tree looking for keyed resources from a <xref:System.Windows.ResourceDictionary>.
|
||||
|
||||
However, resource lookup can also extend beyond the immediate logical tree. For application markup, the resource lookup can then continue onward to application-level resource dictionaries and then to theme support and system values that are referenced as static properties or keys. Themes themselves can also reference system values outside of the theme logical tree if the resource references are dynamic. For more information on resource dictionaries and the lookup logic, see [XAML Resources](/dotnet/desktop-wpf/fundamentals/xaml-resources-define).
|
||||
|
||||
@@ -11,10 +11,13 @@ helpviewer_keywords:
|
||||
ms.assetid: f440c23f-fa5d-4d5a-852f-ba61150e6405
|
||||
---
|
||||
# Troubleshooting Hybrid Applications
|
||||
|
||||
<a name="introduction"></a> This topic lists some common problems that can occur when authoring hybrid applications, which use both [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] and Windows Forms technologies.
|
||||
|
||||
<a name="overlapping_controls"></a>
|
||||
|
||||
## Overlapping Controls
|
||||
|
||||
Controls may not overlap as you would expect. Windows Forms uses a separate HWND for each control. [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] uses one HWND for all content on a page. This implementation difference causes unexpected overlapping behaviors.
|
||||
|
||||
A Windows Forms control hosted in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] always appears on top of the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] content.
|
||||
@@ -22,33 +25,47 @@ ms.assetid: f440c23f-fa5d-4d5a-852f-ba61150e6405
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] content hosted in an <xref:System.Windows.Forms.Integration.ElementHost> control appears at the z-order of the <xref:System.Windows.Forms.Integration.ElementHost> control. It is possible to overlap <xref:System.Windows.Forms.Integration.ElementHost> controls, but the hosted [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] content does not combine or interact.
|
||||
|
||||
<a name="child_property"></a>
|
||||
|
||||
## Child Property
|
||||
|
||||
The <xref:System.Windows.Forms.Integration.WindowsFormsHost> and <xref:System.Windows.Forms.Integration.ElementHost> classes can host only a single child control or element. To host more than one control or element, you must use a container as the child content. For example, you could add Windows Forms button and check box controls to a <xref:System.Windows.Forms.Panel?displayProperty=nameWithType> control, and then assign the panel to a <xref:System.Windows.Forms.Integration.WindowsFormsHost> control's <xref:System.Windows.Forms.Integration.WindowsFormsHost.Child%2A> property. However, you cannot add the button and check box controls separately to the same <xref:System.Windows.Forms.Integration.WindowsFormsHost> control.
|
||||
|
||||
<a name="scaling"></a>
|
||||
|
||||
## Scaling
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] and Windows Forms have different scaling models. Some [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] scaling transformations are meaningful to Windows Forms controls, but others are not. For example, scaling a Windows Forms control to 0 will work, but if you try to scale the same control back to a non-zero value, the control's size remains 0. For more information, see [Layout Considerations for the WindowsFormsHost Element](layout-considerations-for-the-windowsformshost-element.md).
|
||||
|
||||
<a name="adapter"></a>
|
||||
|
||||
## Adapter
|
||||
|
||||
There may be confusion when working the <xref:System.Windows.Forms.Integration.WindowsFormsHost> and <xref:System.Windows.Forms.Integration.ElementHost> classes, because they include a hidden container. Both the <xref:System.Windows.Forms.Integration.WindowsFormsHost> and <xref:System.Windows.Forms.Integration.ElementHost> classes have a hidden container, called an *adapter*, which they use to host content. For the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element, the adapter derives from the <xref:System.Windows.Forms.ContainerControl?displayProperty=nameWithType> class. For the <xref:System.Windows.Forms.Integration.ElementHost> control, the adapter derives from the <xref:System.Windows.Controls.DockPanel> element. When you see references to the adapter in other interoperation topics, this container is what is being discussed.
|
||||
|
||||
<a name="nesting"></a>
|
||||
|
||||
## Nesting
|
||||
|
||||
Nesting a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element inside an <xref:System.Windows.Forms.Integration.ElementHost> control is not supported. Nesting an <xref:System.Windows.Forms.Integration.ElementHost> control inside a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element is also not supported.
|
||||
|
||||
<a name="focus"></a>
|
||||
|
||||
## Focus
|
||||
|
||||
Focus works differently in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] and Windows Forms, which means that focus issues may occur in a hybrid application. For example, if you have focus inside a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element, and you either minimize and restore the page or show a modal dialog box, focus inside the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element may be lost. The <xref:System.Windows.Forms.Integration.WindowsFormsHost> element still has focus, but the control inside it may not.
|
||||
|
||||
Data validation is also affected by focus. Validation works in a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element, but it does not work as you tab out of the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element, or between two different <xref:System.Windows.Forms.Integration.WindowsFormsHost> elements.
|
||||
|
||||
<a name="property_mapping"></a>
|
||||
|
||||
## Property Mapping
|
||||
|
||||
Some property mappings require extensive interpretation to bridge dissimilar implementations between the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] and Windows Forms technologies. Property mappings enable your code to react to changes in fonts, colors, and other properties. In general, property mappings work by listening for either *Property*Changed events or On*Property*Changed calls, and setting appropriate properties on either the child control or its adapter. For more information, see [Windows Forms and WPF Property Mapping](windows-forms-and-wpf-property-mapping.md).
|
||||
|
||||
<a name="layoutrelated_properties_on_hosted_content"></a>
|
||||
|
||||
## Layout-related Properties on Hosted Content
|
||||
|
||||
When the <xref:System.Windows.Forms.Integration.WindowsFormsHost.Child%2A?displayProperty=nameWithType> or <xref:System.Windows.Forms.Integration.ElementHost.Child%2A?displayProperty=nameWithType> property is assigned, several layout-related properties on the hosted content are set automatically. Changing these content properties can cause unexpected layout behaviors.
|
||||
|
||||
Your hosted content is docked to fill the <xref:System.Windows.Forms.Integration.WindowsFormsHost> and <xref:System.Windows.Forms.Integration.ElementHost> parent. To enable this fill behavior, several properties are set when you set the child property. The following table lists which content properties are set by the <xref:System.Windows.Forms.Integration.ElementHost> and <xref:System.Windows.Forms.Integration.WindowsFormsHost> classes.
|
||||
@@ -61,56 +78,74 @@ ms.assetid: f440c23f-fa5d-4d5a-852f-ba61150e6405
|
||||
Do not set these properties directly on the hosted content. For more information, see [Layout Considerations for the WindowsFormsHost Element](layout-considerations-for-the-windowsformshost-element.md).
|
||||
|
||||
<a name="navigation_applications"></a>
|
||||
|
||||
## Navigation Applications
|
||||
|
||||
Navigation applications may not maintain user state. The <xref:System.Windows.Forms.Integration.WindowsFormsHost> element recreates its controls when it is used in a navigation application. Recreating child controls occurs when the user navigates away from the page hosting the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element and then returns to it. Any content that has been typed in by the user will be lost.
|
||||
|
||||
<a name="message_loop_interoperation"></a>
|
||||
|
||||
## Message Loop Interoperation
|
||||
|
||||
When working with Windows Forms message loops, messages may not be processed as expected. The <xref:System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop%2A> method is called by the <xref:System.Windows.Forms.Integration.WindowsFormsHost> constructor. This method adds a message filter to the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] message loop. This filter calls the <xref:System.Windows.Forms.Control.PreProcessMessage%2A?displayProperty=nameWithType> method if a <xref:System.Windows.Forms.Control?displayProperty=nameWithType> was the target of the message and translates/dispatches the message.
|
||||
|
||||
If you show a <xref:System.Windows.Window> in a Windows Forms message loop with <xref:System.Windows.Forms.Application.Run%2A?displayProperty=nameWithType>, you cannot type anything unless you call the <xref:System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop%2A> method. The <xref:System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop%2A> method takes a <xref:System.Windows.Window> and adds a <xref:System.Windows.Forms.IMessageFilter?displayProperty=nameWithType>, which reroutes key-related messages to the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] message loop. For more information, see [Windows Forms and WPF Interoperability Input Architecture](windows-forms-and-wpf-interoperability-input-architecture.md).
|
||||
|
||||
<a name="opacity_and_layering"></a>
|
||||
|
||||
## Opacity and Layering
|
||||
|
||||
The <xref:System.Windows.Interop.HwndHost> class does not support layering. This means that setting the <xref:System.Windows.UIElement.Opacity%2A> property on the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element has no effect, and no blending will occur with other [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] windows which have <xref:System.Windows.Window.AllowsTransparency%2A> set to `true`.
|
||||
|
||||
<a name="dispose"></a>
|
||||
|
||||
## Dispose
|
||||
|
||||
Not disposing classes properly can leak resources. In your hybrid applications, make sure that the <xref:System.Windows.Forms.Integration.WindowsFormsHost> and <xref:System.Windows.Forms.Integration.ElementHost> classes are disposed, or you could leak resources. Windows Forms disposes <xref:System.Windows.Forms.Integration.ElementHost> controls when its non-modal <xref:System.Windows.Forms.Form> parent closes. [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] disposes <xref:System.Windows.Forms.Integration.WindowsFormsHost> elements when your application shuts down. It is possible to show a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element in a <xref:System.Windows.Window> in a Windows Forms message loop. In this case, your code may not receive notification that your application is shutting down.
|
||||
|
||||
<a name="enabling_visual_styles"></a>
|
||||
|
||||
## Enabling Visual Styles
|
||||
|
||||
Microsoft Windows XP visual styles on a Windows Forms control may not be enabled. The <xref:System.Windows.Forms.Application.EnableVisualStyles%2A?displayProperty=nameWithType> method is called in the template for a Windows Forms application. Although this method is not called by default, if you use Visual Studio to create a project, you will get Microsoft Windows XP visual styles for controls, if version 6.0 of Comctl32.dll is available. You must call the <xref:System.Windows.Forms.Application.EnableVisualStyles%2A> method before handles are created on the thread. For more information, see [How to: Enable Visual Styles in a Hybrid Application](how-to-enable-visual-styles-in-a-hybrid-application.md).
|
||||
|
||||
<a name="licensed_controls"></a>
|
||||
|
||||
## Licensed Controls
|
||||
|
||||
Licensed Windows Forms controls that display licensing information in a message box to the user might cause unexpected behavior for a hybrid application. Some licensed controls show a dialog box in response to handle creation. For example, a licensed control might inform the user that a license is required, or that the user has three remaining trial uses of the control.
|
||||
|
||||
The <xref:System.Windows.Forms.Integration.WindowsFormsHost> element derives from the <xref:System.Windows.Interop.HwndHost> class, and the child control’s handle is created inside the <xref:System.Windows.Forms.Integration.WindowsFormsHost.BuildWindowCore%2A> method. The <xref:System.Windows.Interop.HwndHost> class does not allow messages to be processed in the <xref:System.Windows.Forms.Integration.WindowsFormsHost.BuildWindowCore%2A> method, but displaying a dialog box causes messages to be sent. To enable this licensing scenario, call the <xref:System.Windows.Forms.Control.CreateControl%2A?displayProperty=nameWithType> method on the control before assigning it as the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element's child.
|
||||
|
||||
<a name="wpf_designer"></a>
|
||||
|
||||
## WPF Designer
|
||||
|
||||
You can design your WPF content by using the WPF Designer for Visual Studio. The following sections list some common problems that can occur when authoring hybrid applications with the WPF Designer.
|
||||
|
||||
### BackColorTransparent is ignored at design time
|
||||
|
||||
The <xref:System.Windows.Forms.Integration.ElementHost.BackColorTransparent%2A> property might not work as expected at design time.
|
||||
|
||||
If a WPF control is not on a visible parent, the WPF runtime ignores the <xref:System.Windows.Forms.Integration.ElementHost.BackColorTransparent%2A> value. The reason that <xref:System.Windows.Forms.Integration.ElementHost.BackColorTransparent%2A> might be ignored is because <xref:System.Windows.Forms.Integration.ElementHost> object is created in a separate <xref:System.AppDomain>. However, when you run the application, <xref:System.Windows.Forms.Integration.ElementHost.BackColorTransparent%2A> does work as expected.
|
||||
|
||||
### Design-time Error List appears when the obj folder is deleted
|
||||
|
||||
If the obj folder is deleted, the Design-time Error List appears.
|
||||
|
||||
When you design using <xref:System.Windows.Forms.Integration.ElementHost>, the Windows Forms Designer uses generated files in the Debug or Release folder within your project's obj folder. If you delete these files, the Design-time Error List appears. To fix this problem, rebuild your project. For more information, see [Design-Time Errors in the Windows Forms Designer](/dotnet/framework/winforms/controls/design-time-errors-in-the-windows-forms-designer).
|
||||
|
||||
<a name="elementhost_and_ime"></a>
|
||||
|
||||
## ElementHost and IME
|
||||
|
||||
WPF controls hosted in an <xref:System.Windows.Forms.Integration.ElementHost> currently do not support the <xref:System.Windows.Forms.Control.ImeMode%2A> property. Changes to <xref:System.Windows.Forms.Control.ImeMode%2A> will be ignored by the hosted controls.
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Interoperability in the WPF Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/bb628658(v=vs.100))
|
||||
- [Interoperability in the WPF Designer](/previous-versions/visualstudio/visual-studio-2010/bb628658(v=vs.100))
|
||||
- [Windows Forms and WPF Interoperability Input Architecture](windows-forms-and-wpf-interoperability-input-architecture.md)
|
||||
- [How to: Enable Visual Styles in a Hybrid Application](how-to-enable-visual-styles-in-a-hybrid-application.md)
|
||||
- [Layout Considerations for the WindowsFormsHost Element](layout-considerations-for-the-windowsformshost-element.md)
|
||||
|
||||
@@ -6,10 +6,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 06cbf17b-6eff-4fe5-949d-2dd533e4e1f4
|
||||
---
|
||||
# Typography in WPF
|
||||
|
||||
This topic introduces the major typographic features of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]. These features include improved quality and performance of text rendering, OpenType typography support, enhanced international text, enhanced font support, and new text application programming interfaces (APIs).
|
||||
|
||||
<a name="Improved_Quality_and_Performance_of_Text"></a>
|
||||
|
||||
## Improved Quality and Performance of Text
|
||||
|
||||
Text in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] is rendered using Microsoft ClearType, which enhances the clarity and readability of text. ClearType is a software technology developed by Microsoft that improves the readability of text on existing LCDs (Liquid Crystal Displays), such as laptop screens, Pocket PC screens and flat panel monitors. ClearType uses sub-pixel rendering which allows text to be displayed with a greater fidelity to its true shape by aligning characters on a fractional part of a pixel. The extra resolution increases the sharpness of the tiny details in text display, making it much easier to read over long durations. Another improvement of ClearType in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] is y-direction anti-aliasing, which smoothes the tops and bottoms of shallow curves in text characters. For more details on ClearType features, see [ClearType Overview](cleartype-overview.md).
|
||||
|
||||

|
||||
@@ -22,7 +25,9 @@ Text with ClearType y-direction antialiasing
|
||||
In addition, animated text, whether by character or glyph, takes full advantage of the graphics hardware capability enabled by [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]. This results in smooth text animation.
|
||||
|
||||
<a name="Rich_Typography"></a>
|
||||
|
||||
## Rich Typography
|
||||
|
||||
The OpenType font format is an extension of the TrueType® font format. The OpenType font format was developed jointly by Microsoft and Adobe, and provides a rich assortment of advanced typographic features. The <xref:System.Windows.Documents.Typography> object exposes many of the advanced features of OpenType fonts, such as stylistic alternates and swashes. The Windows SDK provides a set of sample OpenType fonts that are designed with rich features, such as the Pericles and Pescadero fonts. For more information, see [Sample OpenType Font Pack](sample-opentype-font-pack.md).
|
||||
|
||||
The Pericles OpenType font contains additional glyphs that provide stylistic alternates to the standard set of glyphs. The following text displays stylistic alternate glyphs.
|
||||
@@ -36,7 +41,9 @@ Text with ClearType y-direction antialiasing
|
||||
For more details on OpenType features, see [OpenType Font Features](opentype-font-features.md).
|
||||
|
||||
<a name="Enhanced_International_Text_Support"></a>
|
||||
|
||||
## Enhanced International Text Support
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides enhanced international text support by providing the following features:
|
||||
|
||||
- Automatic line-spacing in all writing systems, using adaptive measurement.
|
||||
@@ -46,7 +53,9 @@ Text with ClearType y-direction antialiasing
|
||||
- Language-guided line breaking, hyphenation, and justification.
|
||||
|
||||
<a name="Enhanced_Font_Support"></a>
|
||||
|
||||
## Enhanced Font Support
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides enhanced font support by providing the following features:
|
||||
|
||||
- Unicode for all text. Font behavior and selection no longer require charset or codepage.
|
||||
@@ -64,7 +73,9 @@ Text with ClearType y-direction antialiasing
|
||||
- Composite fonts embedded in a document, thereby providing document portability. For more information, see the remarks in the <xref:System.Windows.Media.FontFamily> class.
|
||||
|
||||
<a name="New_Text_APIs"></a>
|
||||
|
||||
## New Text Application Programming Interfaces (APIs)
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides several text APIs for developers to use when including text in their applications. These APIs are grouped into three categories:
|
||||
|
||||
- **Layout and user interface**. The common text controls for the graphical user interface (GUI).
|
||||
@@ -74,9 +85,11 @@ Text with ClearType y-direction antialiasing
|
||||
- **Advanced text formatting**. Allows you to implement a custom text engine.
|
||||
|
||||
### Layout and User Interface
|
||||
|
||||
At the highest level of functionality, the text APIs provide common [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)] controls such as <xref:System.Windows.Controls.Label>, <xref:System.Windows.Controls.TextBlock>, and <xref:System.Windows.Controls.TextBox>. These controls provide the basic [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] elements within an application, and offer an easy way to present and interact with text. Controls such as <xref:System.Windows.Controls.RichTextBox> and <xref:System.Windows.Controls.PasswordBox> enable more advanced or specialized text-handling. And classes such as <xref:System.Windows.Documents.TextRange>, <xref:System.Windows.Documents.TextSelection>, and <xref:System.Windows.Documents.TextPointer> enable useful text manipulation. These [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] controls provide properties such as <xref:System.Windows.Controls.Control.FontFamily%2A>, <xref:System.Windows.Controls.Control.FontSize%2A>, and <xref:System.Windows.Controls.Control.FontStyle%2A>, which enable you to control the font that is used to render the text.
|
||||
|
||||
#### Using Bitmap Effects, Transforms, and Text Effects
|
||||
|
||||
[!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] allows you to create visually interesting uses of text by uses features such as bitmap effects, transforms, and text effects. The following example shows a typical type of a drop shadow effect applied to text.
|
||||
|
||||

|
||||
@@ -106,6 +119,7 @@ Text with ClearType y-direction antialiasing
|
||||

|
||||
|
||||
#### Using Flow Documents
|
||||
|
||||
In addition to the common [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] controls, [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] offers a layout control for text presentation—the <xref:System.Windows.Documents.FlowDocument> element. The <xref:System.Windows.Documents.FlowDocument> element, in conjunction with the <xref:System.Windows.Controls.DocumentViewer> element, provides a control for large amounts of text with varying layout requirements. Layout controls provide access to advanced typography through the <xref:System.Windows.Documents.Typography> object and font-related properties of other [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] controls.
|
||||
|
||||
The following example shows text content hosted in a <xref:System.Windows.Controls.FlowDocumentReader>, which provides search, navigation, pagination, and content scaling support.
|
||||
@@ -115,6 +129,7 @@ Text with ClearType y-direction antialiasing
|
||||
For more information, see [Documents in WPF](documents-in-wpf.md).
|
||||
|
||||
### Lightweight Text Drawing
|
||||
|
||||
You can draw text directly to [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] objects by using the <xref:System.Windows.Media.DrawingContext.DrawText%2A> method of the <xref:System.Windows.Media.DrawingContext> object. To use this method, you create a <xref:System.Windows.Media.FormattedText> object. This object allows you to draw multi-line text, in which each character in the text can be individually formatted. The functionality of the <xref:System.Windows.Media.FormattedText> object contains much of the functionality of the DrawText flags in the Windows API. In addition, the <xref:System.Windows.Media.FormattedText> object contains functionality such as ellipsis support, in which an ellipsis is displayed when text exceeds its bounds. The following example shows text that has several formats applied to it, including a linear gradient on the second and third words.
|
||||
|
||||

|
||||
@@ -134,6 +149,7 @@ Text with ClearType y-direction antialiasing
|
||||
For more information on the <xref:System.Windows.Media.FormattedText> object, see [Drawing Formatted Text](drawing-formatted-text.md).
|
||||
|
||||
### Advanced Text Formatting
|
||||
|
||||
At the most advanced level of the text APIs, [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] offers you the ability to create custom text layout by using the <xref:System.Windows.Media.TextFormatting.TextFormatter> object and other types in the <xref:System.Windows.Media.TextFormatting> namespace. The <xref:System.Windows.Media.TextFormatting.TextFormatter> and associated classes allow you to implement custom text layout that supports your own definition of character formats, paragraph styles, line breaking rules, and other layout features for international text. There are very few cases in which you would want to override the default implementation of the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] text layout support. However, if you were creating a text editing control or application, you might require a different implementation than the default [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] implementation.
|
||||
|
||||
Unlike a traditional text API, the <xref:System.Windows.Media.TextFormatting.TextFormatter> interacts with a text layout client through a set of callback methods. It requires the client to provide these methods in an implementation of the <xref:System.Windows.Media.TextFormatting.TextSource> class. The following diagram illustrates the text layout interaction between the client application and <xref:System.Windows.Media.TextFormatting.TextFormatter>.
|
||||
@@ -151,4 +167,4 @@ Text with ClearType y-direction antialiasing
|
||||
- [Drawing Formatted Text](drawing-formatted-text.md)
|
||||
- [Advanced Text Formatting](advanced-text-formatting.md)
|
||||
- [Text](optimizing-performance-text.md)
|
||||
- [Microsoft Typography](https://docs.microsoft.com/typography/)
|
||||
- [Microsoft Typography](/typography/)
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ With Visual Studio, you can easily add a data source to your project. This proce
|
||||
|
||||
1. From the **Data** menu, select **Add New Data Source**.
|
||||
|
||||
2. In the **Data Source Configuration Wizard**, create a connection to the Northwind database by using a dataset. For more information, see [How to: Connect to Data in a Database](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/fxk9yw1t(v=vs.120)).
|
||||
2. In the **Data Source Configuration Wizard**, create a connection to the Northwind database by using a dataset. For more information, see [How to: Connect to Data in a Database](/previous-versions/visualstudio/visual-studio-2013/fxk9yw1t(v=vs.120)).
|
||||
|
||||
3. When you are prompted by the **Data Source Configuration Wizard**, save the connection string as `NorthwindConnectionString`.
|
||||
|
||||
|
||||
+4
-1
@@ -31,6 +31,7 @@ You need the following components to complete this walkthrough:
|
||||
- Visual Studio 2017
|
||||
|
||||
<a name="To_Create_the_UserControl"></a>
|
||||
|
||||
## Create the UserControl
|
||||
|
||||
1. Create a **WPF User Control Library** project named `HostingWpfUserControlInWf`.
|
||||
@@ -44,6 +45,7 @@ You need the following components to complete this walkthrough:
|
||||
This code defines a <xref:System.Windows.Controls.UserControl?displayProperty=nameWithType> that contains two child controls. The first child control is a <xref:System.Windows.Controls.Label?displayProperty=nameWithType> control; the second is a <xref:System.Windows.Controls.Viewport3D> control that displays a 3D cone.
|
||||
|
||||
<a name="To_Create_the_Windows_Forms_Host_Project"></a>
|
||||
|
||||
## Create the host project
|
||||
|
||||
1. Add a **Windows Forms App (.NET Framework)** project named `WpfUserControlHost` to the solution.
|
||||
@@ -63,6 +65,7 @@ You need the following components to complete this walkthrough:
|
||||
5. In Solution Explorer, set the `WpfUserControlHost` project to be the startup project.
|
||||
|
||||
<a name="To_Host_the_Windows_Presentation_Foundation"></a>
|
||||
|
||||
## Host the UserControl
|
||||
|
||||
1. In the Windows Forms Designer, open Form1.
|
||||
@@ -87,4 +90,4 @@ You need the following components to complete this walkthrough:
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
- [Walkthrough: Hosting a WPF Composite Control in Windows Forms](walkthrough-hosting-a-wpf-composite-control-in-windows-forms.md)
|
||||
- [Walkthrough: Hosting a Windows Forms Composite Control in WPF](walkthrough-hosting-a-windows-forms-composite-control-in-wpf.md)
|
||||
- [Hosting a WPF Composite Control in Windows Forms Sample](https://go.microsoft.com/fwlink/?LinkID=160001)
|
||||
- [Hosting a WPF Composite Control in Windows Forms Sample](https://github.com/microsoft/WPF-Samples/tree/master/Migration%20and%20Interoperability/WindowsFormsHostingWpfControl)
|
||||
|
||||
+15
-1
@@ -11,6 +11,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 96fcd78d-1c77-4206-8928-3a0579476ef4
|
||||
---
|
||||
# Walkthrough: Hosting a Windows Forms Composite Control in WPF
|
||||
|
||||
[!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] provides a rich environment for creating applications. However, when you have a substantial investment in Windows Forms code, it can be more effective to reuse at least some of that code in your [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application rather than to rewrite it from scratch. The most common scenario is when you have existing Windows Forms controls. In some cases, you might not even have access to the source code for these controls. [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides a straightforward procedure for hosting such controls in a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application. For example, you can use [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] for most of your programming while hosting your specialized <xref:System.Windows.Forms.DataGridView> controls.
|
||||
|
||||
This walkthrough steps you through an application that hosts a Windows Forms composite control to perform data entry in a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application. The composite control is packaged in a DLL. This general procedure can be extended to more complex applications and controls. This walkthrough is designed to be nearly identical in appearance and functionality to [Walkthrough: Hosting a WPF Composite Control in Windows Forms](walkthrough-hosting-a-wpf-composite-control-in-windows-forms.md). The primary difference is that the hosting scenario is reversed.
|
||||
@@ -23,13 +24,14 @@ ms.assetid: 96fcd78d-1c77-4206-8928-3a0579476ef4
|
||||
|
||||
- Implementing the WPF host application.
|
||||
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Hosting a Windows Forms Composite Control in WPF Sample](https://go.microsoft.com/fwlink/?LinkID=159999).
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Hosting a Windows Forms Composite Control in WPF Sample](https://github.com/microsoft/WPF-Samples/tree/master/Migration%20and%20Interoperability/HostingWfInWPF).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
You need Visual Studio to complete this walkthrough.
|
||||
|
||||
## Implementing the Windows Forms Composite Control
|
||||
|
||||
The Windows Forms composite control used in this example is a simple data-entry form. This form takes the user's name and address and then uses a custom event to return that information to the host. The following illustration shows the rendered control.
|
||||
|
||||
The following image shows a Windows Forms composite control:
|
||||
@@ -37,6 +39,7 @@ You need Visual Studio to complete this walkthrough.
|
||||

|
||||
|
||||
### Creating the Project
|
||||
|
||||
To start the project:
|
||||
|
||||
1. Launch Visual Studio, and open the **New Project** dialog box.
|
||||
@@ -64,6 +67,7 @@ You need Visual Studio to complete this walkthrough.
|
||||
- System.Xml
|
||||
|
||||
### Adding Controls to the Form
|
||||
|
||||
To add controls to the form:
|
||||
|
||||
- Open `MyControl1` in the designer.
|
||||
@@ -83,6 +87,7 @@ You need Visual Studio to complete this walkthrough.
|
||||
Add two <xref:System.Windows.Forms.Button> controls labeled **OK** and **Cancel**. In the example, the button names are `btnOK` and `btnCancel`, respectively.
|
||||
|
||||
### Implementing the Supporting Code
|
||||
|
||||
Open the form in code view. The control returns the collected data to its host by raising the custom `OnButtonClick` event. The data is contained in the event argument object. The following code shows the event and delegate declaration.
|
||||
|
||||
Add the following code to the `MyControl1` class.
|
||||
@@ -105,6 +110,7 @@ You need Visual Studio to complete this walkthrough.
|
||||
[!code-vb[WpfHostingWindowsFormsControl#4](~/samples/snippets/visualbasic/VS_Snippets_Wpf/WpfHostingWindowsFormsControl/VisualBasic/MyControls/MyControl1.vb#4)]
|
||||
|
||||
### Giving the Assembly a Strong Name and Building the Assembly
|
||||
|
||||
For this assembly to be referenced by a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application, it must have a strong name. To create a strong name, create a key file with Sn.exe and add it to your project.
|
||||
|
||||
1. Open a Visual Studio command prompt. To do so, click the **Start** menu, and then select **All Programs/Microsoft Visual Studio 2010/Visual Studio Tools/Visual Studio Command Prompt**. This launches a console window with customized environment variables.
|
||||
@@ -122,6 +128,7 @@ You need Visual Studio to complete this walkthrough.
|
||||
5. Build the solution. The build will produce a DLL named MyControls.dll.
|
||||
|
||||
## Implementing the WPF Host Application
|
||||
|
||||
The [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] host application uses the <xref:System.Windows.Forms.Integration.WindowsFormsHost> control to host `MyControl1`. The application handles the `OnButtonClick` event to receive the data from the control. It also has a collection of option buttons that enable you to change some of the control's properties from the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] application. The following illustration shows the finished application.
|
||||
|
||||
The following image shows the complete application, including the control embedded in the WPF application:
|
||||
@@ -129,6 +136,7 @@ The following image shows the complete application, including the control embedd
|
||||

|
||||
|
||||
### Creating the Project
|
||||
|
||||
To start the project:
|
||||
|
||||
1. Open Visual Studio, and select **New Project**.
|
||||
@@ -152,6 +160,7 @@ The following image shows the complete application, including the control embedd
|
||||
4. Add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll.
|
||||
|
||||
### Implementing the Basic Layout
|
||||
|
||||
The [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)] of the host application is implemented in MainWindow.xaml. This file contains [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] markup that defines the layout, and hosts the Windows Forms control. The application is divided into three regions:
|
||||
|
||||
- The **Control Properties** panel, which contains a collection of option buttons that you can use to modify various properties of the hosted control.
|
||||
@@ -169,6 +178,7 @@ The following image shows the complete application, including the control embedd
|
||||
The first <xref:System.Windows.Controls.StackPanel> element contains several sets of <xref:System.Windows.Controls.RadioButton> controls that enable you to modify various default properties of the hosted control. That is followed by a <xref:System.Windows.Forms.Integration.WindowsFormsHost> element, which hosts `MyControl1`. The final <xref:System.Windows.Controls.StackPanel> element contains several <xref:System.Windows.Controls.TextBlock> elements that display the data that is returned by the hosted control. The ordering of the elements and the <xref:System.Windows.Controls.DockPanel.Dock%2A> and <xref:System.Windows.FrameworkElement.Height%2A> attribute settings embed the hosted control into the window with no gaps or distortion.
|
||||
|
||||
#### Hosting the Control
|
||||
|
||||
The following edited version of the previous XAML focuses on the elements that are needed to host `MyControl1`.
|
||||
|
||||
[!code-xaml[WpfHostingWindowsFormsControl#101](~/samples/snippets/csharp/VS_Snippets_Wpf/WpfHostingWindowsFormsControl/CSharp/WpfHost/Page1.xaml#101)]
|
||||
@@ -183,6 +193,7 @@ The following image shows the complete application, including the control embedd
|
||||
- `mcl:MyControl1`, which represents `MyControl1`, is added to the <xref:System.Windows.Forms.Integration.WindowsFormsHost> element's child collection. As a result, this Windows Forms control is rendered as part of the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] window, and you can communicate with the control from the application.
|
||||
|
||||
### Implementing the Code-Behind File
|
||||
|
||||
The code-behind file, MainWindow.xaml.vb or MainWindow.xaml.cs, contains the procedural code that implements the functionality of the [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)] discussed in the preceding section. The primary tasks are:
|
||||
|
||||
- Attaching an event handler to `MyControl1`'s `OnButtonClick` event.
|
||||
@@ -192,6 +203,7 @@ The following image shows the complete application, including the control embedd
|
||||
- Displaying the data collected by the control.
|
||||
|
||||
#### Initializing the Application
|
||||
|
||||
The initialization code is contained in an event handler for the window's <xref:System.Windows.FrameworkElement.Loaded> event and attaches an event handler to the control's `OnButtonClick` event.
|
||||
|
||||
In MainWindow.xaml.vb or MainWindow.xaml.cs, add the following code to the `MainWindow` class.
|
||||
@@ -214,6 +226,7 @@ using MyControls;
|
||||
```
|
||||
|
||||
#### Handling the OnButtonClick Event
|
||||
|
||||
`MyControl1` raises the `OnButtonClick` event when the user clicks either of the control's buttons.
|
||||
|
||||
Add the following code to the `MainWindow` class.
|
||||
@@ -224,6 +237,7 @@ using MyControls;
|
||||
The data in the text boxes is packed into the `MyControlEventArgs` object. If the user clicks the **OK** button, the event handler extracts the data and displays it in the panel below `MyControl1`.
|
||||
|
||||
#### Modifying the Control’s Properties
|
||||
|
||||
The <xref:System.Windows.Forms.Integration.WindowsFormsHost> element exposes several of the hosted control's default properties. As a result, you can change the appearance of the control to match the style of your application more closely. The sets of option buttons in the left panel enable the user to modify several color and font properties. Each set of buttons has a handler for the <xref:System.Windows.Controls.Primitives.ButtonBase.Click> event, which detects the user's option button selections and changes the corresponding property on the control.
|
||||
|
||||
Add the following code to the `MainWindow` class.
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ Tasks illustrated in this walkthrough include:
|
||||
|
||||
- Using the LocBaml tool to produce a satellite assembly.
|
||||
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Localizing a Hybrid Application Sample](https://go.microsoft.com/fwlink/?LinkID=160015).
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Localizing a Hybrid Application Sample](https://github.com/microsoft/WPF-Samples/tree/master/Migration%20and%20Interoperability/LocalizingWpfInWf).
|
||||
|
||||
When you are finished, you will have a localized hybrid application.
|
||||
|
||||
@@ -171,5 +171,5 @@ Your localized content is stored in a resource-only *satellite assembly*. Use th
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Localize an Application](how-to-localize-an-application.md)
|
||||
- [Walkthrough: Localizing Windows Forms](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/y99d1cd3(v=vs.100))
|
||||
- [Walkthrough: Localizing Windows Forms](/previous-versions/visualstudio/visual-studio-2010/y99d1cd3(v=vs.100))
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
|
||||
+1
-3
@@ -23,8 +23,6 @@ Tasks illustrated in this walkthrough include:
|
||||
|
||||
- Extending a default property mapping.
|
||||
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Mapping Properties Using the ElementHost Control Sample](https://go.microsoft.com/fwlink/?LinkID=160018).
|
||||
|
||||
When you are finished, you will be able to map Windows Forms properties to corresponding [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties on a hosted element.
|
||||
|
||||
## Prerequisites
|
||||
@@ -56,7 +54,7 @@ You need the following components to complete this walkthrough:
|
||||
|
||||
4. Open `Form1` in the Windows Forms Designer. Double-click the form to add an event handler for the <xref:System.Windows.Forms.Form.Load> event.
|
||||
|
||||
5. Return to the Windows Forms Designer and add an event handler for the form's <xref:System.Windows.Forms.Control.Resize> event. For more information, see [How to: Create Event Handlers Using the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/zwwsdtbk(v=vs.100)).
|
||||
5. Return to the Windows Forms Designer and add an event handler for the form's <xref:System.Windows.Forms.Control.Resize> event. For more information, see [How to: Create Event Handlers Using the Designer](/previous-versions/visualstudio/visual-studio-2010/zwwsdtbk(v=vs.100)).
|
||||
|
||||
6. Declare an <xref:System.Windows.Forms.Integration.ElementHost> field in the `Form1` class.
|
||||
|
||||
|
||||
-2
@@ -27,8 +27,6 @@ Tasks illustrated in this walkthrough include:
|
||||
|
||||
- Extending a default property mapping.
|
||||
|
||||
For a complete code listing of the tasks illustrated in this walkthrough, see [Mapping Properties Using the WindowsFormsHost Element Sample](https://go.microsoft.com/fwlink/?LinkID=160019).
|
||||
|
||||
When you are finished, you will be able to map [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties to corresponding properties on a hosted Windows Forms control.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 8a157e6b-8054-46db-a5cf-a78966acc7a1
|
||||
---
|
||||
# Windows Forms Controls and Equivalent WPF Controls
|
||||
|
||||
Many Windows Forms controls have equivalent [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] controls, but some Windows Forms controls have no equivalents in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]. This topic compares control types provided by the two technologies.
|
||||
|
||||
You can always use interoperation to host Windows Forms controls that do not have equivalents in your [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)]-based applications.
|
||||
@@ -83,7 +84,7 @@ Many Windows Forms controls have equivalent [!INCLUDE[TLA2#tla_winclient](../../
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [WPF Designer for Windows Forms Developers](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/cc165605(v=vs.100))
|
||||
- [WPF Designer for Windows Forms Developers](/previous-versions/visualstudio/visual-studio-2010/cc165605(v=vs.100))
|
||||
- [Walkthrough: Hosting a Windows Forms Control in WPF](walkthrough-hosting-a-windows-forms-control-in-wpf.md)
|
||||
- [Walkthrough: Hosting a WPF Composite Control in Windows Forms](walkthrough-hosting-a-wpf-composite-control-in-windows-forms.md)
|
||||
- [Migration and Interoperability](migration-and-interoperability.md)
|
||||
|
||||
+14
-2
@@ -17,13 +17,17 @@ helpviewer_keywords:
|
||||
ms.assetid: 5c0854e3-7470-435d-9fe2-93eec9d3634e
|
||||
---
|
||||
# XAML Namespaces and Namespace Mapping for WPF XAML
|
||||
|
||||
This topic further explains the presence and purpose of the two XAML namespace mappings as often found in the root tag of a WPF XAML file. It also describes how to produce similar mappings for using elements that are defined in your own code, and/or within separate assemblies.
|
||||
|
||||
## What is a XAML Namespace?
|
||||
## What is a XAML Namespace
|
||||
|
||||
A XAML namespace is really an extension of the concept of an XML namespace. The techniques of specifying a XAML namespace rely on the XML namespace syntax, the convention of using URIs as namespace identifiers, using prefixes to provide a means to reference multiple namespaces from the same markup source, and so on. The primary concept that is added to the XAML definition of the XML namespace is that a XAML namespace implies both a scope of uniqueness for the markup usages, and also influences how markup entities are potentially backed by specific CLR namespaces and referenced assemblies. This latter consideration is also influenced by the concept of a XAML schema context. But for purposes of how WPF works with XAML namespaces, you can generally think of XAML namespaces in terms of a default XAML namespace, the XAML language namespace, and any further XAML namespaces as mapped by your XAML markup directly to specific backing CLR namespaces and referenced assemblies.
|
||||
|
||||
<a name="The_WPF_and_XAML_Namespace_Declarations"></a>
|
||||
|
||||
## The WPF and XAML Namespace Declarations
|
||||
|
||||
Within the namespace declarations in the root tag of many XAML files, you will see that there are typically two XML namespace declarations. The first declaration maps the overall WPF client / framework XAML namespace as the default:
|
||||
|
||||
`xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"`
|
||||
@@ -37,7 +41,9 @@ This topic further explains the presence and purpose of the two XAML namespace m
|
||||
The `x:` prefix convention for mapping the XAML language intrinsics support is followed by project templates, sample code, and the documentation of language features within this SDK. The XAML namespace defines many commonly-used features that are necessary even for basic WPF applications. For instance, in order to join any code-behind to a XAML file through a partial class, you must name that class as the `x:Class` attribute in the root element of the relevant XAML file. Or, any element as defined in a XAML page that you wish to access as a keyed resource should have the `x:Key` attribute set on the element in question. For more information on these and other aspects of XAML see [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml) or [XAML Syntax In Detail](xaml-syntax-in-detail.md).
|
||||
|
||||
<a name="Mapping_To_Custom_Classes_and_Assemblies"></a>
|
||||
|
||||
## Mapping to Custom Classes and Assemblies
|
||||
|
||||
You can map XML namespaces to assemblies using a series of tokens within an `xmlns` prefix declaration, similar to how the standard WPF and XAML-intrinsics XAML namespaces are mapped to prefixes.
|
||||
|
||||
The syntax takes the following possible named tokens and following values:
|
||||
@@ -49,6 +55,7 @@ This topic further explains the presence and purpose of the two XAML namespace m
|
||||
Note that the character separating the `clr-namespace` token from its value is a colon (:) whereas the character separating the `assembly` token from its value is an equals sign (=). The character to use between these two tokens is a semicolon. Also, do not include any white space anywhere in the declaration.
|
||||
|
||||
### A Basic Custom Mapping Example
|
||||
|
||||
The following code defines an example custom class:
|
||||
|
||||
```csharp
|
||||
@@ -94,17 +101,21 @@ End Namespace
|
||||
```
|
||||
|
||||
### Mapping to Current Assemblies
|
||||
|
||||
`assembly` can be omitted if the `clr-namespace` referenced is being defined within the same assembly as the application code that is referencing the custom classes. Or, an equivalent syntax for this case is to specify `assembly=`, with no string token following the equals sign.
|
||||
|
||||
Custom classes cannot be used as the root element of a page if defined in the same assembly. Partial classes do not need to be mapped; only classes that are not the partial class of a page in your application need to be mapped if you intend to reference them as elements in XAML.
|
||||
|
||||
<a name="Mapping_CLR_Namespaces_to_XML_Namespaces_in_an"></a>
|
||||
|
||||
## Mapping CLR Namespaces to XML Namespaces in an Assembly
|
||||
|
||||
WPF defines a CLR attribute that is consumed by XAML processors in order to map multiple CLR namespaces to a single XAML namespace. This attribute, <xref:System.Windows.Markup.XmlnsDefinitionAttribute>, is placed at the assembly level in the source code that produces the assembly. The WPF assembly source code uses this attribute to map the various common namespaces, such as <xref:System.Windows> and <xref:System.Windows.Controls>, to the `http://schemas.microsoft.com/winfx/2006/xaml/presentation` namespace.
|
||||
|
||||
The <xref:System.Windows.Markup.XmlnsDefinitionAttribute> takes two parameters: the XML/XAML namespace name, and the CLR namespace name. More than one <xref:System.Windows.Markup.XmlnsDefinitionAttribute> can exist to map multiple CLR namespaces to the same XML namespace. Once mapped, members of those namespaces can also be referenced without full qualification if desired by providing the appropriate `using` statement in the partial-class code-behind page. For more details, see <xref:System.Windows.Markup.XmlnsDefinitionAttribute>.
|
||||
|
||||
## Designer Namespaces and Other Prefixes From XAML Templates
|
||||
|
||||
If you are working with development environments and/or design tools for WPF XAML, you may notice that there are other defined XAML namespaces / prefixes within the XAML markup.
|
||||
|
||||
WPF Designer for Visual Studio uses a designer namespace that is typically mapped to the prefix `d:`. More recent project templates for WPF might pre-map this XAML namespace to support interchange of the XAML between WPF Designer for Visual Studio and other design environments. This design XAML namespace is used to perpetuate design state while roundtripping XAML-based UI in the designer. It is also used for features such as `d:IsDataSource`, which enable runtime data sources in a designer.
|
||||
@@ -112,6 +123,7 @@ End Namespace
|
||||
Another prefix you might see mapped is `mc:`. `mc:` is for markup compatibility, and is leveraging a markup compatibility pattern that is not necessarily XAML-specific. To some extent, the markup compatibility features can be used to exchange XAML between frameworks or across other boundaries of backing implementation, work between XAML schema contexts, provide compatibility for limited modes in designers, and so on. For more information on markup compatibility concepts and how they relate to WPF, see [Markup Compatibility (mc:) Language Features](markup-compatibility-mc-language-features.md).
|
||||
|
||||
## WPF and Assembly Loading
|
||||
|
||||
The XAML schema context for WPF integrates with the WPF application model, which in turn uses the CLR-defined concept of <xref:System.AppDomain>. The following sequence describes how XAML schema context interprets how to either load assemblies or find types at run time or design time, based on the WPF use of <xref:System.AppDomain> and other factors.
|
||||
|
||||
1. Iterate through the <xref:System.AppDomain>, looking for an already-loaded assembly that matches all aspects of the name, starting from the most recently loaded assembly.
|
||||
@@ -132,5 +144,5 @@ End Namespace
|
||||
|
||||
## See also
|
||||
|
||||
- [Understanding XML Namespaces](https://docs.microsoft.com/previous-versions/aa468565(v=msdn.10))
|
||||
- [Understanding XML Namespaces](/previous-versions/aa468565(v=msdn.10))
|
||||
- [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml)
|
||||
|
||||
Reference in New Issue
Block a user