mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 00:56:03 +02:00
@@ -488,6 +488,38 @@
|
||||
{
|
||||
"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/how-to-implement-a-dependency-property.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/properties/how-to-implement-a-dependency-property?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/framework/wpf/properties/how-to-implement-a-dependency-property.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/advanced/how-to-implement-a-dependency-property?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"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/framework/wpf/properties/how-to-register-an-attached-property.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/advanced/how-to-register-an-attached-property?view=netframeworkdesktop-4.8"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/net/wpf/advanced/collection-type-dependency-properties.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/properties/collection-type-dependency-properties?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"source_path": "dotnet-desktop-guide/framework/wpf/properties/collection-type-dependency-properties.md",
|
||||
"redirect_url": "/dotnet/desktop/wpf/advanced/collection-type-dependency-properties?view=netframeworkdesktop-4.8"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -154,10 +154,15 @@
|
||||
},
|
||||
"ms.prod": {
|
||||
"framework/winforms/**/**.md": "dotnet-framework",
|
||||
"framework/winforms/**/**.yml": "dotnet-framework",
|
||||
"framework/wpf/**/**.md": "dotnet-framework",
|
||||
"framework/wpf/**/**.yml": "dotnet-framework",
|
||||
"net/winforms/**/**.md": "dotnet-desktop",
|
||||
"net/winforms/**/**.yml": "dotnet-desktop",
|
||||
"net/wpf/**/**.md": "dotnet-desktop",
|
||||
"xaml-services/**/*.md": "dotnet-desktop"
|
||||
"net/wpf/**/**.yml": "dotnet-desktop",
|
||||
"xaml-services/**/*.md": "dotnet-desktop",
|
||||
"xaml-services/**/*.yml": "dotnet-desktop"
|
||||
},
|
||||
"ms.topic": {
|
||||
"framework/winforms/**/**.md": "conceptual",
|
||||
|
||||
@@ -23,7 +23,7 @@ ms.assetid: 1fbada8e-4867-4ed1-8d97-62c07dad7ebc
|
||||
## Dependency Properties Might Be "Set" in Multiple Places
|
||||
The following is example [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] where the same property (<xref:System.Windows.Controls.Control.Background%2A>) has three different "set" operations that might influence the value.
|
||||
|
||||
[!code-xaml[PropertiesOvwSupport#DPPrecedence](~/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml#dpprecedence)]
|
||||
:::code language="xaml" source="./snippets/dependency-property-value-precedence/xaml/MainWindow.xaml" id="DependencyPropertyValuePrecedence":::
|
||||
|
||||
Here, which color do you expect will apply—red, green, or blue?
|
||||
|
||||
|
||||
+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>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<Window x:Class="CodeSampleCsharp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Title="Dependency Property Value Precedence" Height="100" Width="300">
|
||||
<!--<DependencyPropertyValuePrecedence>-->
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
|
||||
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<Button Template="{StaticResource ButtonTemplate}" Background="Red">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="Background" Value="Blue"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="Yellow" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
Which color do you expect?
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<!--</DependencyPropertyValuePrecedence>-->
|
||||
</Window>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml.
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// <ProceduralPropertySet>
|
||||
Button myButton = new();
|
||||
myButton.Width = 200.0;
|
||||
// </ProceduralPropertySet>
|
||||
|
||||
// <ProceduralPropertyGet>
|
||||
double whatWidth = myButton.Width;
|
||||
// </ProceduralPropertyGet>
|
||||
}
|
||||
|
||||
// <DefineDependencyProperty>
|
||||
public static readonly DependencyProperty IsSpinningProperty = DependencyProperty.Register(
|
||||
"IsSpinning", typeof(bool),
|
||||
typeof(MainWindow)
|
||||
);
|
||||
|
||||
public bool IsSpinning
|
||||
{
|
||||
get => (bool)GetValue(IsSpinningProperty);
|
||||
set => SetValue(IsSpinningProperty, value);
|
||||
}
|
||||
// </DefineDependencyProperty>
|
||||
}
|
||||
|
||||
// <OverrideMetadata>
|
||||
public class SpinnerControl : ItemsControl
|
||||
{
|
||||
static SpinnerControl() => DefaultStyleKeyProperty.OverrideMetadata(
|
||||
typeof(SpinnerControl),
|
||||
new FrameworkPropertyMetadata(typeof(SpinnerControl))
|
||||
);
|
||||
}
|
||||
// </OverrideMetadata>
|
||||
}
|
||||
+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>
|
||||
+1
-1
@@ -454,7 +454,7 @@ In this section, you'll update the UI for each item in the data-bound lists by u
|
||||
|
||||
[!code-xaml[ExpenseIt#30](~/samples/snippets/csharp/VS_Snippets_Wpf/ExpenseIt/CSharp/ExpenseIt9/ExpenseReportPage.xaml#30)]
|
||||
|
||||
4. Replace the <xref:System.Windows.Controls.DataGridTextColumn> elements with <xref:System.Windows.Controls.DataGridTemplateColumn> under the <xref:System.Windows.Controls.DataGrid> element and apply the templates to them.
|
||||
4. Replace the <xref:System.Windows.Controls.DataGridTextColumn> elements with <xref:System.Windows.Controls.DataGridTemplateColumn> under the <xref:System.Windows.Controls.DataGrid> element and apply the templates to them. Also, specify the `ItemsSource` attribute with its value in the `DataGrid` Element.
|
||||
|
||||
[!code-xaml[ExpenseIt#32](~/samples/snippets/csharp/VS_Snippets_Wpf/ExpenseIt/CSharp/ExpenseIt9/ExpenseReportPage.xaml#32)]
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
title: "Collection-type dependency properties"
|
||||
description: "Learn how to implement a dependency property that's a collection type and how to assign a default collection value."
|
||||
ms.date: "10/06/2021"
|
||||
dev_langs:
|
||||
- "csharp"
|
||||
- "vb"
|
||||
helpviewer_keywords:
|
||||
- "properties [WPF], dependency"
|
||||
- "properties [WPF], collection-type"
|
||||
- "dependency properties [WPF]"
|
||||
- "collection-type properties [WPF]"
|
||||
---
|
||||
<!-- The acrolinx score was 96 on 10/07/2021-->
|
||||
|
||||
# Collection-type dependency properties (WPF .NET)
|
||||
|
||||
This article provides guidance and suggested patterns for implementing a dependency property that's a collection type.
|
||||
|
||||
## Implement a collection-type dependency property
|
||||
|
||||
In general, the implementation pattern for a dependency property is a CLR property wrapper backed by a <xref:System.Windows.DependencyProperty> identifier instead of a field or other construct. You can follow the same pattern when you implement a collection-type dependency property. The pattern is more complex if the collection element type is a <xref:System.Windows.DependencyObject> or a <xref:System.Windows.Freezable> derived class.
|
||||
|
||||
## Initialize the collection
|
||||
|
||||
When you create a dependency property, you typically specify the default value through dependency property metadata instead of specifying an initial property value. However, if your property value is a reference type, the default value should be set in the constructor of the class that registers the dependency property. The dependency property metadata shouldn't include a default reference-type value because that value will be assigned to all instances of the class, creating a singleton class.
|
||||
|
||||
The following example declares an `Aquarium` class that contains a collection of <xref:System.Windows.FrameworkElement> elements in a generic <xref:System.Collections.Generic.List%601>. A default collection value isn't included in the <xref:System.Windows.PropertyMetadata> passed to the <xref:System.Windows.DependencyProperty.RegisterReadOnly%28System.String%2CSystem.Type%2CSystem.Type%2CSystem.Windows.PropertyMetadata%29> method, and instead the class constructor is used to set the default collection value to a new generic `List`.
|
||||
|
||||
:::code language="csharp" source="./snippets/collection-type-dependency-properties/csharp/MainWindow.xaml.cs" id="SetCollectionDefaultValueInConstructor":::
|
||||
:::code language="vb" source="./snippets/collection-type-dependency-properties/vb/MainWindow.xaml.vb" id="SetCollectionDefaultValueInConstructor":::
|
||||
|
||||
The following test code instantiates two separate `Aquarium` instances and adds a different `Fish` item to each collection. If you run the code, you'll see that each `Aquarium` instance has a single collection item, as expected.
|
||||
|
||||
:::code language="csharp" source="./snippets/collection-type-dependency-properties/csharp/MainWindow.xaml.cs" id="InitializeAquariums":::
|
||||
:::code language="vb" source="./snippets/collection-type-dependency-properties/vb/MainWindow.xaml.vb" id="InitializeAquariums":::
|
||||
|
||||
But, if you comment out the class constructor and pass the default collection value as <xref:System.Windows.PropertyMetadata> to the <xref:System.Windows.DependencyProperty.RegisterReadOnly%28System.String%2CSystem.Type%2CSystem.Type%2CSystem.Windows.PropertyMetadata%29> method, you'll see that each `Aquarium` instance gets two collection items! This is because both `Fish` instances are added to the same list, which is shared by all instances of the Aquarium class. So, when the intent is for each object instance to have its own list, the default value should be set in the class constructor.
|
||||
|
||||
### Initialize a read-write collection
|
||||
|
||||
The following example declares a read-write collection-type dependency property in the `Aquarium` class, using the non-key signature methods <xref:System.Windows.DependencyProperty.Register%28System.String%2CSystem.Type%2CSystem.Type%29> and <xref:System.Windows.DependencyObject.SetValue%28System.Windows.DependencyProperty%2CSystem.Object%29>.
|
||||
|
||||
:::code language="csharp" source="./snippets/collection-type-dependency-properties/csharp/MainWindow.xaml.cs" id="ReadWriteDependencyProperty":::
|
||||
:::code language="vb" source="./snippets/collection-type-dependency-properties/vb/MainWindow.xaml.vb" id="ReadWriteDependencyProperty":::
|
||||
|
||||
## FreezableCollection dependency properties
|
||||
|
||||
A collection-type dependency property doesn't automatically report changes in its subproperties. As a result, if you're binding to a collection, the binding might not report changes, invalidating some data binding scenarios. But, if you use <xref:System.Windows.FreezableCollection%601> for the dependency property type, changes to the properties of collection elements are properly reported and binding works as expected.
|
||||
|
||||
To enable subproperty binding in a collection of dependency objects, use the collection type `FreezableCollection`, with a type constraint of any <xref:System.Windows.DependencyObject> derived class.
|
||||
|
||||
The following example declares an `Aquarium` class that contains a `FreezableCollection` with a type constraint of <xref:System.Windows.FrameworkElement>. A default collection value isn't included in the <xref:System.Windows.PropertyMetadata> passed to the <xref:System.Windows.DependencyProperty.RegisterReadOnly%28System.String%2CSystem.Type%2CSystem.Type%2CSystem.Windows.PropertyMetadata%29> method, and instead the class constructor is used to set the default collection value to a new `FreezableCollection`.
|
||||
|
||||
:::code language="csharp" source="./snippets/collection-type-dependency-properties/csharp/MainWindow.xaml.cs" id="FreezableCollectionAquarium":::
|
||||
:::code language="vb" source="./snippets/collection-type-dependency-properties/vb/MainWindow.xaml.vb" id="FreezableCollectionAquarium":::
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.FreezableCollection%601>
|
||||
- [XAML and Custom Classes for WPF](/dotnet/desktop/wpf/advanced/xaml-and-custom-classes-for-wpf?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
- [Data Binding Overview](/dotnet/desktop/wpf/data/)
|
||||
- [Dependency Properties Overview](dependency-properties-overview.md)
|
||||
- [Custom Dependency Properties](/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
- [Dependency Property Metadata](/dotnet/desktop/wpf/advanced/dependency-property-metadata?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: "How to implement a dependency property"
|
||||
description: "Define a dependency property in Windows Presentation Foundation (WPF), by backing a common language runtime property with a DependencyProperty field."
|
||||
ms.date: "10/15/2021"
|
||||
dev_langs:
|
||||
- "csharp"
|
||||
- "vb"
|
||||
helpviewer_keywords:
|
||||
- "dependency properties [WPF], backing properties with"
|
||||
- "properties [WPF], backing with dependency properties"
|
||||
---
|
||||
<!-- The acrolinx score was 96 on 10/15/2021-->
|
||||
|
||||
# How to implement a dependency property (WPF .NET)
|
||||
|
||||
This article describes how to implement a dependency property by using a <xref:System.Windows.DependencyProperty> field to back a common language runtime (CLR) property. Dependency properties support several advanced Windows Presentation Foundation (WPF) property system features. These features include styles, data binding, inheritance, animation, and default values. If you want properties that you define to support those features, then implement your properties as a dependency property.
|
||||
|
||||
## Example
|
||||
|
||||
The following example shows how to register a dependency property, by calling the <xref:System.Windows.DependencyProperty.Register%2A> method. The `Register` method returns a <xref:System.Windows.DependencyProperty> instance called a *dependency property identifier*. The identifier is stored in a `static readonly` field, and holds the name and characteristics of a dependency property.
|
||||
|
||||
The identifier field must follow the naming convention `<property name>Property`. For instance, if you register a dependency property with the name `Location`, then the identifier field should be named `LocationProperty`. If you fail to follow this naming pattern, then WPF designers might not report your property correctly, and aspects of the property system style application might not behave as expected.
|
||||
|
||||
In the following example, the [name](<xref:System.Windows.DependencyProperty.Name>) of the dependency property and its CLR accessor is `HasFish`, so the identifier field is named `HasFishProperty`. The dependency property type is <xref:System.Boolean> and the owner type that registers the dependency property is `Aquarium`.
|
||||
|
||||
You can specify default [metadata](<xref:System.Windows.FrameworkPropertyMetadata>) for a dependency property. This example sets a default value of `false` for the `HasFish` dependency property.
|
||||
|
||||
:::code language="csharp" source="./snippets/how-to-implement-a-dependency-property/csharp/MainWindow.xaml.cs" id="DefineDependencyProperty":::
|
||||
:::code language="vb" source="./snippets/how-to-implement-a-dependency-property/vb/MainWindow.xaml.vb" id="DefineDependencyProperty":::
|
||||
|
||||
For more information about how and why to implement a dependency property, rather than just backing a CLR property with a private field, see [Dependency properties overview](dependency-properties-overview.md).
|
||||
|
||||
## See also
|
||||
|
||||
- [Dependency properties overview](dependency-properties-overview.md)
|
||||
- [How-to topics](/dotnet/desktop/wpf/advanced/properties-how-to-topics?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: "How to register an attached property"
|
||||
description: "Learn about the Windows Presentation Foundation (WPF) property system and how to register an attached property and provide public accessors."
|
||||
ms.date: "10/15/2021"
|
||||
dev_langs:
|
||||
- "csharp"
|
||||
- "vb"
|
||||
helpviewer_keywords:
|
||||
- "attached properties [WPF], registering"
|
||||
- "registering attached properties [WPF]"
|
||||
---
|
||||
<!-- The acrolinx score was 96 on 10/15/2021-->
|
||||
|
||||
# How to register an attached property (WPF .NET)
|
||||
|
||||
This article describes how to register an attached property and provide public accessors that let you access the attached property through Extensible Application Markup Language (XAML) and code. 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. Most attached properties for Windows Presentation Foundation (WPF) types are also implemented as dependency properties. You can create dependency properties on any <xref:System.Windows.DependencyObject> derived type.
|
||||
|
||||
## Example
|
||||
|
||||
The following example shows how to register an attached property as a dependency property, by using the <xref:System.Windows.DependencyProperty.RegisterAttached%2A> method. The provider class has the option of specifying a default value in property metadata. For more information on property metadata, see [Property metadata for a new dependency property](/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8&preserve-view=true#property-metadata-for-a-new-dependency-property). In this example, the `HasFish` property has a <xref:System.Boolean> value type, with its default value set to `false`.
|
||||
|
||||
The provider class for an attached property must provide static get/set accessor methods that follow the naming convention `Get<property name>` and `Set<property name>`. The XAML reader uses the accessors to recognize the XAML attribute for the attached property and resolve its value to the appropriate type. These accessors are necessary even if an attached property isn't registered as a dependency property.
|
||||
|
||||
:::code language="csharp" source="./snippets/how-to-register-an-attached-property/csharp/MainWindow.xaml.cs" id="RegisterAttachedProperty":::
|
||||
:::code language="vb" source="./snippets/how-to-register-an-attached-property/vb/MainWindow.xaml.vb" id="RegisterAttachedProperty":::
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.DependencyProperty>
|
||||
- [Attached properties overview](/dotnet/desktop/wpf/advanced/attached-properties-overview?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
- [Dependency properties overview](dependency-properties-overview.md)
|
||||
- [Custom dependency properties](/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8&preserve-view=true)
|
||||
- [How-to topics](/dotnet/desktop/wpf/advanced/properties-how-to-topics?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
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<Window x:Class="CodeSampleCsharp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:CodeSampleCsharp"
|
||||
Title="Collection-Type Dependency Properties" Height="100" Width="400">
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<Button Click="InitializeAquariums">Set collection default value in class constructor</Button>
|
||||
|
||||
</StackPanel>
|
||||
</Window>
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml.
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
//<InitializeAquariums>
|
||||
private void InitializeAquariums(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Aquarium aquarium1 = new();
|
||||
Aquarium aquarium2 = new();
|
||||
aquarium1.AquariumContents.Add(new Fish());
|
||||
aquarium2.AquariumContents.Add(new Fish());
|
||||
MessageBox.Show(
|
||||
$"Aquarium1 contains {aquarium1.AquariumContents.Count} fish\r\n" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish");
|
||||
}
|
||||
//</InitializeAquariums>
|
||||
}
|
||||
|
||||
//<SetCollectionDefaultValueInConstructor>
|
||||
public class Aquarium : DependencyObject
|
||||
{
|
||||
// Register a dependency property with the specified property name,
|
||||
// property type, owner type, and property metadata.
|
||||
private static readonly DependencyPropertyKey s_aquariumContentsPropertyKey =
|
||||
DependencyProperty.RegisterReadOnly(
|
||||
name: "AquariumContents",
|
||||
propertyType: typeof(List<FrameworkElement>),
|
||||
ownerType: typeof(Aquarium),
|
||||
typeMetadata: new FrameworkPropertyMetadata()
|
||||
//typeMetadata: new FrameworkPropertyMetadata(new List<FrameworkElement>())
|
||||
);
|
||||
|
||||
// Store the dependency property identifier as a static member of the class.
|
||||
public static readonly DependencyProperty AquariumContentsProperty =
|
||||
s_aquariumContentsPropertyKey.DependencyProperty;
|
||||
|
||||
// Set the default collection value in a class constructor.
|
||||
public Aquarium() => SetValue(s_aquariumContentsPropertyKey, new List<FrameworkElement>());
|
||||
|
||||
// Declare a read-only property.
|
||||
public List<FrameworkElement> AquariumContents =>
|
||||
(List<FrameworkElement>)GetValue(AquariumContentsProperty);
|
||||
}
|
||||
|
||||
public class Fish : FrameworkElement { }
|
||||
//</SetCollectionDefaultValueInConstructor>
|
||||
|
||||
public class ReadWriteAquariumContents
|
||||
{
|
||||
private static void InitializeAquariums()
|
||||
{
|
||||
Aquarium aquarium1 = new();
|
||||
Aquarium aquarium2 = new();
|
||||
aquarium1.AquariumContents.Add(new Fish());
|
||||
aquarium2.AquariumContents.Add(new Fish());
|
||||
aquarium2.AquariumContents = new List<FrameworkElement>();
|
||||
MessageBox.Show(
|
||||
$"Aquarium1 contains {aquarium1.AquariumContents.Count} fish\r\n" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish");
|
||||
}
|
||||
|
||||
//<ReadWriteDependencyProperty>
|
||||
public class Aquarium : DependencyObject
|
||||
{
|
||||
// Register a dependency property with the specified property name,
|
||||
// property type, and owner type.
|
||||
private static readonly DependencyProperty s_aquariumContentsProperty =
|
||||
DependencyProperty.Register(
|
||||
name: "AquariumContents",
|
||||
propertyType: typeof(List<FrameworkElement>),
|
||||
ownerType: typeof(Aquarium)
|
||||
);
|
||||
|
||||
// Store the dependency property identifier as a static member of the class.
|
||||
public static readonly DependencyProperty AquariumContentsProperty =
|
||||
s_aquariumContentsProperty;
|
||||
|
||||
// Set the default collection value in a class constructor.
|
||||
public Aquarium() => SetValue(s_aquariumContentsProperty, new List<FrameworkElement>());
|
||||
|
||||
// Declare a read-write property.
|
||||
public List<FrameworkElement> AquariumContents
|
||||
{
|
||||
get => (List<FrameworkElement>)GetValue(AquariumContentsProperty);
|
||||
set => SetValue(AquariumContentsProperty, value);
|
||||
}
|
||||
}
|
||||
//</ReadWriteDependencyProperty>
|
||||
|
||||
public class Fish : FrameworkElement { }
|
||||
}
|
||||
|
||||
public class FreezableCollectionAquarium
|
||||
{
|
||||
public static void InitializeAquariums()
|
||||
{
|
||||
Aquarium aquarium1 = new();
|
||||
Aquarium aquarium2 = new();
|
||||
aquarium1.AquariumContents.Add(new Fish());
|
||||
aquarium2.AquariumContents.Add(new Fish());
|
||||
MessageBox.Show(
|
||||
$"Aquarium1 contains {aquarium1.AquariumContents.Count} fish\r\n" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish");
|
||||
}
|
||||
|
||||
//<FreezableCollectionAquarium>
|
||||
public class Aquarium : DependencyObject
|
||||
{
|
||||
// Register a dependency property with the specified property name,
|
||||
// property type, and owner type.
|
||||
private static readonly DependencyPropertyKey s_aquariumContentsPropertyKey =
|
||||
DependencyProperty.RegisterReadOnly(
|
||||
name: "AquariumContents",
|
||||
propertyType: typeof(FreezableCollection<FrameworkElement>),
|
||||
ownerType: typeof(Aquarium),
|
||||
typeMetadata: new FrameworkPropertyMetadata()
|
||||
);
|
||||
|
||||
// Store the dependency property identifier as a static member of the class.
|
||||
public static readonly DependencyProperty AquariumContentsProperty =
|
||||
s_aquariumContentsPropertyKey.DependencyProperty;
|
||||
|
||||
// Set the default collection value in a class constructor.
|
||||
public Aquarium() => SetValue(s_aquariumContentsPropertyKey, new FreezableCollection<FrameworkElement>());
|
||||
|
||||
// Declare a read-only property.
|
||||
public FreezableCollection<FrameworkElement> AquariumContents =>
|
||||
(FreezableCollection<FrameworkElement>)GetValue(AquariumContentsProperty);
|
||||
}
|
||||
|
||||
//</FreezableCollectionAquarium>
|
||||
|
||||
public class Fish : FrameworkElement { }
|
||||
}
|
||||
}
|
||||
+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>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<Window x:Class="CodeSampleVb.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:CodeSampleCsharp"
|
||||
Title="Collection-Type Dependency Properties" Height="100" Width="400">
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<Button Click="InitializeAquariums">Set collection default value in class constructor</Button>
|
||||
|
||||
</StackPanel>
|
||||
</Window>
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
Namespace CodeSampleVb
|
||||
|
||||
' <summary>
|
||||
' Interaction logic for MainWindow.xaml.
|
||||
' </summary>
|
||||
Partial Public Class MainWindow
|
||||
Inherits Window
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
|
||||
'<InitializeAquariums>
|
||||
Private Sub InitializeAquariums(sender As Object, e As RoutedEventArgs)
|
||||
Dim aquarium1 As New Aquarium()
|
||||
Dim aquarium2 As New Aquarium()
|
||||
aquarium1.AquariumContents.Add(New Fish())
|
||||
aquarium2.AquariumContents.Add(New Fish())
|
||||
MessageBox.Show($"Aquarium1 contains {aquarium1.AquariumContents.Count} fish{Environment.NewLine}" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish")
|
||||
End Sub
|
||||
'</InitializeAquariums>
|
||||
|
||||
End Class
|
||||
|
||||
'<SetCollectionDefaultValueInConstructor>
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
' Register a dependency property with the specified property name,
|
||||
' property type, owner type, and property metadata.
|
||||
Private Shared ReadOnly s_aquariumContentsPropertyKey As DependencyPropertyKey =
|
||||
DependencyProperty.RegisterReadOnly(
|
||||
name:="AquariumContents",
|
||||
propertyType:=GetType(List(Of FrameworkElement)),
|
||||
ownerType:=GetType(Aquarium),
|
||||
typeMetadata:=New FrameworkPropertyMetadata())
|
||||
'typeMetadata:=New FrameworkPropertyMetadata(New List(Of FrameworkElement)))
|
||||
|
||||
' Store the dependency property identifier as a static member of the class.
|
||||
Public Shared ReadOnly AquariumContentsProperty As DependencyProperty =
|
||||
s_aquariumContentsPropertyKey.DependencyProperty
|
||||
|
||||
' Set the default collection value in a class constructor.
|
||||
Public Sub New()
|
||||
SetValue(s_aquariumContentsPropertyKey, New List(Of FrameworkElement)())
|
||||
End Sub
|
||||
|
||||
' Declare a read-only property.
|
||||
Public ReadOnly Property AquariumContents As List(Of FrameworkElement)
|
||||
Get
|
||||
Return CType(GetValue(AquariumContentsProperty), List(Of FrameworkElement))
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
|
||||
Public Class Fish
|
||||
Inherits FrameworkElement
|
||||
End Class
|
||||
'</SetCollectionDefaultValueInConstructor>
|
||||
|
||||
Public Class ReadWriteAquariumContents
|
||||
|
||||
Public Shared Sub InitializeAquariums()
|
||||
Dim aquarium1 As New Aquarium()
|
||||
Dim aquarium2 As New Aquarium()
|
||||
aquarium1.AquariumContents.Add(New Fish())
|
||||
aquarium2.AquariumContents.Add(New Fish())
|
||||
aquarium2.AquariumContents = New List(Of FrameworkElement)()
|
||||
MessageBox.Show($"Aquarium1 contains {aquarium1.AquariumContents.Count} fish{Environment.NewLine}" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish")
|
||||
End Sub
|
||||
|
||||
'<ReadWriteDependencyProperty>
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
' Register a dependency property with the specified property name,
|
||||
' property type, and owner type.
|
||||
Private Shared ReadOnly s_aquariumContentsProperty As DependencyProperty =
|
||||
DependencyProperty.Register(
|
||||
name:="AquariumContents",
|
||||
propertyType:=GetType(List(Of FrameworkElement)),
|
||||
ownerType:=GetType(Aquarium))
|
||||
|
||||
' Store the dependency property identifier as a static member of the class.
|
||||
Public Shared ReadOnly AquariumContentsProperty As DependencyProperty =
|
||||
s_aquariumContentsProperty
|
||||
|
||||
' Set the default collection value in a class constructor.
|
||||
Public Sub New()
|
||||
SetValue(s_aquariumContentsProperty, New List(Of FrameworkElement)())
|
||||
End Sub
|
||||
|
||||
' Declare a read-write property.
|
||||
Public Property AquariumContents As List(Of FrameworkElement)
|
||||
Get
|
||||
Return CType(GetValue(AquariumContentsProperty), List(Of FrameworkElement))
|
||||
End Get
|
||||
Set
|
||||
SetValue(AquariumContentsProperty, Value)
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
'</ReadWriteDependencyProperty>
|
||||
|
||||
Public Class Fish
|
||||
Inherits FrameworkElement
|
||||
End Class
|
||||
|
||||
End Class
|
||||
|
||||
Public Class FreezableCollectionAquarium
|
||||
|
||||
Public Shared Sub InitializeAquariums()
|
||||
Dim aquarium1 As New Aquarium()
|
||||
Dim aquarium2 As New Aquarium()
|
||||
aquarium1.AquariumContents.Add(New Fish())
|
||||
aquarium2.AquariumContents.Add(New Fish())
|
||||
MessageBox.Show($"Aquarium1 contains {aquarium1.AquariumContents.Count} fish{Environment.NewLine}" +
|
||||
$"Aquarium2 contains {aquarium2.AquariumContents.Count} fish")
|
||||
End Sub
|
||||
|
||||
'<FreezableCollectionAquarium>
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
' Register a dependency property with the specified property name,
|
||||
' property type, and owner type.
|
||||
Private Shared ReadOnly s_aquariumContentsPropertyKey As DependencyPropertyKey =
|
||||
DependencyProperty.RegisterReadOnly(
|
||||
name:="AquariumContents",
|
||||
propertyType:=GetType(FreezableCollection(Of FrameworkElement)),
|
||||
ownerType:=GetType(Aquarium),
|
||||
typeMetadata:=New FrameworkPropertyMetadata())
|
||||
|
||||
' Store the dependency property identifier as a static member of the class.
|
||||
Public Shared ReadOnly AquariumContentsProperty As DependencyProperty =
|
||||
s_aquariumContentsPropertyKey.DependencyProperty
|
||||
|
||||
' Set the default collection value in a class constructor.
|
||||
Public Sub New()
|
||||
SetValue(s_aquariumContentsPropertyKey, New FreezableCollection(Of FrameworkElement)())
|
||||
End Sub
|
||||
|
||||
' Declare a read-only property.
|
||||
Public ReadOnly Property AquariumContents As FreezableCollection(Of FrameworkElement)
|
||||
Get
|
||||
Return CType(GetValue(AquariumContentsProperty), FreezableCollection(Of FrameworkElement))
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
'</FreezableCollectionAquarium>
|
||||
|
||||
Public Class Fish
|
||||
Inherits FrameworkElement
|
||||
End Class
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
+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>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<Window x:Class="CodeSampleCsharp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml.
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow() => InitializeComponent();
|
||||
}
|
||||
|
||||
// <DefineDependencyProperty>
|
||||
public class Aquarium : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty HasFishProperty =
|
||||
DependencyProperty.Register(
|
||||
name: "HasFish",
|
||||
propertyType: typeof(bool),
|
||||
ownerType: typeof(Aquarium),
|
||||
typeMetadata: new FrameworkPropertyMetadata(defaultValue: false));
|
||||
|
||||
public bool HasFish
|
||||
{
|
||||
get => (bool)GetValue(HasFishProperty);
|
||||
set => SetValue(HasFishProperty, value);
|
||||
}
|
||||
}
|
||||
// </DefineDependencyProperty>
|
||||
}
|
||||
+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="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>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<Window x:Class="CodeSampleVb.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
Namespace CodeSampleVb
|
||||
Partial Public Class MainWindow
|
||||
Inherits Window
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
|
||||
' <DefineDependencyProperty>
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
Public Shared ReadOnly HasFishProperty As DependencyProperty =
|
||||
DependencyProperty.Register(
|
||||
name:="HasFish",
|
||||
propertyType:=GetType(Boolean),
|
||||
ownerType:=GetType(Aquarium),
|
||||
typeMetadata:=New FrameworkPropertyMetadata(defaultValue:=False))
|
||||
|
||||
Public Property HasFish As Boolean
|
||||
Get
|
||||
Return GetValue(HasFishProperty)
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
SetValue(HasFishProperty, value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
End Class
|
||||
' </DefineDependencyProperty>
|
||||
End Class
|
||||
End Namespace
|
||||
+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>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<Window x:Class="CodeSampleCsharp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CodeSampleCsharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml.
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow() => InitializeComponent();
|
||||
}
|
||||
|
||||
//<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>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<Window x:Class="CodeSampleVb.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/>
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
Namespace CodeSampleVb
|
||||
|
||||
' <summary>
|
||||
' Interaction logic for MainWindow.xaml.
|
||||
' </summary>
|
||||
Partial Public Class MainWindow
|
||||
Inherits Window
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
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
|
||||
@@ -84,6 +84,16 @@ items:
|
||||
href: properties/dependency-properties-overview.md
|
||||
- name: Dependency property value precedence
|
||||
href: properties/dependency-property-value-precedence.md
|
||||
- name: Attached properties
|
||||
href: properties/attached-properties-overview.md
|
||||
- name: Collection-type dependency properties
|
||||
href: properties/collection-type-dependency-properties.md
|
||||
- name: Common tasks
|
||||
items:
|
||||
- name: Implement a dependency property
|
||||
href: properties/how-to-implement-a-dependency-property.md
|
||||
- name: Register an attached property
|
||||
href: properties/how-to-register-an-attached-property.md
|
||||
- name: Resources
|
||||
items:
|
||||
- name: Overview
|
||||
|
||||
+15
-12
@@ -4,27 +4,30 @@
|
||||
x:Class="MyNamespace.MyCode"
|
||||
Loaded="BAQ"
|
||||
>
|
||||
<StackPanel>
|
||||
<!--<SnippetAPBasicUsage>-->
|
||||
<DockPanel>
|
||||
<CheckBox DockPanel.Dock="Top">Hello</CheckBox>
|
||||
</DockPanel>
|
||||
<!--</SnippetAPBasicUsage>-->
|
||||
<Button Click="MakeANewThing">Make a new thing</Button>
|
||||
<!--<SnippetDPPrecedence>-->
|
||||
<Button Background="Red">
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
|
||||
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<Button Template="{StaticResource ButtonTemplate}" Background="Red">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="Background" Value="Green"/>
|
||||
<Setter Property="Background" Value="Blue"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="Blue" />
|
||||
<Setter Property="Background" Value="Yellow" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
Click
|
||||
Which color do you expect?
|
||||
</Button>
|
||||
<!--</SnippetDPPrecedence>-->
|
||||
</StackPanel>
|
||||
<!--</SnippetDPPrecedence>-->
|
||||
</Canvas>
|
||||
|
||||
@@ -329,6 +329,26 @@
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/dependency-property-value-precedence?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/dependency-property-value-precedence?view=netdesktop-5.0"
|
||||
},
|
||||
{
|
||||
"Redirect": "TwoWay",
|
||||
"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"
|
||||
},
|
||||
{
|
||||
"Redirect": "TwoWay",
|
||||
"SourceUrl": "/dotnet/desktop/wpf/advanced/how-to-implement-a-dependency-property?view=netframeworkdesktop-4.8",
|
||||
"TargetUrl": "/dotnet/desktop/wpf/properties/how-to-implement-a-dependency-property?view=netdesktop-5.0"
|
||||
},
|
||||
|
||||
// Systems - XAML
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
This tool uses the _definitions.json_ file to generate a _.openpublishing.redirection_ file. If a _.openpublishing.redirection_ file exists in the folder, it's updated and appended to.
|
||||
This tool uses the _definitions.json_ file to generate a _.openpublishing.redirection_ file. If a _.openpublishing.redirection_ file exists in the folder, it's copied to the output folder and updated and appended to there.
|
||||
|
||||
Pass in the file path of a _.openpublishing.redirection_ file, and it'll be updated in-place. e.g. redirs.exe "c:\repos\dotnet\docs-desktop\.openpublishing.redirection.json"
|
||||
|
||||
The definitions generate two-way redirects between versioned content. The definition file is a json file that has some config at the start:
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
dotnet run -- "..\.openpublishing.redirection.json"
|
||||
|
||||
del .openpublishing.redirection.json
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -7,10 +8,22 @@ const string OutputFile = ".openpublishing.redirection.json";
|
||||
|
||||
JsonSerializerOptions options = new JsonSerializerOptions
|
||||
{
|
||||
Converters = { new System.Text.Json.Serialization.JsonStringEnumConverter() },
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
// If a .openpublishing.redirection.json path is provided,
|
||||
// then copy that file to the output folder.
|
||||
if (args.Length == 1 && File.Exists(args[0]))
|
||||
{
|
||||
// Get passed in .openpublishing.redirection.json path.
|
||||
string srcRedirectFilePath = args[0];
|
||||
|
||||
// Copy .openpublishing.redirection.json to output folder.
|
||||
File.Copy(srcRedirectFilePath, OutputFile, overwrite: true);
|
||||
}
|
||||
|
||||
// Load the definitions
|
||||
Console.WriteLine("Loading 'definitions.json'");
|
||||
Document document = JsonSerializer.Deserialize<Document>(System.IO.File.ReadAllText("definitions.json"), options);
|
||||
@@ -63,6 +76,22 @@ if (System.IO.File.Exists(OutputFile))
|
||||
Console.WriteLine($"Writing '{OutputFile}'");
|
||||
System.IO.File.WriteAllText(OutputFile, JsonSerializer.Serialize(redirects));
|
||||
|
||||
// If a .openpublishing.redirection.json path is provided,
|
||||
// then overwrite it with the formatted new content.
|
||||
if (args.Length == 1 && File.Exists(args[0]))
|
||||
{
|
||||
// Get passed in .openpublishing.redirection.json path.
|
||||
string srcRedirectFilePath = args[0];
|
||||
|
||||
// Format new json content.
|
||||
string formattedJson = JsonSerializer.Serialize(redirects, options);
|
||||
formattedJson = formattedJson.Replace(" ", " "); // match existing indent.
|
||||
formattedJson += "\r\n"; // add newline at end.
|
||||
|
||||
// Save new content to source path.
|
||||
File.WriteAllText(srcRedirectFilePath, formattedJson);
|
||||
}
|
||||
|
||||
void CreateEntry(string sourceMoniker, string sourceUrl, string targetUrl)
|
||||
{
|
||||
// Opposite repo paths are used here according to moniker
|
||||
|
||||
Reference in New Issue
Block a user