mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-08 23:43:29 +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
+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