mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 00:56:03 +02:00
Add article, code projects, toc, and redirects (#1178)
Co-authored-by: Andy (Steve) De George <[email protected]>
This commit is contained in:
co-authored by
Andy De George
parent
cf712b82b0
commit
4f0101b05c
@@ -489,6 +489,14 @@
|
||||
"source_path": "dotnet-desktop-guide/framework/wpf/properties/dependency-property-value-precedence.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/advanced/dependency-property-value-precedence?view=netframeworkdesktop-4.8"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/net/wpf/advanced/attached-properties-overview.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/properties/attached-properties-overview?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/framework/wpf/properties/attached-properties-overview.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/advanced/attached-properties-overview?view=netframeworkdesktop-4.8"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-register-an-attached-property.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/properties/how-to-register-an-attached-property?view=netdesktop-5.0"
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
---
|
||||
title: "Attached properties overview"
|
||||
description: "Learn about the WPF property system and the capabilities of an attached property, which are global properties settable on any object."
|
||||
ms.date: "10/14/2021"
|
||||
ms.topic: overview
|
||||
dev_langs:
|
||||
- "csharp"
|
||||
- "vb"
|
||||
helpviewer_keywords:
|
||||
- "attached properties [WPF Designer]"
|
||||
---
|
||||
<!-- The acrolinx score was 95 on 10/14/2021-->
|
||||
|
||||
# Attached properties overview (WPF .NET)
|
||||
|
||||
An attached property is a Extensible Application Markup Language (XAML) concept. Attached properties enable extra property/value pairs to be set on any XAML element, even though the element doesn't define those extra properties in its object model. The extra properties are globally accessible. Attached properties are typically defined as a specialized form of dependency property that doesn't have a conventional property wrapper.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
The article assumes a basic knowledge of dependency properties, and that you've read [Dependency properties overview](dependency-properties-overview.md). To follow the examples in this article, it helps if you're familiar with XAML and know how to write Windows Presentation Foundation (WPF) applications.
|
||||
|
||||
## Why use attached properties
|
||||
|
||||
An attached property lets a child element specify a unique value for a property that's defined in a parent element. A common scenario is a child element specifying how it should be rendered in the UI by its parent element. For example, <xref:System.Windows.Controls.DockPanel.Dock%2A?displayProperty=nameWithType> is an attached property because it's set on child elements of a <xref:System.Windows.Controls.DockPanel>, not the `DockPanel` itself. The `DockPanel` class defines a static <xref:System.Windows.DependencyProperty> field, named <xref:System.Windows.Controls.DockPanel.DockProperty>, and then provides <xref:System.Windows.Controls.DockPanel.GetDock%2A> and <xref:System.Windows.Controls.DockPanel.SetDock%2A> methods as public accessors for the attached property.
|
||||
|
||||
## Attached properties in XAML
|
||||
|
||||
In XAML, you set attached properties by using the syntax `<attached property provider type>.<property name>`, where the attached property provider is the class that defines the attached property. The following example shows how a child element of <xref:System.Windows.Controls.DockPanel> can set the <xref:System.Windows.Controls.DockPanel.Dock%2A?displayProperty=nameWithType> property value.
|
||||
|
||||
:::code language="xaml" source="./snippets/attached-properties-overview/csharp/MainWindow.xaml" id="SetAttachedPropertyInXaml":::
|
||||
|
||||
The usage is similar to a static property in that you reference the type that owns and registers the attached property (for example, <xref:System.Windows.Controls.DockPanel>), not the instance name.
|
||||
|
||||
When you specify an attached property using a XAML attribute, only the set action is applicable. You can't directly get a property value through XAML, although there are some indirect mechanisms for comparing values, such as [triggers in styles](/dotnet/desktop/wpf/controls/styles-templates-overview#triggers).
|
||||
|
||||
### Attached properties in WPF
|
||||
|
||||
Attached properties are a XAML concept, dependency properties are a WPF concept. In WPF, most UI-related attached properties on WPF types are implemented as dependency properties. WPF attached properties that are implemented as dependency properties support dependency property concepts, such as property metadata including default values from metadata.
|
||||
|
||||
## Attached property usage models
|
||||
|
||||
Although any object can set an attached property value, that doesn't mean setting a value will produce a tangible result or the value will be used by another object. The main purpose of attached properties is to provide a way for objects from a wide variety of class hierarchies and logical relationships to report common information to the type that defines the attached property. Attached property usage typically follows one of these models:
|
||||
|
||||
- The type that defines the attached property is the parent of the elements that set values for the attached property. The parent type iterates its child objects through internal logic that acts on the object tree structure, obtains the values, and acts on those values in some manner.
|
||||
- The type that defines the attached property is used as the child element for various possible parent elements and content models.
|
||||
- The type that defines the attached property represents a service. Other types set values for the attached property. Then, when the element that set the property is evaluated in the context of the service, the attached property values are obtained through internal logic of the service class.
|
||||
|
||||
### An example of a parent-defined attached property
|
||||
|
||||
The typical scenario where WPF defines an attached property is when a parent element supports a child element collection, and the parent element implements a behavior based on data reported by each of its child elements.
|
||||
|
||||
<xref:System.Windows.Controls.DockPanel> defines the <xref:System.Windows.Controls.DockPanel.Dock%2A?displayProperty=nameWithType> attached property. `DockPanel` has class-level code, specifically <xref:System.Windows.Controls.DockPanel.MeasureOverride%2A> and <xref:System.Windows.Controls.DockPanel.ArrangeOverride%2A>, that's part of its rendering logic. A `DockPanel` instance checks whether any of its immediate child elements have set a value for `DockPanel.Dock`. If so, those values become inputs to the rendering logic applied to each child element. Although it's theoretically possible for attached properties to influence elements beyond the immediate parent, the defined behavior for a nested `DockPanel` instance is to only interact with its immediate child element collection. So, if you set `DockPanel.Dock` on an element that has no `DockPanel` parent, no error or exception will be raised and you would have created a global property value that won't be consumed by any `DockPanel`.
|
||||
|
||||
## Attached properties in code
|
||||
|
||||
Attached properties in WPF don't have the typical CLR `get` and `set` wrapper methods because the properties might be set from outside of the CLR namespace. To permit a XAML processor to set those values when parsing XAML, the class that defines the attached property must implement dedicated accessor methods in the form of `Get<property name>` and `Set<property name>`.
|
||||
|
||||
You can also use the dedicated accessor methods to get and set an attached property in code, as shown in the following example. In the example, `myTextBox` is an instance of the <xref:System.Windows.Controls.TextBox> class.
|
||||
|
||||
:::code language="csharp" source="./snippets/attached-properties-overview/csharp/MainWindow.xaml.cs" id="SetAttachedPropertyInCode":::
|
||||
:::code language="vb" source="./snippets/attached-properties-overview/vb/MainWindow.xaml.vb" id="SetAttachedPropertyInCode":::
|
||||
|
||||
If you don't add `myTextBox` as a child element of `myDockPanel`, calling `SetDock` won't raise an exception or have any effect. Only a <xref:System.Windows.Controls.DockPanel.Dock%2A?displayProperty=nameWithType> value set on a child element of a `DockPanel` can affect rendering, and the rendering will be the same whether you set the value before or after adding the child element to the `DockPanel`.
|
||||
|
||||
From a code perspective, an attached property is like a backing field that has method accessors instead of property accessors, and can be set on any object without first needing to be defined on those objects.
|
||||
|
||||
## Attached property metadata
|
||||
|
||||
Metadata for an attached property is generally no different than for a dependency property. When registering an attached property, use <xref:System.Windows.FrameworkPropertyMetadata> to specify characteristics of the property, such as whether the property affects rendering or measurement. When you specify a default value by overriding attached property metadata, that value becomes the default for the implicit attached property on instances of the overriding class. If an attached property value isn't otherwise set, the default value is reported when the property is queried by using the `Get<property name>` accessor with an instance of the class where you specified the metadata.
|
||||
|
||||
To enable property value inheritance on a property, use attached properties instead of non-attached dependency properties. For more information, see [Property value inheritance](/dotnet/desktop/wpf/advanced/property-value-inheritance?view=netframeworkdesktop-4.8&preserve-view=true).
|
||||
|
||||
## Custom attached properties
|
||||
|
||||
### When to create an attached property
|
||||
|
||||
Creating an attached property is useful when:
|
||||
|
||||
- You need a property setting mechanism available to classes other than the defining class. A common scenario is for UI layout, for instance <xref:System.Windows.Controls.DockPanel.Dock%2A?displayProperty=nameWithType>, <xref:System.Windows.Controls.Panel.ZIndex%2A?displayProperty=nameWithType>, and <xref:System.Windows.Controls.Canvas.Top%2A?displayProperty=nameWithType> are all examples of existing layout properties. In the layout scenario, child elements of a layout-controlling element are able to express layout requirements to their layout parent and to set a value for an attached property defined by the parent.
|
||||
|
||||
- One of your classes represents a service, and you want other classes to integrate the service more transparently.
|
||||
- You want Visual Studio WPF Designer support, such as the ability to edit a property through the **Properties** window. For more information, see [Control authoring overview](/dotnet/desktop/wpf/controls/control-authoring-overview?view=netframeworkdesktop-4.8&preserve-view=true).
|
||||
- You want to use property value inheritance.
|
||||
|
||||
### How to create an attached property
|
||||
|
||||
If your class defines an attached property solely for use by other types, then your class doesn't need to derive from <xref:System.Windows.DependencyObject>. Otherwise, follow the WPF model of having an attached property also be a dependency property, by deriving your class from `DependencyObject`.
|
||||
|
||||
Define your attached property as a dependency in the defining class by declaring a `public static readonly` field of type <xref:System.Windows.DependencyProperty>. Then, assign the return value of the <xref:System.Windows.DependencyProperty.RegisterAttached%2A> method to the field, which is also known as the *dependency property identifier*. Follow the WPF property naming convention that distinguishes fields from the properties that they represent, by naming the identifier field `<property name>Property`. Also, provide static `Get<property name>` and `Set<property name>` accessor methods, which lets the property system access your attached property.
|
||||
|
||||
The following example shows how to register a dependency property using the <xref:System.Windows.DependencyProperty.RegisterAttached%2A> method, and how to define the accessor methods. In the example, the name of the attached property is `HasFish`, so the identifier field is named `HasFishProperty`, and the accessor methods are named `GetHasFish` and `SetHasFish`.
|
||||
|
||||
:::code language="csharp" source="./snippets/attached-properties-overview/csharp/MainWindow.xaml.cs" id="RegisterAttachedProperty":::
|
||||
:::code language="vb" source="./snippets/attached-properties-overview/vb/MainWindow.xaml.vb" id="RegisterAttachedProperty":::
|
||||
|
||||
#### The Get accessor
|
||||
|
||||
The `get` accessor method signature is `public static object Get<property name>(object target)`, where:
|
||||
|
||||
- `target` is the object from which the attached property is read. The `target` type can be more specific than `object`. For example, the <xref:System.Windows.Controls.DockPanel.GetDock%2A?displayProperty=nameWithType> accessor method types the `target` as <xref:System.Windows.UIElement> because the attached property is intended to be set on `UIElement` instances.
|
||||
- The return type can be more specific than `object`. For example, the <xref:System.Windows.Controls.DockPanel.GetDock%2A> method types the returned value as <xref:System.Windows.Controls.Dock> because the return value should be a `Dock` enumeration.
|
||||
|
||||
> [!NOTE]
|
||||
> The `get` accessor for an attached property is required for data binding support in design tools, such as Visual Studio or Blend for Visual Studio.
|
||||
|
||||
#### The Set accessor
|
||||
|
||||
The `set` accessor method signature is `public static void Set<property name>(object target, object value)`, where:
|
||||
|
||||
- `target` is the object on which the attached property is written. The `target` type can be more specific than `object`. For example, the <xref:System.Windows.Controls.DockPanel.SetDock%2A> method types the `target` as <xref:System.Windows.UIElement> because the attached property is intended to be set on <xref:System.Windows.UIElement> instances.
|
||||
- The `value` type can be more specific than `object`. For example, the <xref:System.Windows.Controls.DockPanel.SetDock%2A> method requires a <xref:System.Windows.Controls.Dock> value. The XAML loader needs to be able to generate the `value` type from the markup string that represents the attached property value. So, there must be type conversion, value serializer, or markup extension support for the type you use.
|
||||
|
||||
### Attached property attributes
|
||||
|
||||
WPF defines several .NET attributes that provide information about attached properties to reflection processes and also to consumers of reflection and property information, such as designers. Designers use WPF defined .NET attributes to limit the properties shown in the properties window, to avoid overwhelming users with a global list of all attached properties. You might consider applying these attributes to your own custom attached properties. The purpose and syntax of .NET attributes is described in these reference pages:
|
||||
|
||||
- <xref:System.Windows.AttachedPropertyBrowsableAttribute>
|
||||
- <xref:System.Windows.AttachedPropertyBrowsableForChildrenAttribute>
|
||||
- <xref:System.Windows.AttachedPropertyBrowsableForTypeAttribute>
|
||||
- <xref:System.Windows.AttachedPropertyBrowsableWhenAttributePresentAttribute>
|
||||
|
||||
## Learn more
|
||||
|
||||
- For more information about creating an attached property, see [Register an attached property](/dotnet/desktop/wpf/advanced/how-to-register-an-attached-property?view=netframeworkdesktop-4.8&preserve-view=true).
|
||||
- For more advanced usage scenarios for dependency properties and attached properties, see [Custom dependency properties](/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8&preserve-view=true).
|
||||
- You can register a property as both an attached property and a dependency property, and include conventional property wrappers. In this way, a property can be set on an element by using property wrappers, and also on any other element by using XAML attached property syntax. For an example, see <xref:System.Windows.FrameworkElement.FlowDirection%2A?displayProperty=nameWithType>.
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.DependencyProperty>
|
||||
- [Dependency properties overview](dependency-properties-overview.md)
|
||||
- [Custom dependency properties](/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
- [XAML in WPF](/dotnet/desktop/wpf/xaml/)
|
||||
- [How to: Register an attached property](/dotnet/desktop/wpf/advanced/how-to-register-an-attached-property?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<Window x:Class="CodeSampleCsharp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Attached Properties Overview" Height="100" Width="400">
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<!--<SetAttachedPropertyInXaml>-->
|
||||
<DockPanel>
|
||||
<TextBox DockPanel.Dock="Top">Enter text</TextBox>
|
||||
</DockPanel>
|
||||
<!--</SetAttachedPropertyInXaml>-->
|
||||
|
||||
</StackPanel>
|
||||
</Window>
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml.
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
SetAttachedPropertyInCode();
|
||||
}
|
||||
|
||||
public static void SetAttachedPropertyInCode()
|
||||
{
|
||||
//<SetAttachedPropertyInCode>
|
||||
DockPanel myDockPanel = new();
|
||||
TextBox myTextBox = new();
|
||||
myTextBox.Text = "Enter text";
|
||||
|
||||
// Add child element to the DockPanel.
|
||||
myDockPanel.Children.Add(myTextBox);
|
||||
|
||||
// Set the attached property value.
|
||||
DockPanel.SetDock(myTextBox, Dock.Top);
|
||||
//</SetAttachedPropertyInCode>
|
||||
}
|
||||
}
|
||||
|
||||
//<RegisterAttachedProperty>
|
||||
public class Aquarium : DependencyObject
|
||||
{
|
||||
// Register an attached dependency property with the specified
|
||||
// property name, property type, owner type, and property metadata.
|
||||
public static readonly DependencyProperty HasFishProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"HasFish",
|
||||
typeof(bool),
|
||||
typeof(Aquarium),
|
||||
new FrameworkPropertyMetadata(defaultValue: false,
|
||||
flags: FrameworkPropertyMetadataOptions.AffectsRender)
|
||||
);
|
||||
|
||||
// Declare a get accessor method.
|
||||
public static bool GetHasFish(UIElement target) =>
|
||||
(bool)target.GetValue(HasFishProperty);
|
||||
|
||||
// Declare a set accessor method.
|
||||
public static void SetHasFish(UIElement target, bool value) =>
|
||||
target.SetValue(HasFishProperty, value);
|
||||
}
|
||||
//</RegisterAttachedProperty>
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace CodeSampleCsharp.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeSampleCsharp.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="CodeSampleCsharp.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:CodeSampleCsharp"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="Application"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:CodeSampleVb"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
Class Application
|
||||
|
||||
' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
|
||||
' can be handled in this file.
|
||||
|
||||
End Class
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
Imports System.Windows
|
||||
|
||||
'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found.
|
||||
'1st parameter: where theme specific resource dictionaries are located
|
||||
'(used if a resource is not found in the page,
|
||||
' or application resource dictionaries)
|
||||
|
||||
'2nd parameter: where the generic resource dictionary is located
|
||||
'(used if a resource is not found in the page,
|
||||
'app, and any theme specific resource dictionaries)
|
||||
<Assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<RootNamespace>CodeSampleVb</RootNamespace>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Import Include="System.Windows" />
|
||||
<Import Include="System.Windows.Controls" />
|
||||
<Import Include="System.Windows.Data" />
|
||||
<Import Include="System.Windows.Documents" />
|
||||
<Import Include="System.Windows.Input" />
|
||||
<Import Include="System.Windows.Media" />
|
||||
<Import Include="System.Windows.Media.Imaging" />
|
||||
<Import Include="System.Windows.Navigation" />
|
||||
<Import Include="System.Windows.Shapes" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<Window x:Class="CodeSampleVb.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Attached Properties Overview" Height="100" Width="400">
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<!--<SetAttachedPropertyInXaml>-->
|
||||
<DockPanel>
|
||||
<TextBox DockPanel.Dock="Top">Enter text</TextBox>
|
||||
</DockPanel>
|
||||
<!--</SetAttachedPropertyInXaml>-->
|
||||
|
||||
</StackPanel>
|
||||
</Window>
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
Namespace CodeSampleVb
|
||||
|
||||
' <summary>
|
||||
' Interaction logic for MainWindow.xaml.
|
||||
' </summary>
|
||||
Partial Public Class MainWindow
|
||||
Inherits Window
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
|
||||
SetAttachedPropertyInCode()
|
||||
End Sub
|
||||
|
||||
Public Shared Sub SetAttachedPropertyInCode()
|
||||
'<SetAttachedPropertyInCode>
|
||||
Dim myDockPanel As DockPanel = New DockPanel()
|
||||
Dim myTextBox As TextBox = New TextBox()
|
||||
myTextBox.Text = "Enter text"
|
||||
|
||||
' Add child element to the DockPanel.
|
||||
myDockPanel.Children.Add(myTextBox)
|
||||
|
||||
' Set the attached property value.
|
||||
DockPanel.SetDock(myTextBox, Dock.Top)
|
||||
'</SetAttachedPropertyInCode>
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
'<RegisterAttachedProperty>
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
' Register an attached dependency property with the specified
|
||||
' property name, property type, owner type, and property metadata.
|
||||
Public Shared ReadOnly HasFishProperty As DependencyProperty =
|
||||
DependencyProperty.RegisterAttached("HasFish", GetType(Boolean), GetType(Aquarium),
|
||||
New FrameworkPropertyMetadata(defaultValue:=False,
|
||||
flags:=FrameworkPropertyMetadataOptions.AffectsRender))
|
||||
|
||||
' Declare a get accessor method.
|
||||
Public Shared Function GetHasFish(target As UIElement) As Boolean
|
||||
Return target.GetValue(HasFishProperty)
|
||||
End Function
|
||||
|
||||
' Declare a set accessor method.
|
||||
Public Shared Sub SetHasFish(target As UIElement, value As Boolean)
|
||||
target.SetValue(HasFishProperty, value)
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
'</RegisterAttachedProperty>
|
||||
|
||||
End Namespace
|
||||
@@ -88,6 +88,10 @@ items:
|
||||
href: properties/how-to-register-an-attached-property.md
|
||||
- name: Collection-type dependency properties
|
||||
href: properties/collection-type-dependency-properties.md
|
||||
- name: Common tasks
|
||||
items:
|
||||
- name: Attached properties
|
||||
href: properties/attached-properties-overview.md
|
||||
- name: Resources
|
||||
items:
|
||||
- name: Overview
|
||||
|
||||
@@ -331,14 +331,19 @@
|
||||
},
|
||||
{
|
||||
"Redirect": "TwoWay",
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/how-to-register-an-attached-property?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/how-to-register-an-attached-property?view=netdesktop-5.0"
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/attached-properties-overview?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/attached-properties-overview?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"Redirect": "TwoWay",
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/collection-type-dependency-properties?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/collection-type-dependency-properties?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"Redirect": "TwoWay",
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/how-to-register-an-attached-property?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/how-to-register-an-attached-property?view=netdesktop-5.0"
|
||||
},
|
||||
|
||||
// Systems - XAML
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user