mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-09 16:06:09 +02:00
Content update - Custom dependency properties (user story 1878471) (#1189)
* Add article, code projects, toc, and redirects * Update dotnet-desktop-guide/net/wpf/properties/custom-dependency-properties.md Co-authored-by: Andy (Steve) De George <[email protected]> * Update dotnet-desktop-guide/net/wpf/properties/custom-dependency-properties.md Co-authored-by: Andy (Steve) De George <[email protected]> Co-authored-by: Andy (Steve) De George <[email protected]>
This commit is contained in:
co-authored by
Andy De George
parent
db732763f4
commit
db80384cb9
+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>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<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:CodeSampleVb"
|
||||
Title="Custom Dependency Properties" Height="100" Width="400">
|
||||
</Window>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
Namespace CodeSampleVb
|
||||
|
||||
' <summary>
|
||||
' Interaction logic for MainWindow.xaml.
|
||||
' </summary>
|
||||
Partial Public Class MainWindow
|
||||
Inherits Window
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class Aquarium
|
||||
Inherits DependencyObject
|
||||
|
||||
'<RegisterDependencyPropertyWithWrapper>
|
||||
'<RegisterDependencyProperty>
|
||||
' Register a dependency property with the specified property name,
|
||||
' property type, owner type, and property metadata.
|
||||
Private Shared ReadOnly s_aquariumGraphicProperty As DependencyProperty =
|
||||
DependencyProperty.Register(
|
||||
name:="AquariumGraphic",
|
||||
propertyType:=GetType(Uri),
|
||||
ownerType:=GetType(Aquarium),
|
||||
typeMetadata:=New FrameworkPropertyMetadata(
|
||||
defaultValue:=New Uri("http://www.contoso.com/aquarium-graphic.jpg"),
|
||||
flags:=FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
propertyChangedCallback:=New PropertyChangedCallback(AddressOf OnUriChanged)))
|
||||
|
||||
' Store the dependency property identifier as a static member of the class.
|
||||
Public Shared ReadOnly AquariumGraphicProperty As DependencyProperty =
|
||||
s_aquariumGraphicProperty
|
||||
'</RegisterDependencyProperty>
|
||||
|
||||
' Declare a read-write property.
|
||||
Public Property AquariumGraphic As Uri
|
||||
Get
|
||||
Return CType(GetValue(AquariumGraphicProperty), Uri)
|
||||
End Get
|
||||
Set
|
||||
SetValue(AquariumGraphicProperty, Value)
|
||||
End Set
|
||||
End Property
|
||||
'</RegisterDependencyPropertyWithWrapper>
|
||||
|
||||
Private Shared Sub OnUriChanged(dependencyObject As DependencyObject, e As DependencyPropertyChangedEventArgs)
|
||||
Dim shape As Shape = CType(dependencyObject, Shape)
|
||||
shape.Fill = New ImageBrush(New BitmapImage(CType(e.NewValue, Uri)))
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user