diff --git a/dotnet-desktop-guide/framework/wpf/advanced/toc.yml b/dotnet-desktop-guide/framework/wpf/advanced/toc.yml index 310fd2f..012a1c1 100644 --- a/dotnet-desktop-guide/framework/wpf/advanced/toc.yml +++ b/dotnet-desktop-guide/framework/wpf/advanced/toc.yml @@ -7,7 +7,7 @@ href: xaml-in-wpf.md items: - name: XAML Overview (WPF) - href: /dotnet/desktop-wpf/fundamentals/xaml + href: xaml-overview.md - name: XAML Syntax In Detail href: xaml-syntax-in-detail.md - name: Code-Behind and XAML in WPF @@ -290,7 +290,7 @@ href: resources-wpf.md items: - name: XAML Resources - href: /dotnet/desktop-wpf/fundamentals/xaml-resources-define + href: xaml-resources-define.md items: - name: Resources and Code href: resources-and-code.md diff --git a/dotnet-desktop-guide/framework/wpf/advanced/xaml-overview.md b/dotnet-desktop-guide/framework/wpf/advanced/xaml-overview.md new file mode 100644 index 0000000..3229afa --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/xaml-overview.md @@ -0,0 +1,334 @@ +--- +title: XAML overview +description: Learn how the XAML language is structured and implemented by Windows Presentation Foundation (WPF) for .NET Framework. +author: adegeo +ms.date: 12/03/2020 +ms.author: adegeo +ms.topic: overview +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "user interfaces [XAML]" + - "classes [XAML]" + - "root element [XAML]" + - "XAML [WPF], about XAML" + - "base classes [XAML]" + - "routed events [WPF]" + - "code-behind files [WPF], XAML" + - "collection properties [XAML]" + - "events [XAML]" + - "property element [XAML]" + - "content models [XAML]" + - "Extensible Application Markup Language (see XAML)" + - "attribute syntax [XAML]" +--- + +# XAML overview in WPF + +This article describes the features of the XAML language and demonstrates how you can use XAML to write Windows Presentation Foundation (WPF) apps. This article specifically describes XAML as implemented by WPF. XAML itself is a larger language concept than WPF. + +## What is XAML + +XAML is a declarative markup language. As applied to the .NET Core programming model, XAML simplifies creating a UI for a .NET Core app. You can create visible UI elements in the declarative XAML markup, and then separate the UI definition from the run-time logic by using code-behind files that are joined to the markup through partial class definitions. XAML directly represents the instantiation of objects in a specific set of backing types defined in assemblies. This is unlike most other markup languages, which are typically an interpreted language without such a direct tie to a backing type system. XAML enables a workflow where separate parties can work on the UI and the logic of an app, using potentially different tools. + +When represented as text, XAML files are XML files that generally have the `.xaml` extension. The files can be encoded by any XML encoding, but encoding as UTF-8 is typical. + +The following example shows how you might create a button as part of a UI. This example is intended to give you a flavor of how XAML represents common UI programming metaphors (it is not a complete sample). + +[!code-xaml[XAMLOvwSupport#DirtSimple](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#dirtsimple)] + +## XAML syntax in brief + +The following sections explain the basic forms of XAML syntax, and give a short markup example. These sections are not intended to provide complete information about each syntax form, such as how these are represented in the backing type system. For more information about the specifics of XAML syntax, see [XAML Syntax In Detail](xaml-syntax-in-detail.md). + +Much of the material in the next few sections will be elementary to you if you have previous familiarity with the XML language. This is a consequence of one of the basic design principles of XAML. The XAML language defines concepts of its own, but these concepts work within the XML language and markup form. + +### XAML object elements + +An object element typically declares an instance of a type. That type is defined in the assemblies referenced by the technology that uses XAML as a language. + +Object element syntax always starts with an opening angle bracket (`<`). This is followed by the name of the type where you want to create an instance. (The name can include a prefix, a concept that will be explained later.) After this, you can optionally declare attributes on the object element. To complete the object element tag, end with a closing angle bracket (`>`). You can instead use a self-closing form that does not have any content, by completing the tag with a forward slash and closing angle bracket in succession (`/>`). For example, look at the previously shown markup snippet again. + +[!code-xaml[XAMLOvwSupport#DirtSimple](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#dirtsimple)] + +This specifies two object elements: `` (with content, and a closing tag later), and ` +``` + +For more information about the specifics of XAML syntax, see [XAML Syntax In Detail](xaml-syntax-in-detail.md). + +### Text content + +A small number of XAML elements can directly process text as their content. To enable this, one of the following cases must be true: + +- The class must declare a content property, and that content property must be of a type assignable to a string (the type could be ). For instance, any uses as its content property and it is type , and this supports the following usage on a such as a : ``. + +- The type must declare a type converter, in which case the text content is used as initialization text for that type converter. For example, `Blue` converts the content value of `Blue` into a brush. This case is less common in practice. + +- The type must be a known XAML language primitive. + +### Content properties and collection syntax combined + +Consider this example. + +```xaml + + + + +``` + +Here, each is a child element of . This is a streamlined and intuitive markup that omits two tags for two different reasons. + +- **Omitted StackPanel.Children property element:** derives from . defines as its XAML content property. + +- **Omitted UIElementCollection object element:** The property takes the type , which implements . The collection's element tag can be omitted, based on the XAML rules for processing collections such as . (In this case, actually cannot be instantiated because it does not expose a parameterless constructor, and that is why the object element is shown commented out). + +```xaml + + + + + + + + +``` + +### Attribute syntax (events) + +Attribute syntax can also be used for members that are events rather than properties. In this case, the attribute's name is the name of the event. In the WPF implementation of events for XAML, the attribute's value is the name of a handler that implements that event's delegate. For example, the following markup assigns a handler for the event to a created in markup: + +[!code-xaml[XAMLOvwSupport#ButtonWithCodeBehind](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml#buttonwithcodebehind)] + +There is more to events and XAML in WPF than just this example of the attribute syntax. For example, you might wonder what the `ClickHandler` referenced here represents and how it is defined. This will be explained in the upcoming [Events and XAML code-behind](#events-and-xaml-code-behind) section of this article. + +## Case and white space in XAML + +In general, XAML is case-sensitive. For purposes of resolving backing types, WPF XAML is case-sensitive by the same rules that the CLR is case-sensitive. Object elements, property elements, and attribute names must all be specified by using the sensitive casing when compared by name to the underlying type in the assembly, or to a member of a type. XAML language keywords and primitives are also case-sensitive. Values are not always case-sensitive. Case sensitivity for values will depend on the type converter behavior associated with the property that takes the value, or the property value type. For example, properties that take the type can take either `true` or `True` as equivalent values, but only because the native WPF XAML parser type conversion for string to already permits these as equivalents. + +WPF XAML processors and serializers will ignore or drop all nonsignificant white space, and will normalize any significant white space. This is consistent with the default white-space behavior recommendations of the XAML specification. This behavior is only of consequence when you specify strings within XAML content properties. In simplest terms, XAML converts space, linefeed, and tab characters into spaces, and then preserves one space if found at either end of a contiguous string. The full explanation of XAML white-space handling is not covered in this article. For more information, see [White space processing in XAML](../../../xaml-services/white-space-processing.md). + +## Markup extensions + +Markup extensions are a XAML language concept. When used to provide the value of an attribute syntax, curly braces (`{` and `}`) indicate a markup extension usage. This usage directs the XAML processing to escape from the general treatment of attribute values as either a literal string or a string-convertible value. + +The most common markup extensions used in WPF app programming are [`Binding`](binding-markup-extension.md), used for data binding expressions, and the resource references [`StaticResource`](staticresource-markup-extension.md) and [`DynamicResource`](dynamicresource-markup-extension.md). By using markup extensions, you can use attribute syntax to provide values for properties even if that property does not support an attribute syntax in general. Markup extensions often use intermediate expression types to enable features such as deferring values or referencing other objects that are only present at run-time. + +For example, the following markup sets the value of the property using attribute syntax. The property takes an instance of the class, which by default could not be instantiated by an attribute syntax string. But in this case, the attribute references a particular markup extension, `StaticResource`. When that markup extension is processed, it returns a reference to a style that was previously instantiated as a keyed resource in a resource dictionary. + +[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources)] +[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources2](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources2)] +[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources3](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources3)] + +For a reference listing of all markup extensions for XAML implemented specifically in WPF, see [WPF XAML Extensions](wpf-xaml-extensions.md). For a reference listing of the markup extensions that are defined by System.Xaml and are more widely available for .NET Core XAML implementations, see [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md). For more information about markup extension concepts, see [Markup Extensions and WPF XAML](markup-extensions-and-wpf-xaml.md). + +## Type converters + +In the [XAML Syntax in Brief](#xaml-syntax-in-brief) section, it was stated that the attribute value must be able to be set by a string. The basic, native handling of how strings are converted into other object types or primitive values is based on the type itself, in addition to native processing for certain types such as or . But many WPF types or members of those types extend the basic string attribute processing behavior in such a way that instances of more complex object types can be specified as strings and attributes. + +The structure is an example of a type that has a type conversion enabled for XAML usages. indicates measurements within a nested rectangle and is used as the value for properties such as . By placing a type converter on , all properties that use a are easier to specify in XAML because they can be specified as attributes. The following example uses a type conversion and attribute syntax to provide a value for a : + +[!code-xaml[XAMLOvwSupport#MarginTCE](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#margintce)] + +The previous attribute syntax example is equivalent to the following more verbose syntax example, where the is instead set through property element syntax containing a object element. The four key properties of are set as attributes on the new instance: + +[!code-xaml[XAMLOvwSupport#MarginVerbose](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#marginverbose)] + +> [!NOTE] +> There are also a limited number of objects where the type conversion is the only public way to set a property to that type without involving a subclass, because the type itself does not have a parameterless constructor. An example is . + +For more information on type conversion, see [TypeConverters and XAML](typeconverters-and-xaml.md). + +## XAML root elements and XAML namespaces + +A XAML file must have only one root element, in order to be both a well-formed XML file and a valid XAML file. For typical WPF scenarios, you use a root element that has a prominent meaning in the WPF app model (for example, or for a page, for an external dictionary, or for the app definition). The following example shows the root element of a typical XAML file for a WPF page, with the root element of . + +[!code-xaml[XAMLOvwSupport#RootOnly](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#rootonly)] +[!code-xaml[XAMLOvwSupport#RootOnly2](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#rootonly2)] + +The root element also contains the attributes `xmlns` and `xmlns:x`. These attributes indicate to a XAML processor which XAML namespaces contain the type definitions for backing types that the markup will reference as elements. The `xmlns` attribute specifically indicates the default XAML namespace. Within the default XAML namespace, object elements in the markup can be specified without a prefix. For most WPF app scenarios, and for almost all of the examples given in the WPF sections of the SDK, the default XAML namespace is mapped to the WPF namespace `http://schemas.microsoft.com/winfx/2006/xaml/presentation`. The `xmlns:x` attribute indicates an additional XAML namespace, which maps the XAML language namespace `http://schemas.microsoft.com/winfx/2006/xaml`. + +This usage of `xmlns` to define a scope for usage and mapping of a namescope is consistent with the XML 1.0 specification. XAML namescopes are different from XML namescopes only in that a XAML namescope also implies something about how the namescope's elements are backed by types when it comes to type resolution and parsing the XAML. + +The `xmlns` attributes are only strictly necessary on the root element of each XAML file. `xmlns` definitions will apply to all descendant elements of the root element (this behavior is again consistent with the XML 1.0 specification for `xmlns`.) `xmlns` attributes are also permitted on other elements underneath the root, and would apply to any descendant elements of the defining element. However, frequent definition or redefinition of XAML namespaces can result in a XAML markup style that is difficult to read. + +The WPF implementation of its XAML processor includes an infrastructure that has awareness of the WPF core assemblies. The WPF core assemblies are known to contain the types that support the WPF mappings to the default XAML namespace. This is enabled through configuration that is part of your project build file and the WPF build and project systems. Therefore, declaring the default XAML namespace as the default `xmlns` is all that is necessary in order to reference XAML elements that come from WPF assemblies. + +### The x: prefix + +In the previous root element example, the prefix `x:` was used to map the XAML namespace `http://schemas.microsoft.com/winfx/2006/xaml`, which is the dedicated XAML namespace that supports XAML language constructs. This `x:` prefix is used for mapping this XAML namespace in the templates for projects, in examples, and in documentation throughout this SDK. The XAML namespace for the XAML language contains several programming constructs that you will use frequently in your XAML. The following is a listing of the most common `x:` prefix programming constructs you will use: + +- [x:Key](../../../xaml-services/xkey-directive.md): Sets a unique key for each resource in a (or similar dictionary concepts in other frameworks). `x:Key` will probably account for 90 percent of the `x:` usages you will see in a typical WPF app's markup. + +- [x:Class](../../../xaml-services/xclass-directive.md): Specifies the CLR namespace and class name for the class that provides code-behind for a XAML page. You must have such a class to support code-behind per the WPF programming model, and therefore you almost always see `x:` mapped, even if there are no resources. + +- [x:Name](../../../xaml-services/xname-directive.md): Specifies a run-time object name for the instance that exists in run-time code after an object element is processed. In general, you will frequently use a WPF-defined equivalent property for [x:Name](../../../xaml-services/xname-directive.md). Such properties map specifically to a CLR backing property and are thus more convenient for app programming, where you frequently use run-time code to find the named elements from initialized XAML. The most common such property is . You might still use [x:Name](../../../xaml-services/xname-directive.md) when the equivalent WPF framework-level property is not supported in a particular type. This occurs in certain animation scenarios. + +- [x:Static](../../../xaml-services/xstatic-markup-extension.md): Enables a reference that returns a static value that is not otherwise a XAML-compatible property. + +- [x:Type](../../../xaml-services/xtype-markup-extension.md): Constructs a reference based on a type name. This is used to specify attributes that take , such as , although frequently the property has native string-to- conversion in such a way that the [x:Type](../../../xaml-services/xtype-markup-extension.md) markup extension usage is optional. + +There are additional programming constructs in the `x:` prefix/XAML namespace, which are not as common. For details, see [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md). + +## Custom prefixes and custom types in XAML + +For your own custom assemblies, or for assemblies outside the WPF core of **PresentationCore**, **PresentationFramework** and **WindowsBase**, you can specify the assembly as part of a custom `xmlns` mapping. You can then reference types from that assembly in your XAML, so long as that type is correctly implemented to support the XAML usages you are attempting. + +The following is a basic example of how custom prefixes work in XAML markup. The prefix `custom` is defined in the root element tag, and mapped to a specific assembly that is packaged and available with the app. This assembly contains a type `NumericUpDown`, which is implemented to support general XAML usage as well as using a class inheritance that permits its insertion at this particular point in a WPF XAML content model. An instance of this `NumericUpDown` control is declared as an object element, using the prefix so that a XAML parser knows which XAML namespace contains the type, and therefore where the backing assembly is that contains the type definition. + +```xaml + + + +... + + +``` + +For more information about custom types in XAML, see [XAML and Custom Classes for WPF](xaml-and-custom-classes-for-wpf.md). + +For more information about how XML namespaces and code namespaces in assemblies are related, see [XAML Namespaces and Namespace Mapping for WPF XAML](xaml-namespaces-and-namespace-mapping-for-wpf-xaml.md). + +## Events and XAML code-behind + +Most WPF apps consist of both XAML markup and code-behind. Within a project, the XAML is written as a `.xaml` file, and a CLR language such as Microsoft Visual Basic or C# is used to write a code-behind file. When a XAML file is markup compiled as part of the WPF programming and application models, the location of the XAML code-behind file for a XAML file is identified by specifying a namespace and class as the `x:Class` attribute of the root element of the XAML. + +In the examples so far, you have seen several buttons, but none of these buttons had any logical behavior associated with them yet. The primary application-level mechanism for adding a behavior for an object element is to use an existing event of the element class, and to write a specific handler for that event that is invoked when that event is raised at run-time. The event name and the name of the handler to use are specified in the markup, whereas the code that implements your handler is defined in the code-behind. + +[!code-xaml[XAMLOvwSupport#ButtonWithCodeBehind](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml#buttonwithcodebehind)] + +[!code-csharp[XAMLOvwSupport#ButtonWithCodeBehindHandler](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml.cs#buttonwithcodebehindhandler)] +[!code-vb[XAMLOvwSupport#ButtonWithCodeBehindHandler](~/samples/snippets/visualbasic/VS_Snippets_Wpf/XAMLOvwSupport/VisualBasic/Page1.xaml.vb#buttonwithcodebehindhandler)] + +Notice that the code-behind file uses the CLR namespace `ExampleNamespace` and declares `ExamplePage` as a partial class within that namespace. This parallels the `x:Class` attribute value of `ExampleNamespace`.`ExamplePage` that was provided in the markup root. The WPF markup compiler will create a partial class for any compiled XAML file, by deriving a class from the root element type. When you provide code-behind that also defines the same partial class, the resulting code is combined within the same namespace and class of the compiled app. + +For more information about requirements for code-behind programming in WPF, see [Code-behind, Event Handler, and Partial Class Requirements in WPF](code-behind-and-xaml-in-wpf.md#code-behind-event-handler-and-partial-class-requirements-in-wpf). + +If you do not want to create a separate code-behind file, you can also inline your code in a XAML file. However, inline code is a less versatile technique that has substantial limitations. For more informaiton, see [Code-Behind and XAML in WPF](code-behind-and-xaml-in-wpf.md). + +### Routed events + +A particular event feature that is fundamental to WPF is a routed event. Routed events enable an element to handle an event that was raised by a different element, as long as the elements are connected through a tree relationship. When specifying event handling with a XAML attribute, the routed event can be listened for and handled on any element, including elements that do not list that particular event in the class members table. This is accomplished by qualifying the event name attribute with the owning class name. For instance, the parent `StackPanel` in the ongoing `StackPanel` / `Button` example could register a handler for the child element button's event by specifying the attribute `Button.Click` on the `StackPanel` object element, with your handler name as the attribute value. For more information, see [Routed Events Overview](routed-events-overview.md). + +## XAML named elements + +By default, the object instance that is created in an object graph by processing a XAML object element does not possess a unique identifier or object reference. In contrast, if you call a constructor in code, you almost always use the constructor result to set a variable to the constructed instance, so that you can reference the instance later in your code. In order to provide standardized access to objects that were created through a markup definition, XAML defines the [x:Name attribute](../../../xaml-services/xname-directive.md). You can set the value of the `x:Name` attribute on any object element. In your code-behind, the identifier you choose is equivalent to an instance variable that refers to the constructed instance. In all respects, named elements function as if they were object instances (the name references that instance), and your code-behind can reference the named elements to handle run-time interactions within the app. This connection between instances and variables is accomplished by the WPF XAML markup compiler, and more specifically involve features and patterns such as that will not be discussed in detail in this article. + +WPF framework-level XAML elements inherit a property, which is equivalent to the XAML defined `x:Name` attribute. Certain other classes also provide property-level equivalents for `x:Name`, which is also generally defined as a `Name` property. Generally speaking, if you cannot find a `Name` property in the members table for your chosen element/type, use `x:Name` instead. The `x:Name` values will provide an identifier to a XAML element that can be used at run-time, either by specific subsystems or by utility methods such as . + +The following example sets on a element. Then, a handler on a within that references the through its instance reference `buttonContainer` as set by . + +[!code-xaml[XAMLOvwSupport#NamedE](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#namede)] +[!code-xaml[XAMLOvwSupport#NamedE2](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#namede2)] + +[!code-csharp[XAMLOvwSupport#NameCode](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml.cs#namecode)] +[!code-vb[XAMLOvwSupport#NameCode](~/samples/snippets/visualbasic/VS_Snippets_Wpf/XAMLOvwSupport/VisualBasic/Page1.xaml.vb#namecode)] + +Just like a variable, the XAML name for an instance is governed by a concept of scope, so that names can be enforced to be unique within a certain scope that is predictable. The primary markup that defines a page denotes one unique XAML namescope, with the XAML namescope boundary being the root element of that page. However, other markup sources can interact with a page at run-time, such as styles or templates within styles, and such markup sources often have their own XAML namescopes that do not necessarily connect with the XAML namescope of the page. For more information on `x:Name` and XAML namescopes, see , [x:Name Directive](../../../xaml-services/xname-directive.md), or [WPF XAML Namescopes](wpf-xaml-namescopes.md). + +## Attached properties and attached events + +XAML specifies a language feature that enables certain properties or events to be specified on any element, regardless of whether the property or event exists in the type's definitions for the element it is being set on. The properties version of this feature is called an attached property, the events version is called an attached event. Conceptually, you can think of attached properties and attached events as global members that can be set on any XAML element/object instance. However, that element/class or a larger infrastructure must support a backing property store for the attached values. + +Attached properties in XAML are typically used through attribute syntax. In attribute syntax, you specify an attached property in the form `ownerType.propertyName`. + +Superficially, this resembles a property element usage, but in this case the `ownerType` you specify is always a different type than the object element where the attached property is being set. `ownerType` is the type that provides the accessor methods that are required by a XAML processor in order to get or set the attached property value. + +The most common scenario for attached properties is to enable child elements to report a property value to their parent element. + +The following example illustrates the attached property. The class defines the accessors for and therefore owns the attached property. The class also includes logic that iterates its child elements and specifically checks each element for a set value of . If a value is found, that value is used during layout to position the child elements. Use of the attached property and this positioning capability is in fact the motivating scenario for the class. + +[!code-xaml[XAMLOvwSupport#DockAP](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page8.xaml#dockap)] + +In WPF, most or all the attached properties are also implemented as dependency properties. For more information, see [Attached Properties Overview](attached-properties-overview.md). + +Attached events use a similar `ownerType.eventName` form of attribute syntax. Just like the non-attached events, the attribute value for an attached event in XAML specifies the name of the handler method that is invoked when the event is handled on the element. Attached event usages in WPF XAML are less common. For more information, see [Attached Events Overview](attached-events-overview.md). + +## Base types and XAML + +Underlying WPF XAML and its XAML namespace is a collection of types that correspond to CLR objects in addition to markup elements for XAML. However, not all classes can be mapped to elements. Abstract classes, such as , and certain non-abstract base classes, are used for inheritance in the CLR objects model. Base classes, including abstract ones, are still important to XAML development because each of the concrete XAML elements inherits members from some base class in its hierarchy. Often these members include properties that can be set as attributes on the element, or events that can be handled. is the concrete base UI class of WPF at the WPF framework level. When designing UI, you will use various shape, panel, decorator, or control classes, which all derive from . A related base class, , supports document-oriented elements that work well for a flow layout presentation, using APIs that deliberately mirror the APIs in . The combination of attributes at the element level and a CLR object model provides you with a set of common properties that are settable on most concrete XAML elements, regardless of the specific XAML element and its underlying type. + +## XAML security + +XAML is a markup language that directly represents object instantiation and execution. Therefore, elements created in XAML have the same ability to interact with system resources (network access, file system IO, for example) as the equivalent generated code does. XAML loaded in to a fully trusted app has the same access to the system resources as the hosting app does. + +### Code Access Security (CAS) in WPF + +WPF for .NET Framework supports Code Access Security (CAS). This means that WPF content running in the internet zone has reduced execution permissions. "Loose XAML" (pages of noncompiled XAML interpreted at load time by a XAML viewer) and XBAP are usually run in this internet zone and use the same permission set. However, XAML loaded in to a fully trusted application has the same access to the system resources as the hosting application does. For more information, see [WPF Partial Trust Security](../wpf-partial-trust-security.md). + +## Loading XAML from code + +XAML can be used to define all of the UI, but it is sometimes also appropriate to define just a piece of the UI in XAML. This capability could be used to enable partial customization, local storage of information, using XAML to provide a business object, or a variety of possible scenarios. The key to these scenarios is the class and its method. The input is a XAML file, and the output is an object that represents all of the run-time tree of objects that was created from that markup. You then can insert the object to be a property of another object that already exists in the app. So long as the property is an appropriate property in the content model that has eventual display capabilities and that will notify the execution engine that new content has been added into the app, you can modify a running app's contents easily by loading in XAML. For .NET Framework, this capability is generally only available in full-trust applications, because of the obvious security implications of loading files into applications as they run. + +## See also + +- [XAML Syntax In Detail](xaml-syntax-in-detail.md) +- [XAML and Custom Classes for WPF](xaml-and-custom-classes-for-wpf.md) +- [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md) +- [WPF XAML Extensions](wpf-xaml-extensions.md) +- [Base Elements Overview](base-elements-overview.md) +- [Trees in WPF](trees-in-wpf.md) diff --git a/dotnet-desktop-guide/framework/wpf/advanced/xaml-resources-define.md b/dotnet-desktop-guide/framework/wpf/advanced/xaml-resources-define.md new file mode 100644 index 0000000..549019e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/xaml-resources-define.md @@ -0,0 +1,162 @@ +--- +title: Define XAML resources +description: Learn about XAML resources in WPF for .NET Framework. Understand the types of XAML resources and learn how to define XAML resources. +author: adegeo +ms.author: adegeo +ms.date: 12/03/2020 +ms.topic: overview +--- + +# Overview of XAML resources + +A resource is an object that can be reused in different places in your app. Examples of resources include brushes and styles. This overview describes how to use resources in Extensible Application Markup Language (XAML). You can also create and access resources by using code. + +> [!NOTE] +> XAML resources described in this article are different from *app resources* which are generally files added to an app, such as content, data, or embedded files. + +## Using resources in XAML + +The following example defines a as a resource on the root element of a page. The example then references the resource and uses it to set properties of several child elements, including an , a , and a . + +[!code-xaml[FEResourceSH_snip#XAML](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xaml)] + +Every framework-level element ( or ) has a property, which is a type that contains defined resources. You can define resources on any element, such as a . However, resources are most often defined on the root element, which is in the example. + +Each resource in a resource dictionary must have a unique key. When you define resources in markup, you assign the unique key through the [x:Key Directive](../../../xaml-services/xkey-directive.md). Typically, the key is a string; however, you can also set it to other object types by using the appropriate markup extensions. Non-string keys for resources are used by certain feature areas in WPF, notably for styles, component resources, and data styling. + +You can use a defined resource with the resource markup extension syntax that specifies the key name of the resource. For example, use the resource as the value of a property on another element. + +[!code-xaml[FEResourceSH_snip#KeyNameUsage](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page2.xaml#keynameusage)] + +In the preceding example, when the XAML loader processes the value `{StaticResource MyBrush}` for the property on , the resource lookup logic first checks the resource dictionary for the element. If doesn't have a definition of the resource key `MyBrush` (in that example it doesn't; its resource collection is empty), the lookup next checks the parent element of , which is . If you define a resource on the root element, all the elements in the logical tree of the can access it. And you can reuse the same resource for setting the value of any property that accepts the same type that the resource represents. In the previous example, the same `MyBrush` resource sets two different properties: the of a , and the of a . + +## Static and dynamic resources + +A resource can be referenced as either static or dynamic. References are created by using either the [StaticResource Markup Extension](staticresource-markup-extension.md) or the [DynamicResource Markup Extension](dynamicresource-markup-extension.md). A markup extension is a XAML feature that lets you specify an object reference by having the markup extension process the attribute string and return the object to a XAML loader. For more information about markup extension behavior, see [Markup Extensions and WPF XAML](markup-extensions-and-wpf-xaml.md). + +When you use a markup extension, you typically provide one or more parameters in string form that are processed by that particular markup extension. The [StaticResource Markup Extension](staticresource-markup-extension.md) processes a key by looking up the value for that key in all available resource dictionaries. Processing happens during load, which is when the loading process needs to assign the property value. The [DynamicResource Markup Extension](dynamicresource-markup-extension.md) instead processes a key by creating an expression, and that expression remains unevaluated until the app runs, at which time the expression is evaluated and provides a value. + +When you reference a resource, the following considerations can influence whether you use a static resource reference or a dynamic resource reference: + +- When determining the overall design of how you create the resources for your app (per page, in the app, in loose XAML, or in a resource-only assembly), consider the following: + +- The app's functionality. Are updating resources in real-time part of your app requirements? +- The respective lookup behavior of that resource reference type. +- The particular property or resource type, and the native behavior of those types. + +## Static resources + +Static resource references work best for the following circumstances: + +- Your app design concentrates most of its resources into page or application-level resource dictionaries. Static resource references aren't reevaluated based on runtime behaviors, such as reloading a page. So there can be some performance benefit to avoiding large numbers of dynamic resource references when they aren't necessary based on your resource and app design. + +- You're setting the value of a property that isn't on a or a . + +- You're creating a resource dictionary that will be compiled into a DLL and packaged as part of the app or shared between apps. + +- You're creating a theme for a custom control and are defining resources that are used within the themes. For this case, you typically do not want the dynamic resource reference lookup behavior; you instead want the static resource reference behavior so that the lookup is predictable and self-contained to the theme. With a dynamic resource reference, even a reference within a theme is left unevaluated until run-time. and there is a chance that when the theme is applied, some local element will redefine a key that your theme is trying to reference, and the local element will fall prior to the theme itself in the lookup. If that happens, your theme will not behave as expected. + +- You're using resources to set large numbers of dependency properties. Dependency properties have effective value caching as enabled by the property system, so if you provide a value for a dependency property that can be evaluated at load time, the dependency property doesn't have to check for a reevaluated expression and can return the last effective value. This technique can be a performance benefit. + +- You want to change the underlying resource for all consumers, or you want to maintain separate writable instances for each consumer by using the [x:Shared Attribute](../../../xaml-services/xshared-attribute.md). + +### Static resource lookup behavior + +The following describes the lookup process that automatically happens when a static resource is referenced by a property or element: + +01. The lookup process checks for the requested key within the resource dictionary defined by the element that sets the property. + +01. The lookup process then traverses the logical tree upward to the parent element and its resource dictionary. This process continues until the root element is reached. + +01. App resources are checked. App resources are those resources within the resource dictionary that is defined by the object for your WPF app. + +Static resource references from within a resource dictionary must reference a resource that has already been defined lexically before the resource reference. Forward references cannot be resolved by a static resource reference. For this reason, design your resource dictionary structure such that resources are defined at or near the beginning of each respective resource dictionary. + +Static resource lookup can extend into themes or into system resources, but this lookup is supported only because the XAML loader defers the request. The deferral is necessary so that the runtime theme at the time the page loads applies properly to the app. However, static resource references to keys that are known to only exist in themes or as system resources aren't recommended, because such references aren't reevaluated if the theme is changed by the user in real time. A dynamic resource reference is more reliable when you request theme or system resources. The exception is when a theme element itself requests another resource. These references should be static resource references, for the reasons mentioned earlier. + +The exception behavior if a static resource reference isn't found varies. If the resource was deferred, then the exception occurs at runtime. If the resource was not deferred, the exception occurs at load time. + +## Dynamic resources + +Dynamic resources work best when: + +- The value of the resource, including system resources, or resources that are otherwise user settable, depends on conditions that aren't known until runtime. For example, you can create setter values that refer to system properties as exposed by , , or . These values are truly dynamic because they ultimately come from the runtime environment of the user and operating system. You might also have application-level themes that can change, where page-level resource access must also capture the change. + +- You're creating or referencing theme styles for a custom control. + +- You intend to adjust the contents of a during an app lifetime. + +- You have a complicated resource structure that has interdependencies, where a forward reference may be required. Static resource references do not support forward references, but dynamic resource references do support them because the resource doesn't need to be evaluated until runtime, and forward references are therefore not a relevant concept. + +- You're referencing a resource that is large from the perspective of a compile or working set, and the resource might not be used immediately when the page loads. Static resource references always load from XAML when the page loads. However, a dynamic resource reference doesn't load until it's used. + +- You're creating a style where setter values might come from other values that are influenced by themes or other user settings. + +- You're applying resources to elements that might be reparented in the logical tree during app lifetime. Changing the parent also potentially changes the resource lookup scope, so if you want the resource for a reparented element to be reevaluated based on the new scope, always use a dynamic resource reference. + +### Dynamic resource lookup behavior + +Resource lookup behavior for a dynamic resource reference parallels the lookup behavior in your code if you call or : + +01. The lookup checks for the requested key within the resource dictionary defined by the element that sets the property: + + - If the element defines a property, the of the element has its dictionary checked. + + - If the element defines a property, the dictionary of the element is checked. + +01. The lookup traverses the logical tree upward to the parent element and its resource dictionary. This process continues until the root element is reached. + +01. App resources are checked. App resources are those resources within the resource dictionary that are defined by the object for your WPF app. + +01. The theme resource dictionary is checked for the currently active theme. If the theme changes at runtime, the value is reevaluated. + +01. System resources are checked. + +Exception behavior (if any) varies: + +- If a resource was requested by a call and was not found, an exception is thrown. + +- If a resource was requested by a call and was not found, no exception is thrown, and the returned value is `null`. If the property being set doesn't accept `null`, then it's still possible that a deeper exception will be thrown, depending on the individual property being set. + +- If a resource was requested by a dynamic resource reference in XAML and was not found, then the behavior depends on the general property system. The general behavior is as if no property setting operation occurred at the level where the resource exists. For instance, if you attempt to set the background on an individual button element using a resource that could not be evaluated, then no value set results, but the effective value can still come from other participants in the property system and value precedence. For instance, the background value might still come from a locally defined button style or from the theme style. For properties that aren't defined by theme styles, the effective value after a failed resource evaluation might come from the default value in the property metadata. + +### Restrictions + +Dynamic resource references have some notable restrictions. At least one of the following conditions must be true: + +- The property being set must be a property on a or . That property must be backed by a . + +- The reference is for a value within a `StyleSetter`. + +- The property being set must be a property on a that is provided as a value of either a or property, or a value. + +Because the property being set must be a or property, most property changes can propagate to the UI because a property change (the changed dynamic resource value) is acknowledged by the property system. Most controls include logic that will force another layout of a control if a changes and that property might affect layout. However, not all properties that have a [DynamicResource Markup Extension](dynamicresource-markup-extension.md) as their value are guaranteed to provide real time updates in the UI. That functionality still might vary depending on the property, as well as depending on the type that owns the property, or even the logical structure of your app. + +## Styles, DataTemplates, and implicit keys + +Although all items in a must have a key, that doesn't mean that all resources must have an explicit `x:Key`. Several object types support an implicit key when defined as a resource, where the key value is tied to the value of another property. This type of key is known as an implicit key, whereas an `x:Key` attribute is an explicit key. You can overwrite any implicit key by specifying an explicit key. + +One important scenario for resources is when you define a . In fact, a is almost always defined as an entry in a resource dictionary, because styles are inherently intended for reuse. For more information about styles, see [Styling and Templating](../controls/styles-templates-overview.md). + +Styles for controls can be both created with and referenced with an implicit key. The theme styles that define the default appearance of a control rely on this implicit key. From the standpoint of requesting it, the implicit key is the of the control itself. From the standpoint of defining the resources, the implicit key is the of the style. Therefore, if you're creating themes for custom controls or creating styles that interact with existing theme styles, you do not need to specify an [x:Key Directive](../../../xaml-services/xkey-directive.md) for that . And if you want to use the themed styles, you do not need to specify any style at all. For instance, the following style definition works, even though the resource doesn't appear to have a key: + +[!code-xaml[FEResourceSH_snip#ImplicitStyle](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page2.xaml#implicitstyle)] + +That style really does have a key: the implicit key `typeof(System.Windows.Controls.Button)`. In markup, you can specify a directly as the type name (or you can optionally use [{x:Type...}](../../../xaml-services/xtype-markup-extension.md) to return a . + +Through the default theme style mechanisms used by WPF, that style is applied as the runtime style of a on the page, even though the itself doesn't attempt to specify its property or a specific resource reference to the style. Your style defined in the page is found earlier in the lookup sequence than the theme dictionary style, using the same key that the theme dictionary style has. You could just specify `` anywhere in the page, and the style you defined with of `Button` would apply to that button. If you want, you can still explicitly key the style with the same type value as for clarity in your markup, but that is optional. + +Implicit keys for styles do not apply on a control if is `true`. (Also note that might be set as part of native behavior for the control class, rather than explicitly on an instance of the control.) Also, in order to support implicit keys for derived class scenarios, the control must override (all existing controls provided as part of WPF include this override). For more information about styles, themes, and control design, see [Guidelines for Designing Stylable Controls](../../../framework/wpf/controls/guidelines-for-designing-stylable-controls.md). + + also has an implicit key. The implicit key for a is the property value. can also be specified as the name of the type rather than explicitly using [{x:Type...}](../../../xaml-services/xtype-markup-extension.md). For details, see [Data Templating Overview](../../../framework/wpf/data/data-templating-overview.md). + +## See also + +- +- [Application resources](optimizing-performance-application-resources.md) +- [Resources and code](resources-and-code.md) +- [Define and reference a resource](how-to-define-and-reference-a-resource.md) +- [Application management overview](../../../framework/wpf/app-development/application-management-overview.md) +- [x:Type markup extension](../../../xaml-services/xtype-markup-extension.md) +- [StaticResource markup extension](staticresource-markup-extension.md) +- [DynamicResource markup extension](dynamicresource-markup-extension.md) diff --git a/dotnet-desktop-guide/framework/wpf/controls/how-to-create-apply-template.md b/dotnet-desktop-guide/framework/wpf/controls/how-to-create-apply-template.md new file mode 100644 index 0000000..b64ce4c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/how-to-create-apply-template.md @@ -0,0 +1,184 @@ +--- +title: Create a template in WPF +description: Learn how to create and reference a control template in Windows Presentation Foundation and .NET Framework. +author: adegeo +ms.author: adegeo +ms.date: 12/03/2020 +no-loc: ["", "", "", "", "", "", "", "", "", "", "", "", "SizeToContent", "MinWidth", "TargetType", "Title"] +ms.topic: how-to +helpviewer_keywords: + - "control contract [WPF]" + - "controls [WPF], visual structure changes" + - "ControlTemplate [WPF], customizing for existing controls" + - "skinning controls [WPF]" + - "controls [WPF], appearance specified by state" + - "templates [WPF], custom for existing controls" +--- + +# Create a template for a control + +With Windows Presentation Foundation (WPF), you can customize an existing control's visual structure and behavior with your own reusable template. Templates can be applied globally to your application, windows and pages, or directly to controls. Most scenarios that require you to create a new control can be covered by instead creating a new template for an existing control. + +In this article, you'll explore creating a new for the control. + +## When to create a ControlTemplate + +Controls have many properties, such as , , and . These properties control different aspects of the control's appearance, but the changes that you can make by setting these properties are limited. For example, you can set the property to blue and to italic on a . When you want to customize the control's appearance beyond what setting the other properties on the control can do, you create a . + +In most user interfaces, a button has the same general appearance: a rectangle with some text. If you wanted to create a rounded button, you could create a new control that inherits from the button or recreates the functionality of the button. In addition, the new user control would provide the circular visual. + +You can avoid creating new controls by customizing the visual layout of an existing control. With a rounded button, you create a with the desired visual layout. + +On the other hand, if you need a control with new functionality, different properties, and new settings, you would create a new . + +## Prerequisites + +Create a new WPF application and in *MainWindow.xaml* (or another window of your choice) set the following properties on the **\** element: + +| | | +| --- | --- | +| **Title** | `Template Intro Sample` | +| **SizeToContent** | `WidthAndHeight` | +| **MinWidth** | `250` | + +Set the content of the **\** element to the following XAML: + +[!code-xaml[Initial](./snippets/how-to-create-apply-template/csharp/Window1.xaml#Initial)] + +In the end, the *MainWindow.xaml* file should look similar to the following: + +[!code-xaml[InitialWhole](./snippets/how-to-create-apply-template/csharp/Window1.xaml#InitialWhole)] + +If you run the application, it looks like the following: + +![WPF window with two unstyled buttons](media/how-to-create-apply-template/unstyled-button.png) + +## Create a ControlTemplate + +The most common way to declare a is as a resource in the `Resources` section in a XAML file. Because templates are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a template affects where the template can be applied. For example, if you declare the template in the root element of your application definition XAML file, the template can be used anywhere in your application. If you define the template in a window, only the controls in that window can use the template. + +To start with, add a `Window.Resources` element to your *MainWindow.xaml* file: + +[!code-xaml[WindowResStart](./snippets/how-to-create-apply-template/csharp/Window2.xaml#WindowResStart)] + +Create a new **\** with the following properties set: + +| | | +| --- | --- | +| **x:Key** | `roundbutton` | +| **TargetType** | `Button` | + +This control template will be simple: + +- a root element for the control, a +- an to draw the rounded appearance of the button +- a to display the user-specified button content + +[!code-xaml[ControlTemplate](./snippets/how-to-create-apply-template/csharp/Window3.xaml#ControlTemplate)] + +### TemplateBinding + +When you create a new , you still might want to use the public properties to change the control's appearance. The [TemplateBinding](../advanced/templatebinding-markup-extension.md) markup extension binds a property of an element that is in the to a public property that is defined by the control. When you use a [TemplateBinding](../advanced/templatebinding-markup-extension.md), you enable properties on the control to act as parameters to the template. That is, when a property on a control is set, that value is passed on to the element that has the [TemplateBinding](../advanced/templatebinding-markup-extension.md) on it. + +### Ellipse + +Notice that the **:::no-loc text="Fill":::** and **:::no-loc text="Stroke":::** properties of the **\** element are bound to the control's and properties. + +### ContentPresenter + +A [\](xref:System.Windows.Controls.ContentPresenter) element is also added to the template. Because this template is designed for a button, take into consideration that the button inherits from . The button presents the content of the element. You can set anything inside of the button, such as plain text or even another control. Both of the following are valid buttons: + +```xaml + + + + + +``` + +In both of the previous examples, the text and the checkbox are set as the [Button.Content](xref:System.Windows.Controls.ContentControl.Content) property. Whatever is set as the content can be presented through a **\**, which is what the template does. + +If the is applied to a type, such as a `Button`, a is searched for in the element tree. If the `ContentPresenter` is found, the template automatically binds the control's property to the `ContentPresenter`. + +## Use the template + +Find the buttons that were declared at the start of this article. + +[!code-xaml[Initial](./snippets/how-to-create-apply-template/csharp/Window1.xaml#Initial)] + +Set the second button's property to the `roundbutton` resource: + +[!code-xaml[StyledButton](./snippets/how-to-create-apply-template/csharp/Window3.xaml#StyledButton)] + +If you run the project and look at the result, you'll see that the button has a rounded background. + +![WPF window with one template oval button](media/how-to-create-apply-template/styled-button.png) + +You may have noticed that the button isn't a circle but is skewed. Because of the way the **\** element works, it always expands to fill the available space. Make the circle uniform by changing the button's **:::no-loc text="width":::** and **:::no-loc text="height":::** properties to the same value: + +[!code-xaml[StyledButtonSize](./snippets/how-to-create-apply-template/csharp/Window3.xaml#StyledButtonSize)] + +![WPF window with one template circular button](media/how-to-create-apply-template/styled-uniform-button.png) + +## Add a Trigger + +Even though a button with a template applied looks different, it behaves the same as any other button. If you press the button, the event fires. However, you may have noticed that when you move your mouse over the button, the button's visuals don't change. These visual interactions are all defined by the template. + +With the dynamic event and property systems that WPF provides, you can watch a specific property for a value and then restyle the template when appropriate. In this example, you'll watch the button's property. When the mouse is over the control, style the **\** with a new color. This type of trigger is known as a *PropertyTrigger*. + +For this to work, you'll need to add a name to the **\** that you can reference. Give it the name of **backgroundElement**. + +[!code-xaml[EllipseName](./snippets/how-to-create-apply-template/csharp/Window4.xaml#EllipseName)] + +Next, add a new to the [ControlTemplate.Triggers](xref:System.Windows.Controls.ControlTemplate.Triggers) collection. The trigger will watch the `IsMouseOver` event for the value `true`. + +[!code-xaml[ControlTemplate](./snippets/how-to-create-apply-template/csharp/Window4.xaml?name=ControlTemplate&highlight=6-10)] + +Next, add a **\** to the **\** that changes the **Fill** property of the **\** to a new color. + +[!code-xaml[MouseOver](./snippets/how-to-create-apply-template/csharp/Window5.xaml#MouseOver)] + +Run the project. Notice that when you move the mouse over the button, the color of the **\** changes. + +![mouse moves over WPF button to change the fill color](media/how-to-create-apply-template/mouse-move-over-button.gif) + +## Use a VisualState + +Visual states are defined and triggered by a control. For example, when the mouse is moved on top of the control, the `CommonStates.MouseOver` state is triggered. You can animate property changes based on the current state of the control. In the previous section, a **\** was used to change the foreground of the button to `AliceBlue` when the `IsMouseOver` property was `true`. Instead, create a visual state that animates the change of this color, providing a smooth transition. For more information about *VisualStates*, see [Styles and templates in WPF](styles-templates-overview.md#visual-states). + +To convert the **\** to an animated visual state, First, remove the **\** element from your template. + +[!code-xaml[CleanTemplate](./snippets/how-to-create-apply-template/csharp/Window5.xaml#CleanTemplate)] + +Next, in the **\** root of the control template, add the **\** element with a **\** for `CommonStates`. Define two states, `Normal` and `MouseOver`. + +[!code-xaml[VisualState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#VisualState)] + +Any animations defined in a **\** are applied when that state is triggered. Create animations for each state. Animations are put inside of a **\** element. For more information about storyboards, see [Storyboards Overview](../graphics-multimedia/storyboards-overview.md). + +- Normal + + This state animates the ellipse fill, restoring it to the control's `Background` color. + + [!code-xaml[NormalState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#NormalState)] + +- MouseOver + + This state animates the ellipse `Background` color to a new color: `Yellow`. + + [!code-xaml[MouseOverState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#MouseOverState)] + +The **\** should now look like the following. + +[!code-xaml[FinalTemplate](./snippets/how-to-create-apply-template/csharp/Window7.xaml#FinalTemplate)] + +Run the project. Notice that when you move the mouse over the button, the color of the **\** animates. + +![mouse moves over WPF button to change visual state](media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif) + +## Next steps + +- [Styles and templates in WPF](styles-templates-overview.md) +- [Overview of XAML Resources](../advanced/xaml-resources-define.md) diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif new file mode 100644 index 0000000..cdd2656 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button.gif b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button.gif new file mode 100644 index 0000000..b18823b Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button.gif differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-button.png b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-button.png new file mode 100644 index 0000000..21ccdf9 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-button.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-uniform-button.png b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-uniform-button.png new file mode 100644 index 0000000..89e43b2 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/styled-uniform-button.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/unstyled-button.png b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/unstyled-button.png new file mode 100644 index 0000000..c38a044 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/how-to-create-apply-template/unstyled-button.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/create-a-style-explicit-textblock.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/create-a-style-explicit-textblock.png new file mode 100644 index 0000000..81d0145 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/create-a-style-explicit-textblock.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-eventtriggers.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-eventtriggers.png new file mode 100644 index 0000000..e3c7d79 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-eventtriggers.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-listboxbefore.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-listboxbefore.png new file mode 100644 index 0000000..40b8e15 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-listboxbefore.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-photosasimages.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-photosasimages.png new file mode 100644 index 0000000..cbbbb2b Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-photosasimages.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png new file mode 100644 index 0000000..e03d4f8 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png new file mode 100644 index 0000000..1517b88 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbefore.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbefore.png new file mode 100644 index 0000000..b1707b9 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocksbefore.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-triggers.png b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-triggers.png new file mode 100644 index 0000000..24cb704 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/media/styles-and-templates-overview/stylingintro-triggers.png differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.cs new file mode 100644 index 0000000..50bab6f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.cs @@ -0,0 +1,14 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.xaml new file mode 100644 index 0000000..df37f82 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/App.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj new file mode 100644 index 0000000..c453c2b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj @@ -0,0 +1,11 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.cs new file mode 100644 index 0000000..2246531 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.cs @@ -0,0 +1,28 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; +using System.Windows.Data; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void WindowLoaded(object sender, RoutedEventArgs e) + { + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Clicked"); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.xaml new file mode 100644 index 0000000..bd1bb12 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.xaml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml new file mode 100644 index 0000000..b49fd59 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs new file mode 100644 index 0000000..dbfa52e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml new file mode 100644 index 0000000..ef27f8d --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs new file mode 100644 index 0000000..6184fbb --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml new file mode 100644 index 0000000..018d7ce --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs new file mode 100644 index 0000000..960a904 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window3.xaml + /// + public partial class Window3 : Window + { + public Window3() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml new file mode 100644 index 0000000..fe6cab1 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs new file mode 100644 index 0000000..e6a7dff --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window4.xaml + /// + public partial class Window4 : Window + { + public Window4() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml new file mode 100644 index 0000000..04274c9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs new file mode 100644 index 0000000..95cf6d8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window5.xaml + /// + public partial class Window5 : Window + { + public Window5() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml new file mode 100644 index 0000000..c61499a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs new file mode 100644 index 0000000..8db370c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window6.xaml + /// + public partial class Window6 : Window + { + public Window6() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml new file mode 100644 index 0000000..5dbcb54 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs new file mode 100644 index 0000000..c37e7de --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window7.xaml + /// + public partial class Window7 : Window + { + public Window7() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Clicked"); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml new file mode 100644 index 0000000..254fe99 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml @@ -0,0 +1,25 @@ + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs new file mode 100644 index 0000000..f28be5f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for ExplicitStyle.xaml + /// + public partial class ExplicitStyle : Window + { + public ExplicitStyle() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml new file mode 100644 index 0000000..3c2510b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs new file mode 100644 index 0000000..66e60e8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for WindowSingleResource.xaml + /// + public partial class WindowSingleResource : Window + { + public WindowSingleResource() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml new file mode 100644 index 0000000..7f4e220 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml.vb new file mode 100644 index 0000000..084cbe9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml new file mode 100644 index 0000000..f62477d --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..e2e55ee --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb @@ -0,0 +1,6 @@ +Class MainWindow + + Private Sub WindowLoaded(sender As Object, e As Windows.RoutedEventArgs) + + End Sub +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj new file mode 100644 index 0000000..c453c2b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj @@ -0,0 +1,11 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.cs new file mode 100644 index 0000000..50bab6f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.cs @@ -0,0 +1,14 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.xaml new file mode 100644 index 0000000..a4bba90 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/App.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj new file mode 100644 index 0000000..661e3a7 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj @@ -0,0 +1,29 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.cs new file mode 100644 index 0000000..185500d --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.cs @@ -0,0 +1,27 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; +using System.Windows.Data; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private PhotoList _photos; + + public MainWindow() + { + InitializeComponent(); + } + + private void WindowLoaded(object sender, RoutedEventArgs e) + { + _photos = (PhotoList) (Resources["MyPhotos"] as ObjectDataProvider).Data; + _photos.Path = "images"; + } + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.xaml new file mode 100644 index 0000000..b263d5a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/MainWindow.xaml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Photo.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Photo.cs new file mode 100644 index 0000000..34bd270 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Photo.cs @@ -0,0 +1,19 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace IntroToStylingAndTemplating +{ + // + public class Photo + { + public Photo(string path) + { + Source = path; + } + + public string Source { get; } + + public override string ToString() => Source; + } + // +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/PhotoList.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/PhotoList.cs new file mode 100644 index 0000000..8c78cd7 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/PhotoList.cs @@ -0,0 +1,55 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.ObjectModel; +using System.IO; + +namespace IntroToStylingAndTemplating +{ + public class PhotoList : ObservableCollection + { + private DirectoryInfo _directory; + + public PhotoList() + { + } + + public PhotoList(string path) : this(new DirectoryInfo(path)) + { + } + + public PhotoList(DirectoryInfo directory) + { + _directory = directory; + Update(); + } + + public string Path + { + set + { + _directory = new DirectoryInfo(value); + Update(); + } + get { return _directory.FullName; } + } + + public DirectoryInfo Directory + { + set + { + _directory = value; + Update(); + } + get { return _directory; } + } + + private void Update() + { + foreach (var f in _directory.GetFiles("*.jpg")) + { + Add(new Photo(f.FullName)); + } + } + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml new file mode 100644 index 0000000..4358f66 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml.cs new file mode 100644 index 0000000..dbfa52e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window1.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml new file mode 100644 index 0000000..cf47444 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs new file mode 100644 index 0000000..65023c6 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + // + textblock1.Style = (Style)Resources["TitleText"]; + // + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml new file mode 100644 index 0000000..5de6707 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml @@ -0,0 +1,20 @@ + + + + + + My Pictures + Check out my new pictures! + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml.cs new file mode 100644 index 0000000..960a904 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window3.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window3.xaml + /// + public partial class Window3 : Window + { + public Window3() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml new file mode 100644 index 0000000..541d94a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml.cs new file mode 100644 index 0000000..e6a7dff --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window4.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window4.xaml + /// + public partial class Window4 : Window + { + public Window4() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml new file mode 100644 index 0000000..c2ea90c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml.cs new file mode 100644 index 0000000..95cf6d8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window5.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window5.xaml + /// + public partial class Window5 : Window + { + public Window5() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml new file mode 100644 index 0000000..2851b1e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml @@ -0,0 +1,53 @@ + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml.cs new file mode 100644 index 0000000..8db370c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/Window6.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window6.xaml + /// + public partial class Window6 : Window + { + public Window6() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml new file mode 100644 index 0000000..254fe99 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml @@ -0,0 +1,25 @@ + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml.cs new file mode 100644 index 0000000..f28be5f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for ExplicitStyle.xaml + /// + public partial class ExplicitStyle : Window + { + public ExplicitStyle() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml new file mode 100644 index 0000000..3c2510b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml.cs new file mode 100644 index 0000000..66e60e8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for WindowSingleResource.xaml + /// + public partial class WindowSingleResource : Window + { + public WindowSingleResource() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower1.jpg new file mode 100644 index 0000000..6eb28de Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower2.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower2.jpg new file mode 100644 index 0000000..f3004f2 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/flower2.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf1.jpg new file mode 100644 index 0000000..1ab47b0 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf2.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf2.jpg new file mode 100644 index 0000000..8dae26f Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/leaf2.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/winter1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/winter1.jpg new file mode 100644 index 0000000..8baa8b4 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/csharp/images/winter1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml new file mode 100644 index 0000000..7f4e220 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml.vb new file mode 100644 index 0000000..084cbe9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml new file mode 100644 index 0000000..e8ad57a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + My Pictures + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..0adf714 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb @@ -0,0 +1,7 @@ +Class MainWindow + Private Sub Window_Loaded(sender As Object, e As Windows.RoutedEventArgs) + ' + textblock1.Style = CType(Resources("TitleText"), Windows.Style) + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Photo.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Photo.vb new file mode 100644 index 0000000..59866e0 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/Photo.vb @@ -0,0 +1,13 @@ +' +Public Class Photo + Sub New(ByVal path As String) + Source = path + End Sub + + Public ReadOnly Property Source As String + + Public Overrides Function ToString() As String + Return Source + End Function +End Class +' diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj new file mode 100644 index 0000000..c453c2b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj @@ -0,0 +1,11 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.cs new file mode 100644 index 0000000..50bab6f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.cs @@ -0,0 +1,14 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.xaml new file mode 100644 index 0000000..a4bba90 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/App.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj new file mode 100644 index 0000000..661e3a7 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj @@ -0,0 +1,29 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.cs new file mode 100644 index 0000000..185500d --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.cs @@ -0,0 +1,27 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; +using System.Windows.Data; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private PhotoList _photos; + + public MainWindow() + { + InitializeComponent(); + } + + private void WindowLoaded(object sender, RoutedEventArgs e) + { + _photos = (PhotoList) (Resources["MyPhotos"] as ObjectDataProvider).Data; + _photos.Path = "images"; + } + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.xaml new file mode 100644 index 0000000..b263d5a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.xaml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Photo.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Photo.cs new file mode 100644 index 0000000..34bd270 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Photo.cs @@ -0,0 +1,19 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace IntroToStylingAndTemplating +{ + // + public class Photo + { + public Photo(string path) + { + Source = path; + } + + public string Source { get; } + + public override string ToString() => Source; + } + // +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/PhotoList.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/PhotoList.cs new file mode 100644 index 0000000..8c78cd7 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/PhotoList.cs @@ -0,0 +1,55 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.ObjectModel; +using System.IO; + +namespace IntroToStylingAndTemplating +{ + public class PhotoList : ObservableCollection + { + private DirectoryInfo _directory; + + public PhotoList() + { + } + + public PhotoList(string path) : this(new DirectoryInfo(path)) + { + } + + public PhotoList(DirectoryInfo directory) + { + _directory = directory; + Update(); + } + + public string Path + { + set + { + _directory = new DirectoryInfo(value); + Update(); + } + get { return _directory.FullName; } + } + + public DirectoryInfo Directory + { + set + { + _directory = value; + Update(); + } + get { return _directory; } + } + + private void Update() + { + foreach (var f in _directory.GetFiles("*.jpg")) + { + Add(new Photo(f.FullName)); + } + } + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml new file mode 100644 index 0000000..4358f66 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml.cs new file mode 100644 index 0000000..dbfa52e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml new file mode 100644 index 0000000..cf47444 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml.cs new file mode 100644 index 0000000..65023c6 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + // + textblock1.Style = (Style)Resources["TitleText"]; + // + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml new file mode 100644 index 0000000..5de6707 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml @@ -0,0 +1,20 @@ + + + + + + My Pictures + Check out my new pictures! + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml.cs new file mode 100644 index 0000000..960a904 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window3.xaml + /// + public partial class Window3 : Window + { + public Window3() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml new file mode 100644 index 0000000..541d94a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml.cs new file mode 100644 index 0000000..e6a7dff --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window4.xaml + /// + public partial class Window4 : Window + { + public Window4() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml new file mode 100644 index 0000000..c2ea90c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml.cs new file mode 100644 index 0000000..95cf6d8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window5.xaml + /// + public partial class Window5 : Window + { + public Window5() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml new file mode 100644 index 0000000..2851b1e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml @@ -0,0 +1,53 @@ + + + + + + + + My Pictures + Check out my new pictures! + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml.cs new file mode 100644 index 0000000..8db370c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for Window6.xaml + /// + public partial class Window6 : Window + { + public Window6() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml new file mode 100644 index 0000000..254fe99 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml @@ -0,0 +1,25 @@ + + + + + + + + + My Pictures + Check out my new pictures! + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs new file mode 100644 index 0000000..f28be5f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for ExplicitStyle.xaml + /// + public partial class ExplicitStyle : Window + { + public ExplicitStyle() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml new file mode 100644 index 0000000..3c2510b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs new file mode 100644 index 0000000..66e60e8 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace IntroToStylingAndTemplating +{ + /// + /// Interaction logic for WindowSingleResource.xaml + /// + public partial class WindowSingleResource : Window + { + public WindowSingleResource() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower1.jpg new file mode 100644 index 0000000..6eb28de Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower2.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower2.jpg new file mode 100644 index 0000000..f3004f2 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/flower2.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf1.jpg new file mode 100644 index 0000000..1ab47b0 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf2.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf2.jpg new file mode 100644 index 0000000..8dae26f Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf2.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/winter1.jpg b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/winter1.jpg new file mode 100644 index 0000000..8baa8b4 Binary files /dev/null and b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/csharp/images/winter1.jpg differ diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml new file mode 100644 index 0000000..7f4e220 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml.vb new file mode 100644 index 0000000..084cbe9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml new file mode 100644 index 0000000..e8ad57a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + My Pictures + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..0adf714 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml.vb @@ -0,0 +1,7 @@ +Class MainWindow + Private Sub Window_Loaded(sender As Object, e As Windows.RoutedEventArgs) + ' + textblock1.Style = CType(Resources("TitleText"), Windows.Style) + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Photo.vb b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Photo.vb new file mode 100644 index 0000000..59866e0 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/Photo.vb @@ -0,0 +1,13 @@ +' +Public Class Photo + Sub New(ByVal path As String) + Source = path + End Sub + + Public ReadOnly Property Source As String + + Public Overrides Function ToString() As String + Return Source + End Function +End Class +' diff --git a/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj new file mode 100644 index 0000000..c453c2b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj @@ -0,0 +1,11 @@ + + + + WinExe + netcoreapp3.1 + IntroToStylingAndTemplating + true + IntroToStylingAndTemplating + + + diff --git a/dotnet-desktop-guide/framework/wpf/controls/styles-templates-overview.md b/dotnet-desktop-guide/framework/wpf/controls/styles-templates-overview.md new file mode 100644 index 0000000..7b0f6e7 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/controls/styles-templates-overview.md @@ -0,0 +1,239 @@ +--- +title: Styles and templates +description: Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET Framework. Understand the types of XAML resources related to styles and themes. +author: adegeo +ms.author: adegeo +ms.date: 09/09/2019 +ms.topic: overview +dev_langs: + - "csharp" + - "vb" +--- + +# Styles and templates in WPF + +Windows Presentation Foundation (WPF) styling and templating refer to a suite of features that let developers and designers create visually compelling effects and a consistent appearance for their product. When customizing the appearance of an app, you want a strong styling and templating model that enables maintenance and sharing of appearance within and among apps. WPF provides that model. + +Another feature of the WPF styling model is the separation of presentation and logic. Designers can work on the appearance of an app by using only XAML at the same time that developers work on the programming logic by using C# or Visual Basic. + +This overview focuses on the styling and templating aspects of the app and doesn't discuss any data-binding concepts. For information about data binding, see [Data Binding Overview](../data/data-binding-overview.md). + +It's important to understand resources, which are what enable styles and templates to be reused. For more information about resources, see [XAML Resources](../advanced/xaml-resources-define.md). + +## Sample + +The sample code provided in this overview is based on a [simple photo browsing application](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating) shown in the following illustration. + +![Styled ListView](./media/styles-and-templates-overview/stylingintro-triggers.png "StylingIntro_triggers") + +This simple photo sample uses styling and templating to create a visually compelling user experience. The sample has two elements and a control that is bound to a list of images. + +For the complete sample, see [Introduction to Styling and Templating Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating). + +## Styles + +You can think of a as a convenient way to apply a set of property values to multiple elements. You can use a style on any element that derives from or such as a or a . + +The most common way to declare a style is as a resource in the `Resources` section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied. For example, if you declare the style in the root element of your app definition XAML file, the style can be used anywhere in your app. + +For example, the following XAML code declares two styles for a `TextBlock`, one automatically applied to all `TextBlock` elements, and another that must be explicitly referenced. + +[!code-xaml[SnippetDefaultTextBlockStyleBasedOn](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetDefaultTextBlockStyleBasedOn)] + +Here is an example of the styles declared above being used. + +[!code-xaml[SnippetTextBlocksExplicit](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetTextBlocksExplicit)] + +![Styled textblocks](./media/styles-and-templates-overview/stylingintro-textblocks.png) + +## ControlTemplates + +In WPF, the of a control defines the appearance of the control. You can change the structure and appearance of a control by defining a new and assigning it to a control. In many cases, templates give you enough flexibility so that you do not have to write your own custom controls. + +Each control has a default template assigned to the [Control.Template](xref:System.Windows.Controls.Control.Template) property. The template connects the visual presentation of the control with the control's capabilities. Because you define a template in XAML, you can change the control's appearance without writing any code. Each template is designed for a specific control, such as a . + +Commonly you declare a template as a resource on the `Resources` section of a XAML file. As with all resources, scoping rules apply. + +Control templates are a lot more involved than a style. This is because the control template rewrites the visual appearance of the entire control, while a style simply applies property changes to the existing control. However, since the template of a control is applied by setting the [Control.Template](xref:System.Windows.Controls.Control.Template) property, you can use a style to define or set a template. + +Designers generally allow you to create a copy of an existing template and modify it. For example, in the Visual Studio WPF designer, select a `CheckBox` control, and then right-click and select **Edit template** > **Create a copy**. This command generates a *style that defines a template*. + +```xaml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml.cs new file mode 100644 index 0000000..2cfed7c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace bindings +{ + /// + /// Interaction logic for DataValidation.xaml + /// + public partial class DataValidation : Window + { + public DataValidation() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DateConverter.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DateConverter.cs new file mode 100644 index 0000000..4360d0a --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/DateConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using System.Globalization; +using System.Windows.Data; + +namespace bindings +{ + [ValueConversion(typeof(DateTime), typeof(string))] + public class DateConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + DateTime date = (DateTime)value; + return date.ToShortDateString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + string strValue = value.ToString(); + DateTime resultDateTime; + if (DateTime.TryParse(strValue, out resultDateTime)) + { + return resultDateTime; + } + return value; + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml new file mode 100644 index 0000000..0c40cdf --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml.cs new file mode 100644 index 0000000..8369efa --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/EmptyBinding.xaml.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace bindings +{ + /// + /// Interaction logic for EmptyBinding.xaml + /// + public partial class EmptyBinding : UserControl + { + public EmptyBinding() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/FutureDateRule.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/FutureDateRule.cs new file mode 100644 index 0000000..bf55bd1 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/FutureDateRule.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Windows.Controls; + +namespace bindings +{ + // + public class FutureDateRule : ValidationRule + { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + // Test if date is valid + if (DateTime.TryParse(value.ToString(), out DateTime date)) + { + // Date is not in the future, fail + if (DateTime.Now > date) + return new ValidationResult(false, "Please enter a date in the future."); + } + else + { + // Date is not a valid date, fail + return new ValidationResult(false, "Value is not a valid date."); + } + + // Date is valid and in the future, pass + return ValidationResult.ValidResult; + } + } + // +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml new file mode 100644 index 0000000..978ffcd --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..660283f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace bindings +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/ManualBinding.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/ManualBinding.cs new file mode 100644 index 0000000..ef9ab49 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/ManualBinding.cs @@ -0,0 +1,26 @@ +using System.Windows.Controls; +using System.Windows.Data; +using SDKSample; + +namespace bindings +{ + class ManualBinding + { + public TextBox myText; + + public void BindTextBox() + { + // + // Make a new source + var myDataObject = new MyData(); + var myBinding = new Binding("ColorName") + { + Source = myDataObject + }; + + // Bind the data source to the TextBox control's Text dependency property + myText.SetBinding(TextBlock.TextProperty, myBinding); + // + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MyData.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MyData.cs new file mode 100644 index 0000000..d1dd33f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/MyData.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SDKSample +{ + class MyData + { + public string ColorName => "Red"; + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/SpecialFeatures.cs b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/SpecialFeatures.cs new file mode 100644 index 0000000..2ade086 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/SpecialFeatures.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace bindings +{ + public enum SpecialFeatures + { + None, + Color, + Highlight + } +} diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj new file mode 100644 index 0000000..248170e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj @@ -0,0 +1,9 @@ + + + + WinExe + netcoreapp3.1 + true + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml new file mode 100644 index 0000000..2db4e85 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml.vb new file mode 100644 index 0000000..1b090eb --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/Application.xaml.vb @@ -0,0 +1,10 @@ +Imports System.Collections.ObjectModel + +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + + Public ReadOnly Property AuctionItems As ObservableCollection(Of AuctionItem) = New ObservableCollection(Of AuctionItem) + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/AuctionItem.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/AuctionItem.vb new file mode 100644 index 0000000..549c7bc --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/AuctionItem.vb @@ -0,0 +1,10 @@ +Imports System.ComponentModel + +Public Class AuctionItem + Implements INotifyPropertyChanged + + Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged + + Public CurrentPrice As Integer + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml new file mode 100644 index 0000000..81e63a6 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + Add Sorting + Add Filtering + Add Grouping + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml.vb new file mode 100644 index 0000000..84c05c0 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/CollectionView.xaml.vb @@ -0,0 +1,58 @@ +Imports System.ComponentModel + +Public Class CollectionView + + Public listingDataView As CollectionViewSource + + Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) + listingDataView = CType(Resources("listingDataView"), CollectionViewSource) + + End Sub + + ' + Private Sub AddFilteringCheckBox_Checked(sender As Object, e As RoutedEventArgs) + Dim checkBox = DirectCast(sender, CheckBox) + + If checkBox.IsChecked = True Then + AddHandler listingDataView.Filter, AddressOf ListingDataView_Filter + Else + RemoveHandler listingDataView.Filter, AddressOf ListingDataView_Filter + End If + End Sub + ' + + Private Sub AddGroupingCheckBox_Checked(sender As Object, e As RoutedEventArgs) + ' + ' This groups the items in the view by the property "Category" + Dim groupDescription = New PropertyGroupDescription() + groupDescription.PropertyName = "Category" + listingDataView.GroupDescriptions.Add(groupDescription) + ' + End Sub + + ' + Private Sub ListingDataView_Filter(sender As Object, e As FilterEventArgs) + + ' Start with everything excluded + e.Accepted = False + + Dim product As AuctionItem = TryCast(e.Item, AuctionItem) + + If product IsNot Nothing Then + + ' Only include products with prices lower than 25 + If product.CurrentPrice < 25 Then e.Accepted = True + + End If + + End Sub + ' + + ' + Private Sub AddSortCheckBox_Checked(sender As Object, e As RoutedEventArgs) + ' Sort the items first by Category And then by StartDate + listingDataView.SortDescriptions.Add(New SortDescription("Category", ListSortDirection.Ascending)) + listingDataView.SortDescriptions.Add(New SortDescription("StartDate", ListSortDirection.Ascending)) + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ColorBrushConverter.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ColorBrushConverter.vb new file mode 100644 index 0000000..0018d0e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ColorBrushConverter.vb @@ -0,0 +1,14 @@ +' + +Public Class ColorBrushConverter + Implements IValueConverter + Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert + Dim color As Color = CType(value, Color) + Return New SolidColorBrush(color) + End Function + + Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack + Return Nothing + End Function +End Class +' diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/FutureDateRule.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/FutureDateRule.vb new file mode 100644 index 0000000..e30e10e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/FutureDateRule.vb @@ -0,0 +1,30 @@ +Imports System.Globalization + +' +Public Class FutureDateRule + Inherits ValidationRule + + Public Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As ValidationResult + + Dim inputDate As Date + + ' Test if date is valid + If Date.TryParse(value.ToString, inputDate) Then + + ' Date is not in the future, fail + If Date.Now > inputDate Then + Return New ValidationResult(False, "Please enter a date in the future.") + End If + + Else + ' // Date Is Not a valid date, fail + Return New ValidationResult(False, "Value is not a valid date.") + End If + + ' Date is valid and in the future, pass + Return ValidationResult.ValidResult + + End Function + +End Class +' diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml new file mode 100644 index 0000000..065ad48 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..922a5de --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MainWindow.xaml.vb @@ -0,0 +1,3 @@ +Class MainWindow + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ManualBinding.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ManualBinding.vb new file mode 100644 index 0000000..1646c04 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/ManualBinding.vb @@ -0,0 +1,19 @@ +Imports bindings.SDKSample + +Public Class ManualBinding + + Public myText As TextBox + + Public Sub BindTextBox() + ' + ' Make a New source + Dim myDataObject As New MyData + Dim myBinding As New Binding("ColorName") + myBinding.Source = myDataObject + + ' Bind the data source to the TextBox control's Text dependency property + myText.SetBinding(TextBlock.TextProperty, myBinding) + ' + End Sub + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MyData.vb b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MyData.vb new file mode 100644 index 0000000..02e86e5 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/MyData.vb @@ -0,0 +1,9 @@ +Namespace SDKSample + + Public Class MyData + + Public ReadOnly Property ColorName As String = "Red" + + End Class + +End Namespace diff --git a/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj new file mode 100644 index 0000000..6eab484 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + netcoreapp3.1 + bindings + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/data/toc.yml b/dotnet-desktop-guide/framework/wpf/data/toc.yml index 4c9beeb..473d134 100644 --- a/dotnet-desktop-guide/framework/wpf/data/toc.yml +++ b/dotnet-desktop-guide/framework/wpf/data/toc.yml @@ -1,7 +1,7 @@ - name: Data binding documentation href: index.md - name: Overview - href: /dotnet/desktop-wpf/data/data-binding-overview?toc=/dotnet/framework/wpf/data/toc.json&bc=/dotnet/framework/wpf/data/breadcrumb/toc.json + href: data-binding-overview.md - name: Binding sources href: binding-sources-overview.md - name: Data templating diff --git a/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md b/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md index f54e656..957b84d 100644 --- a/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md +++ b/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md @@ -1,6 +1,6 @@ --- title: Data binding overview -description: Learn about the different data sources you can add to your project in Windows Presentation Foundation for .NET Core. Data sources can be bound to XAML elements to create dynamic apps. +description: Learn about the different data sources you can add to your project in Windows Presentation Foundation for .NET. Data sources can be bound to XAML elements to create dynamic apps. author: adegeo ms.date: 09/19/2019 ms.author: adegeo @@ -10,7 +10,7 @@ dev_langs: - "vb" --- -# Data binding overview in WPF +# Data binding overview (WPF .NET) Data binding in Windows Presentation Foundation (WPF) provides a simple and consistent way for apps to present and interact with data. Elements can be bound to data from a variety of data sources in the form of .NET objects and XML. Any such as and any , such as and , have built-in functionality to enable flexible styling of single data items or collections of data items. Sort, filter, and group views can be generated on top of the data. @@ -400,7 +400,7 @@ With the custom and t If your has associated validation rules but you do not specify an on the bound control, a default will be used to notify users when there is a validation error. The default is a control template that defines a red border in the adorner layer. With the default and the , the UI of the *StartPriceEntryForm* looks like the following when there is a validation error. -![Data binding validation error](./media/data-binding-overview/demo-validation-price.png "DataBindingDemo_ValidationDefault") +![Data binding validation error default](./media/data-binding-overview/demo-validation-price.png "DataBindingDemo_ValidationDefault") For an example of how to provide logic to validate all controls in a dialog box, see the Custom Dialog Boxes section in the [Dialog boxes overview](../../../framework/wpf/app-development/dialog-boxes-overview.md). diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md b/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md index d34ecb0..5201e6e 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md +++ b/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md @@ -1,6 +1,6 @@ --- title: Create a style for a control -description: Learn how to create and reference a control style in Windows Presentation Foundation and .NET Core. +description: Learn how to create and reference a control style in Windows Presentation Foundation and .NET. author: adegeo ms.author: adegeo ms.date: 09/12/2019 @@ -11,7 +11,7 @@ dev_langs: #no-loc: [TextBlock, Setter] --- -# Create a style for a control in WPF +# Create a style for a control (WPF .NET) With Windows Presentation Foundation (WPF), you can customize an existing control's appearance with your own reusable style. Styles can be applied globally to your app, windows and pages, or directly to controls. @@ -37,7 +37,7 @@ A is a convenient way to apply a set of property val [!code-xaml[TextBlocks](./snippets/styles-templates-create-apply-style/csharp/Window1.xaml#SnippetTextBlocks)] -![Styling sample screenshot](./media/styles-and-templates-overview/stylingintro-textblocksbefore.png "StylingIntro_TextBlocksBefore") +![Styling sample screenshot before](./media/styles-and-templates-overview/stylingintro-textblocksbefore.png "StylingIntro_TextBlocksBefore") You can change the default appearance by setting properties, such as and , on each element directly. However, if you want your elements to share some properties, you can create a in the `Resources` section of your XAML file, as shown here. @@ -47,7 +47,7 @@ When you set the of your style to the Now the elements appear as follows. -![Styling sample screenshot](./media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png "StylingIntro_TextBlocksBaseStyle") +![Styling sample screenshot base style](./media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png "StylingIntro_TextBlocksBaseStyle") ## Apply a style explicitly @@ -63,7 +63,7 @@ To apply the style, set the prop Notice that the first element has the style applied to it while the second TextBlock element remains unchanged. The implicit style from the previous section was changed to a style that declared the `x:Key` attribute, meaning, the only element affected by the style is the one that referenced the style directly. -![Styling sample screenshot](./media/styles-and-templates-overview/create-a-style-explicit-textblock.png "create-a-style-explicit-textblock") +![Styling sample screenshot textblock](./media/styles-and-templates-overview/create-a-style-explicit-textblock.png "create-a-style-explicit-textblock") Once a style is applied, explicitly or implicitly, it becomes sealed and can't be changed. If you want to change a style that has been applied, create a new style to replace the existing one. For more information, see the property. diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md b/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md index 82d1c8f..90ececa 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md +++ b/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md @@ -1,6 +1,6 @@ --- title: Styles and templates -description: Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET Core. Understand the types of XAML resources related to styles and themes. +description: Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET. Understand the types of XAML resources related to styles and themes. author: adegeo ms.author: adegeo ms.date: 09/09/2019 @@ -10,7 +10,7 @@ dev_langs: - "vb" --- -# Styles and templates in WPF +# Styles and templates (WPF .NET) Windows Presentation Foundation (WPF) styling and templating refer to a suite of features that let developers and designers create visually compelling effects and a consistent appearance for their product. When customizing the appearance of an app, you want a strong styling and templating model that enables maintenance and sharing of appearance within and among apps. WPF provides that model. diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md b/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md index 6d9d22f..1508623 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md +++ b/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md @@ -1,21 +1,19 @@ --- title: Define XAML resources -description: Learn about XAML resources in WPF for .NET Core. Understand the types of XAML resources and learn how to define XAML resources. +description: Learn about XAML resources in WPF for .NET. Understand the types of XAML resources and learn how to define XAML resources. author: adegeo ms.author: adegeo ms.date: 08/21/2019 ms.topic: overview --- -# Overview of XAML resources +# Overview of XAML resources (WPF .NET) A resource is an object that can be reused in different places in your app. Examples of resources include brushes and styles. This overview describes how to use resources in Extensible Application Markup Language (XAML). You can also create and access resources by using code. > [!NOTE] > XAML resources described in this article are different from *app resources* which are generally files added to an app, such as content, data, or embedded files. - - [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] ## Using resources in XAML diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md b/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md index c295878..8bdb76e 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md +++ b/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md @@ -1,8 +1,8 @@ --- title: XAML overview -description: Learn how the XAML language is structured and implemented by Windows Presentation Foundation (WPF) for .NET Core. +description: Learn how the XAML language is structured and implemented by Windows Presentation Foundation (WPF) for .NET. author: adegeo -ms.date: 08/08/2019 +ms.date: 12/03/2020 ms.author: adegeo ms.topic: overview dev_langs: @@ -24,7 +24,7 @@ helpviewer_keywords: - "attribute syntax [XAML]" --- -# XAML overview in WPF +# XAML overview (WPF .NET) This article describes the features of the XAML language and demonstrates how you can use XAML to write Windows Presentation Foundation (WPF) apps. This article specifically describes XAML as implemented by WPF. XAML itself is a larger language concept than WPF. @@ -320,13 +320,11 @@ XAML is a markup language that directly represents object instantiation and exec ### Code Access Security (CAS) in WPF -**This section only applies to .NET Framework. WPF for .NET Core doesn't support CAS. For more information, see [Code Access Security differences](../migration/differences-from-net-framework.md#code-access-security).** - -WPF for .NET Framework supports Code Access Security (CAS). This means that WPF content running in the internet zone has reduced execution permissions. "Loose XAML" (pages of noncompiled XAML interpreted at load time by a XAML viewer) and XBAP are usually run in this internet zone and use the same permission set. However, XAML loaded in to a fully trusted application has the same access to the system resources as the hosting application does. For more information, see [WPF Partial Trust Security](../../../framework/wpf/wpf-partial-trust-security.md). +Unlike .NET Framework, WPF for .NET doesn't support CAS. For more information, see [Code Access Security differences](../migration/differences-from-net-framework.md#code-access-security). ## Loading XAML from code -XAML can be used to define all of the UI, but it is sometimes also appropriate to define just a piece of the UI in XAML. This capability could be used to enable partial customization, local storage of information, using XAML to provide a business object, or a variety of possible scenarios. The key to these scenarios is the class and its method. The input is a XAML file, and the output is an object that represents all of the run-time tree of objects that was created from that markup. You then can insert the object to be a property of another object that already exists in the app. So long as the property is an appropriate property in the content model that has eventual display capabilities and that will notify the execution engine that new content has been added into the app, you can modify a running app's contents easily by loading in XAML. For .NET Framework, this capability is generally only available in full-trust applications, because of the obvious security implications of loading files into applications as they run. +XAML can be used to define all of the UI, but it is sometimes also appropriate to define just a piece of the UI in XAML. This capability could be used to enable partial customization, local storage of information, using XAML to provide a business object, or a variety of possible scenarios. The key to these scenarios is the class and its method. The input is a XAML file, and the output is an object that represents all of the run-time tree of objects that was created from that markup. You then can insert the object to be a property of another object that already exists in the app. So long as the property is an appropriate property in the content model that has eventual display capabilities and that will notify the execution engine that new content has been added into the app, you can modify a running app's contents easily by loading in XAML. ## See also diff --git a/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md b/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md index c9932f9..a49ae85 100644 --- a/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md +++ b/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md @@ -1,13 +1,13 @@ --- -title: Differences between .NET Framework and .NET Core -description: Describes the differences between the .NET Framework implementation of Windows Presentation Foundation (WPF) and .NET Core WPF. When migrating your app, you should consider these incompatibilities. +title: Differences between .NET Framework and .NET +description: Describes the differences between the .NET Framework implementation of Windows Presentation Foundation (WPF) and .NET WPF. When migrating your app, you should consider these incompatibilities. author: adegeo ms.date: 09/21/2019 ms.author: adegeo ms.topic: conceptual --- -# Differences in WPF +# Differences in WPF .NET This article describes the differences between Windows Presentation Foundation (WPF) on .NET Core and .NET Framework. WPF for .NET Core is an [open-source framework](https://github.com/dotnet/wpf) forked from the original WPF for .NET Framework source code. diff --git a/dotnet-desktop-guide/net/wpf/overview/index.md b/dotnet-desktop-guide/net/wpf/overview/index.md index 63547b6..b1b0672 100644 --- a/dotnet-desktop-guide/net/wpf/overview/index.md +++ b/dotnet-desktop-guide/net/wpf/overview/index.md @@ -1,12 +1,12 @@ --- title: What is Windows Presentation Foundation -description: This article gives an overview about what Windows Presentation Foundation (WPF) is as it relates to .NET Core and what features are provided. +description: This article gives an overview about what Windows Presentation Foundation (WPF) is as it relates to .NET and what features are provided. ms.date: 07/18/2019 ms.topic: overview #Customer intent: As a developer, I want to understand the components of WPF so that I can understand the overall picture of WPF. --- -# What is Windows Presentation Foundation +# What is Windows Presentation Foundation (WPF .NET) Welcome to the Desktop Guide for Windows Presentation Foundation (WPF), a UI framework that creates desktop client applications for Windows. The WPF development platform supports a broad set of application development features, including an application model, controls, graphics, and data binding. WPF uses Extensible Application Markup Language (XAML) to provide a declarative model for application programming.