diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index c6e9dd6..d67c743 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -1,232 +1,388 @@ { - "redirections": [ - { - "source_path": "dotnet-desktop-guide/net/winforms/windows-forms-overview.md", - "redirect_url": "/dotnet/desktop/winforms/overview/?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/overview/index.md", - "redirect_url": "/dotnet/desktop/winforms/windows-forms-overview?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-create-a-windows-forms-application-from-the-command-line.md", - "redirect_url": "/dotnet/desktop/winforms/get-started/create-app-visual-studio?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/get-started/create-app-visual-studio.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-create-a-windows-forms-application-from-the-command-line?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/events-overview-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/forms/events?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/forms/events.md", - "redirect_url": "/dotnet/desktop/winforms/events-overview-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/automatic-scaling-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/forms/autoscale?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/forms/autoscale.md", - "redirect_url": "/dotnet/desktop/winforms/automatic-scaling-in-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-resize-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/forms/how-to-position-and-resize?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/forms/how-to-position-and-resize.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-resize-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/layout-in-windows-forms-controls.md", - "redirect_url": "/dotnet/desktop/winforms/controls/layout?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/layout.md", - "redirect_url": "/dotnet/desktop/winforms/controls/layout-in-windows-forms-controls?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/label-control-overview-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/controls/labels?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/labels.md", - "redirect_url": "/dotnet/desktop/winforms/controls/label-control-overview-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/varieties-of-custom-controls.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/custom.md", - "redirect_url": "/dotnet/desktop/winforms/controls/varieties-of-custom-controls?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/custom-control-painting-and-rendering.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/custom-painting-drawing.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom-control-painting-and-rendering?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-add-controls-to-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-to-a-form?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-add-to-a-form.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-controls-to-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys-for-windows-forms-controls.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-create-access-keys?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-create-access-keys.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-create-access-keys-for-windows-forms-controls?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-set-the-text-displayed-by-a-windows-forms-control.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-display-text?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-set-the-display-text.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-text-displayed-by-a-windows-forms-control?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-set-the-image-displayed-by-a-windows-forms-control.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-a-picture-to-a-control?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-add-a-picture-to-a-control.md", - "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-image-displayed-by-a-windows-forms-control?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/keyboard-input-in-a-windows-forms-application.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/overview?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/overview.md", - "redirect_url": "/dotnet/desktop/winforms/keyboard-input-in-a-windows-forms-application?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/using-keyboard-events.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/events?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/events.md", - "redirect_url": "/dotnet/desktop/winforms/using-keyboard-events?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/user-input-validation-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/validation?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/validation.md", - "redirect_url": "/dotnet/desktop/winforms/user-input-validation-in-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-modify-keyboard-input-to-a-standard-control.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-change-key-press?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-change-key-press.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-modify-keyboard-input-to-a-standard-control?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-determine-which-modifier-key-was-pressed.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-check-modifier-key?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-check-modifier-key.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-determine-which-modifier-key-was-pressed?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-handle-keyboard-input-at-the-form-level.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-handle-forms?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-handle-forms.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-handle-keyboard-input-at-the-form-level?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-simulate-events.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-simulate-mouse-and-keyboard-events-in-code?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/mouse-input-in-a-windows-forms-application.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/overview?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/overview.md", - "redirect_url": "/dotnet/desktop/winforms/mouse-input-in-a-windows-forms-application?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/mouse-events-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/events?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/events.md", - "redirect_url": "/dotnet/desktop/winforms/mouse-events-in-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/drag-and-drop-functionality-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/drag-and-drop?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/drag-and-drop.md", - "redirect_url": "/dotnet/desktop/winforms/drag-and-drop-functionality-in-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/mouse-pointers-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-manage-cursor-pointer?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-manage-cursor-pointer.md", - "redirect_url": "/dotnet/desktop/winforms/mouse-pointers-in-windows-forms?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-simulate-mouse-and-keyboard-events-in-code.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-simulate-events?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-simulate-events.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-simulate-mouse-and-keyboard-events-in-code?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-to-distinguish-between-clicks-and-double-clicks.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-distinguish-between-clicks-and-double-clicks?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-distinguish-between-clicks-and-double-clicks.md", - "redirect_url": "/dotnet/desktop/winforms/how-to-distinguish-between-clicks-and-double-clicks?view=netframeworkdesktop-4.8" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/creating-event-handlers-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/forms/events?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/control-type-recommendations.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/rendering-a-windows-forms-control.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/controls/user-drawn-controls.md", - "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-keyboard-input-works.md", - "redirect_url": "/dotnet/desktop/winforms/input-keyboard/overview?view=netdesktop-5.0" - }, - { - "source_path": "dotnet-desktop-guide/net/winforms/how-mouse-input-works-in-windows-forms.md", - "redirect_url": "/dotnet/desktop/winforms/input-mouse/overview?view=netdesktop-5.0" - } - ] + "redirections": [ + { + "source_path": "dotnet-desktop-guide/net/winforms/windows-forms-overview.md", + "redirect_url": "/dotnet/desktop/winforms/overview/?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/overview/index.md", + "redirect_url": "/dotnet/desktop/winforms/windows-forms-overview?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-create-a-windows-forms-application-from-the-command-line.md", + "redirect_url": "/dotnet/desktop/winforms/get-started/create-app-visual-studio?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/get-started/create-app-visual-studio.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-create-a-windows-forms-application-from-the-command-line?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/events-overview-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/forms/events?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/forms/events.md", + "redirect_url": "/dotnet/desktop/winforms/events-overview-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/automatic-scaling-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/forms/autoscale?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/forms/autoscale.md", + "redirect_url": "/dotnet/desktop/winforms/automatic-scaling-in-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-resize-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/forms/how-to-position-and-resize?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/forms/how-to-position-and-resize.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-resize-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/layout-in-windows-forms-controls.md", + "redirect_url": "/dotnet/desktop/winforms/controls/layout?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/layout.md", + "redirect_url": "/dotnet/desktop/winforms/controls/layout-in-windows-forms-controls?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/label-control-overview-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/controls/labels?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/labels.md", + "redirect_url": "/dotnet/desktop/winforms/controls/label-control-overview-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/varieties-of-custom-controls.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/custom.md", + "redirect_url": "/dotnet/desktop/winforms/controls/varieties-of-custom-controls?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/custom-control-painting-and-rendering.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/custom-painting-drawing.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom-control-painting-and-rendering?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-add-controls-to-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-to-a-form?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-add-to-a-form.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-controls-to-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys-for-windows-forms-controls.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-create-access-keys?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-create-access-keys.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-create-access-keys-for-windows-forms-controls?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-set-the-text-displayed-by-a-windows-forms-control.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-display-text?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-set-the-display-text.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-text-displayed-by-a-windows-forms-control?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-set-the-image-displayed-by-a-windows-forms-control.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-add-a-picture-to-a-control?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-add-a-picture-to-a-control.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-image-displayed-by-a-windows-forms-control?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/keyboard-input-in-a-windows-forms-application.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/overview.md", + "redirect_url": "/dotnet/desktop/winforms/keyboard-input-in-a-windows-forms-application?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/using-keyboard-events.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/events?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/events.md", + "redirect_url": "/dotnet/desktop/winforms/using-keyboard-events?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/user-input-validation-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/validation?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/validation.md", + "redirect_url": "/dotnet/desktop/winforms/user-input-validation-in-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-modify-keyboard-input-to-a-standard-control.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-change-key-press?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-change-key-press.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-modify-keyboard-input-to-a-standard-control?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-determine-which-modifier-key-was-pressed.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-check-modifier-key?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-check-modifier-key.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-determine-which-modifier-key-was-pressed?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-handle-keyboard-input-at-the-form-level.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/how-to-handle-forms?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-handle-forms.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-handle-keyboard-input-at-the-form-level?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-keyboard/how-to-simulate-events.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-simulate-mouse-and-keyboard-events-in-code?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/mouse-input-in-a-windows-forms-application.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/overview.md", + "redirect_url": "/dotnet/desktop/winforms/mouse-input-in-a-windows-forms-application?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/mouse-events-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/events?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/events.md", + "redirect_url": "/dotnet/desktop/winforms/mouse-events-in-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/drag-and-drop-functionality-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/drag-and-drop?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/drag-and-drop.md", + "redirect_url": "/dotnet/desktop/winforms/drag-and-drop-functionality-in-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/mouse-pointers-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-manage-cursor-pointer?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-manage-cursor-pointer.md", + "redirect_url": "/dotnet/desktop/winforms/mouse-pointers-in-windows-forms?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-simulate-mouse-and-keyboard-events-in-code.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-simulate-events?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-simulate-events.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-simulate-mouse-and-keyboard-events-in-code?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-to-distinguish-between-clicks-and-double-clicks.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/how-to-distinguish-between-clicks-and-double-clicks?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/input-mouse/how-to-distinguish-between-clicks-and-double-clicks.md", + "redirect_url": "/dotnet/desktop/winforms/how-to-distinguish-between-clicks-and-double-clicks?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/creating-event-handlers-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/forms/events?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/control-type-recommendations.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/rendering-a-windows-forms-control.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/user-drawn-controls.md", + "redirect_url": "/dotnet/desktop/winforms/controls/custom-painting-drawing?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-keyboard-input-works.md", + "redirect_url": "/dotnet/desktop/winforms/input-keyboard/overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/how-mouse-input-works-in-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/input-mouse/overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/introduction-to-wpf.md", + "redirect_url": "/dotnet/desktop/wpf/overview/?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/overview/index.md", + "redirect_url": "/dotnet/desktop/wpf/introduction-to-wpf?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/getting-started/walkthrough-my-first-wpf-desktop-application.md", + "redirect_url": "/dotnet/desktop/wpf/get-started/create-app-visual-studio?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/get-started/create-app-visual-studio.md", + "redirect_url": "/dotnet/desktop/wpf/getting-started/walkthrough-my-first-wpf-desktop-application?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/wpf-windows-overview.md", + "redirect_url": "/dotnet/desktop/wpf/windows/index?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/windows/index.md", + "redirect_url": "/dotnet/desktop/wpf/app-development/wpf-windows-overview?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/dialog-boxes-overview.md", + "redirect_url": "/dotnet/desktop/wpf/windows/dialog-boxes-overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/windows/dialog-boxes-overview.md", + "redirect_url": "/dotnet/desktop/wpf/app-development/dialog-boxes-overview?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/how-to-open-a-window.md", + "redirect_url": "/dotnet/desktop/wpf/windows/how-to-open-window-dialog-box?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/windows/how-to-open-window-dialog-box.md", + "redirect_url": "/dotnet/desktop/wpf/app-development/how-to-open-a-window?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/how-to-open-a-dialog-box.md", + "redirect_url": "/dotnet/desktop/wpf/windows/how-to-open-window-dialog-box?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/how-to-return-a-dialog-box-result.md", + "redirect_url": "/dotnet/desktop/wpf/windows/how-to-open-window-dialog-box?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/how-to-open-a-message-box.md", + "redirect_url": "/dotnet/desktop/wpf/windows/how-to-open-message-box?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/windows/how-to-open-message-box.md", + "redirect_url": "/dotnet/desktop/wpf/app-development/how-to-open-a-message-box?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/app-development/how-to-get-and-set-the-main-application-window.md", + "redirect_url": "/dotnet/desktop/wpf/windows/how-to-get-set-main-application-window?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/windows/how-to-get-set-main-application-window.md", + "redirect_url": "/dotnet/desktop/wpf/app-development/how-to-get-and-set-the-main-application-window?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/data/data-binding-overview.md", + "redirect_url": "/dotnet/desktop/wpf/data/index?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/xaml-in-wpf.md", + "redirect_url": "/dotnet/desktop/wpf/xaml/index?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/xaml/index.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/xaml-in-wpf?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/fundamentals/xaml.md", + "redirect_url": "/dotnet/desktop/wpf/xaml/overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/fundamentals/xaml-resources-define.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/fundamentals/styles-templates-overview.md", + "redirect_url": "/dotnet/desktop/wpf/controls/styles-templates-overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/fundamentals/styles-templates-create-apply-style.md", + "redirect_url": "/dotnet/desktop/wpf/controls/how-to-create-apply-style?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/themes/how-to-create-apply-template.md", + "redirect_url": "/dotnet/desktop/wpf/controls/how-to-create-apply-template?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/xaml-resources-define.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-overview?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-overview.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/xaml-resources-define?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/resources-and-code.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-and-code?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-and-code.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/resources-and-code?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/merged-resource-dictionaries.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-merged-dictionaries?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-merged-dictionaries.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/merged-resource-dictionaries?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-define-and-reference-a-resource.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-define-and-reference?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-how-to-define-and-reference.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/how-to-define-and-reference-a-resource?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-use-application-resources.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-use-application?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-how-to-use-application.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/how-to-use-application-resources?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-use-systemfonts.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-use-system?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/wpf/systems/xaml-resources-how-to-use-system.md", + "redirect_url": "/dotnet/desktop/wpf/advanced/how-to-use-systemfonts?view=netframeworkdesktop-4.8" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-use-system-fonts-keys.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-use-system?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-use-systemparameters.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-use-system?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/net/wpf/advanced/how-to-use-system-parameters-keys.md", + "redirect_url": "/dotnet/desktop/wpf/systems/xaml-resources-how-to-use-system?view=netdesktop-5.0" + } + ] } diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md b/dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-style.md similarity index 78% rename from dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md rename to dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-style.md index 5201e6e..bf4e314 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-create-apply-style.md +++ b/dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-style.md @@ -1,9 +1,9 @@ --- -title: Create a style for a control +title: How to create a style for a control description: Learn how to create and reference a control style in Windows Presentation Foundation and .NET. author: adegeo ms.author: adegeo -ms.date: 09/12/2019 +ms.date: 04/15/2021 ms.topic: conceptual dev_langs: - "csharp" @@ -11,7 +11,7 @@ dev_langs: #no-loc: [TextBlock, Setter] --- -# Create a style for a control (WPF .NET) +# How to create a style for a control (WPF .NET) With Windows Presentation Foundation (WPF), you can customize an existing control's appearance with your own reusable style. Styles can be applied globally to your app, windows and pages, or directly to controls. @@ -23,11 +23,11 @@ You can think of a as a convenient way to apply a se The most common way to declare a style is as a resource in the `Resources` section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied. For example, if you declare the style in the root element of your app definition XAML file, the style can be used anywhere in your app. -[!code-xaml[AppResources](./snippets/styles-templates-create-apply-style/csharp/App.xaml#AppResources)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/App.xaml" id="AppResources"::: -If you declare the style in one of the app's XAML files, the style can be used only in that XAML file. For more information about scoping rules for resources, see [XAML Resources](xaml-resources-define.md). +If you declare the style in one of the app's XAML files, the style can be used only in that XAML file. For more information about scoping rules for resources, see [Overview of XAML resources](../systems/xaml-resources-overview.md). -[!code-xaml[AppResources](./snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml#WindowResources)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/WindowSingleResource.xaml" id="WindowResources"::: A style is made up of `` child elements that set properties on the elements the style is applied to. In the example above, notice that the style is set to apply to `TextBlock` types through the `TargetType` attribute. The style will set the to `15` and the to `ExtraBold`. Add a `` for each property the style changes. @@ -35,19 +35,19 @@ A style is made up of `` child elements that set properties on the eleme A is a convenient way to apply a set of property values to more than one element. For example, consider the following elements and their default appearance in a window. -[!code-xaml[TextBlocks](./snippets/styles-templates-create-apply-style/csharp/Window1.xaml#SnippetTextBlocks)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/Window1.xaml" id="SnippetTextBlocks"::: -![Styling sample screenshot before](./media/styles-and-templates-overview/stylingintro-textblocksbefore.png "StylingIntro_TextBlocksBefore") +:::image type="content" source="./media/how-to-create-apply-style/stylingintro-textblocksbefore.png" alt-text="Styling sample screenshot before"::: You can change the default appearance by setting properties, such as and , on each element directly. However, if you want your elements to share some properties, you can create a in the `Resources` section of your XAML file, as shown here. -[!code-xaml[DefaultTextBlockStyle](./snippets/styles-templates-create-apply-style/csharp/Window1.xaml#SnippetDefaultTextBlockStyle)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/Window1.xaml" id="SnippetDefaultTextBlockStyle"::: When you set the of your style to the type and omit the `x:Key` attribute, the style is applied to all the elements scoped to the style, which is generally the XAML file itself. Now the elements appear as follows. -![Styling sample screenshot base style](./media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png "StylingIntro_TextBlocksBaseStyle") +:::image type="content" source="./media/how-to-create-apply-style/stylingintro-textblocksbasestyle.png" alt-text="Styling sample screenshot base style"::: ## Apply a style explicitly @@ -55,15 +55,15 @@ If you add an `x:Key` attribute with value to the style, the style is no longer Here is the style from the previous section, but declared with the `x:Key` attribute. -[!code-xaml[ExplicitStyleDeclare](./snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml#ExplicitStyleDeclare)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml" id="ExplicitStyleDeclare"::: To apply the style, set the property on the element to the `x:Key` value, using a [StaticResource markup extension](../../../framework/wpf/advanced/staticresource-markup-extension.md), as shown here. -[!code-xaml[ExplicitStyleReference](./snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml#ExplicitStyleReference)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml" id="ExplicitStyleReference"::: Notice that the first element has the style applied to it while the second TextBlock element remains unchanged. The implicit style from the previous section was changed to a style that declared the `x:Key` attribute, meaning, the only element affected by the style is the one that referenced the style directly. -![Styling sample screenshot textblock](./media/styles-and-templates-overview/create-a-style-explicit-textblock.png "create-a-style-explicit-textblock") +:::image type="content" source="./media/how-to-create-apply-style/create-a-style-explicit-textblock.png" alt-text="Styling sample screenshot textblock"::: Once a style is applied, explicitly or implicitly, it becomes sealed and can't be changed. If you want to change a style that has been applied, create a new style to replace the existing one. For more information, see the property. @@ -73,22 +73,22 @@ You can create an object that chooses a style to apply based on custom logic. Fo To assign a named style to an element programmatically, get the style from the resources collection and assign it to the element's property. The items in a resources collection are of type . Therefore, you must cast the retrieved style to a before assigning it to the `Style` property. For example, the following code sets the style of a `TextBlock` named `textblock1` to the defined style `TitleText`. -[!code-csharp[SetStyleCode](./snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs#SnippetSetStyleCode)] -[!code-vb[SetStyleCode](./snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb#SnippetSetStyleCode)] +:::code language="csharp" source="./snippets/how-to-create-apply-style/csharp/Window2.xaml.cs" id="SnippetSetStyleCode"::: +:::code language="vb" source="./snippets/how-to-create-apply-style/vb/MainWindow.xaml.vb" id="SnippetSetStyleCode"::: ## Extend a style Perhaps you want your two elements to share some property values, such as the and the centered . But you also want the text **My Pictures** to have some additional properties. You can do that by creating a new style that is based on the first style, as shown here. -[!code-xaml[DefaultTextBlockStyleBasedOn](./snippets/styles-templates-create-apply-style/csharp/Window2.xaml#SnippetDefaultTextBlockStyleBasedOn)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/Window2.xaml" id="SnippetDefaultTextBlockStyleBasedOn"::: -[!code-xaml[TextBlocksExplicit](./snippets/styles-templates-create-apply-style/csharp/Window2.xaml#SnippetTextBlocksExplicit)] +:::code language="xaml" source="./snippets/how-to-create-apply-style/csharp/Window2.xaml" id="SnippetTextBlocksExplicit"::: This `TextBlock` style is now centered, uses a `Comic Sans MS` font with a size of `26`, and the foreground color set to the shown in the example. Notice that it overrides the value of the base style. If there's more than one pointing to the same property in a , the `Setter` that is declared last takes precedence. The following shows what the elements now look like: -![Styled TextBlocks](./media/styles-and-templates-overview/stylingintro-textblocks.png "StylingIntro_TextBlocks") +:::image type="content" source="./media/how-to-create-apply-style/stylingintro-textblocks.png" alt-text="Styled TextBlocks"::: This `TitleText` style extends the style that has been created for the type, referenced with `BasedOn="{StaticResource {x:Type TextBlock}}"`. You can also extend a style that has an `x:Key` by using the `x:Key` of the style. For example, if there was a style named `Header1` and you wanted to extend that style, you would use `BasedOn="{StaticResource Header1}"`. @@ -102,6 +102,6 @@ Also note that many WPF controls consist of a combination of other WPF controls. ## See also - -- [Overview of XAML Resources](xaml-resources-define.md) -- [XAML overview (WPF & .NET Core)](xaml.md) +- [How to create a template for a control](how-to-create-apply-template.md) +- [Overview of XAML resources](../systems/xaml-resources-overview.md) +- [XAML overview](../xaml/index.md) diff --git a/dotnet-desktop-guide/net/wpf/themes/how-to-create-apply-template.md b/dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-template.md similarity index 76% rename from dotnet-desktop-guide/net/wpf/themes/how-to-create-apply-template.md rename to dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-template.md index db71e70..be2b8cd 100644 --- a/dotnet-desktop-guide/net/wpf/themes/how-to-create-apply-template.md +++ b/dotnet-desktop-guide/net/wpf/controls/how-to-create-apply-template.md @@ -1,9 +1,9 @@ --- -title: Create a template in WPF - .NET Desktop +title: How to create a template description: Learn how to create and reference a control template in Windows Presentation Foundation and .NET Core. author: adegeo ms.author: adegeo -ms.date: 11/15/2019 +ms.date: 04/15/2021 no-loc: ["", "", "", "", "", "", "", "", "", "", "", "", "SizeToContent", "MinWidth", "TargetType", "Title"] ms.topic: how-to helpviewer_keywords: @@ -15,7 +15,7 @@ helpviewer_keywords: - "templates [WPF], custom for existing controls" --- -# Create a template for a control +# How to create a template for a control (WPF.NET) With Windows Presentation Foundation (WPF), you can customize an existing control's visual structure and behavior with your own reusable template. Templates can be applied globally to your application, windows and pages, or directly to controls. Most scenarios that require you to create a new control can be covered by instead creating a new template for an existing control. @@ -37,23 +37,23 @@ On the other hand, if you need a control with new functionality, different prope Create a new WPF application and in *MainWindow.xaml* (or another window of your choice) set the following properties on the **\** element: -| | | -| --- | --- | +| Property | Value | +|-------------------|-------------------------| | **Title** | `Template Intro Sample` | -| **SizeToContent** | `WidthAndHeight` | -| **MinWidth** | `250` | +| **SizeToContent** | `WidthAndHeight` | +| **MinWidth** | `250` | Set the content of the **\** element to the following XAML: -[!code-xaml[Initial](./snippets/how-to-create-apply-template/csharp/Window1.xaml#Initial)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window1.xaml" id="Initial"::: In the end, the *MainWindow.xaml* file should look similar to the following: -[!code-xaml[InitialWhole](./snippets/how-to-create-apply-template/csharp/Window1.xaml#InitialWhole)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window1.xaml" id="InitialWhole"::: If you run the application, it looks like the following: -![WPF window with two unstyled buttons](media/create-apply-template/unstyled-button.png) +:::image type="content" source="media/how-to-create-apply-template/unstyled-button.png" alt-text="WPF window with two unstyled buttons"::: ## Create a ControlTemplate @@ -61,14 +61,14 @@ The most common way to declare a To start with, add a `Window.Resources` element to your *MainWindow.xaml* file: -[!code-xaml[WindowResStart](./snippets/how-to-create-apply-template/csharp/Window2.xaml#WindowResStart)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window2.xaml" id="WindowResStart"::: Create a new **\** with the following properties set: -| | | -| --- | --- | -| **x:Key** | `roundbutton` | -| **TargetType** | `Button` | +| Property | Value | +|----------------|---------------| +| **x:Key** | `roundbutton` | +| **TargetType** | `Button` | This control template will be simple: @@ -76,7 +76,7 @@ This control template will be simple: - an to draw the rounded appearance of the button - a to display the user-specified button content -[!code-xaml[ControlTemplate](./snippets/how-to-create-apply-template/csharp/Window3.xaml#ControlTemplate)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window3.xaml" id="ControlTemplate"::: ### TemplateBinding @@ -108,21 +108,21 @@ If the is applied to a property to the `roundbutton` resource: -[!code-xaml[StyledButton](./snippets/how-to-create-apply-template/csharp/Window3.xaml#StyledButton)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window3.xaml" id="StyledButton"::: If you run the project and look at the result, you'll see that the button has a rounded background. -![WPF window with one template oval button](media/create-apply-template/styled-button.png) +:::image type="content" source="media/how-to-create-apply-template/styled-button.png" alt-text="WPF window with one template oval button"::: You may have noticed that the button isn't a circle but is skewed. Because of the way the **\** element works, it always expands to fill the available space. Make the circle uniform by changing the button's **:::no-loc text="width":::** and **:::no-loc text="height":::** properties to the same value: -[!code-xaml[StyledButtonSize](./snippets/how-to-create-apply-template/csharp/Window3.xaml#StyledButtonSize)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window3.xaml" id="StyledButtonSize"::: -![WPF window with one template circular button](media/create-apply-template/styled-uniform-button.png) +:::image type="content" source="media/how-to-create-apply-template/styled-uniform-button.png" alt-text="WPF window with one template circular button"::: ## Add a Trigger @@ -132,7 +132,7 @@ With the dynamic event and property systems that WPF provides, you can watch a s For this to work, you'll need to add a name to the **\** that you can reference. Give it the name of **backgroundElement**. -[!code-xaml[EllipseName](./snippets/how-to-create-apply-template/csharp/Window4.xaml#EllipseName)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window4.xaml" id="EllipseName"::: Next, add a new to the [ControlTemplate.Triggers](xref:System.Windows.Controls.ControlTemplate.Triggers) collection. The trigger will watch the `IsMouseOver` event for the value `true`. @@ -140,23 +140,23 @@ Next, add a new to the [ControlTemplate.Triggers]( Next, add a **\** to the **\** that changes the **Fill** property of the **\** to a new color. -[!code-xaml[MouseOver](./snippets/how-to-create-apply-template/csharp/Window5.xaml#MouseOver)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window5.xaml" id="MouseOver"::: Run the project. Notice that when you move the mouse over the button, the color of the **\** changes. -![mouse moves over WPF button to change the fill color](media/create-apply-template/mouse-move-over-button.gif) +:::image type="content" source="media/how-to-create-apply-template/mouse-move-over-button.gif" alt-text="mouse moves over WPF button to change the fill color"::: ## Use a VisualState -Visual states are defined and triggered by a control. For example, when the mouse is moved on top of the control, the `CommonStates.MouseOver` state is triggered. You can animate property changes based on the current state of the control. In the previous section, a **\** was used to change the foreground of the button to `AliceBlue` when the `IsMouseOver` property was `true`. Instead, create a visual state that animates the change of this color, providing a smooth transition. For more information about *VisualStates*, see [Styles and templates in WPF](../fundamentals/styles-templates-overview.md#visual-states). +Visual states are defined and triggered by a control. For example, when the mouse is moved on top of the control, the `CommonStates.MouseOver` state is triggered. You can animate property changes based on the current state of the control. In the previous section, a **\** was used to change the foreground of the button to `AliceBlue` when the `IsMouseOver` property was `true`. Instead, create a visual state that animates the change of this color, providing a smooth transition. For more information about *VisualStates*, see [Styles and templates in WPF](styles-templates-overview.md#visual-states). To convert the **\** to an animated visual state, First, remove the **\** element from your template. -[!code-xaml[CleanTemplate](./snippets/how-to-create-apply-template/csharp/Window5.xaml#CleanTemplate)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window5.xaml" id="CleanTemplate"::: Next, in the **\** root of the control template, add the **\** element with a **\** for `CommonStates`. Define two states, `Normal` and `MouseOver`. -[!code-xaml[VisualState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#VisualState)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window6.xaml" id="VisualState"::: Any animations defined in a **\** are applied when that state is triggered. Create animations for each state. Animations are put inside of a **\** element. For more information about storyboards, see [Storyboards Overview](../../../framework/wpf/graphics-multimedia/storyboards-overview.md). @@ -164,24 +164,24 @@ Any animations defined in a **\** are applied when that state is tr This state animates the ellipse fill, restoring it to the control's `Background` color. - [!code-xaml[NormalState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#NormalState)] + :::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window6.xaml" id="NormalState"::: - MouseOver This state animates the ellipse `Background` color to a new color: `Yellow`. - [!code-xaml[MouseOverState](./snippets/how-to-create-apply-template/csharp/Window6.xaml#MouseOverState)] + :::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window6.xaml" id="MouseOverState"::: The **\** should now look like the following. -[!code-xaml[FinalTemplate](./snippets/how-to-create-apply-template/csharp/Window7.xaml#FinalTemplate)] +:::code language="xaml" source="./snippets/how-to-create-apply-template/csharp/Window7.xaml" id="FinalTemplate"::: Run the project. Notice that when you move the mouse over the button, the color of the **\** animates. -![mouse moves over WPF button to change the fill color](media/create-apply-template/mouse-move-over-button-visualstate.gif) +:::image type="content" source="media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif" alt-text="mouse moves over WPF button to change the fill color with a visual state"::: ## Next steps -- [Create a style for a control in WPF](../fundamentals/styles-templates-create-apply-style.md) -- [Styles and templates in WPF](../fundamentals/styles-templates-overview.md) -- [Overview of XAML Resources](../fundamentals/xaml-resources-define.md) +- [Create a style for a control](how-to-create-apply-style.md) +- [Styles and templates](styles-templates-overview.md) +- [Overview of XAML resources](../systems/xaml-resources-overview.md) diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/create-a-style-explicit-textblock.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/create-a-style-explicit-textblock.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/create-a-style-explicit-textblock.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/create-a-style-explicit-textblock.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocks.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocks.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocks.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocks.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocksbasestyle.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocksbasestyle.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocksbasestyle.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocksbefore.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocksbefore.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-textblocksbefore.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-style/stylingintro-textblocksbefore.png diff --git a/dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/mouse-move-over-button-visualstate.gif b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/mouse-move-over-button-visualstate.gif rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button-visualstate.gif diff --git a/dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/mouse-move-over-button.gif b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button.gif similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/mouse-move-over-button.gif rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/mouse-move-over-button.gif diff --git a/dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/styled-button.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/styled-button.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/styled-button.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/styled-button.png diff --git a/dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/styled-uniform-button.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/styled-uniform-button.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/styled-uniform-button.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/styled-uniform-button.png diff --git a/dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/unstyled-button.png b/dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/unstyled-button.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/media/create-apply-template/unstyled-button.png rename to dotnet-desktop-guide/net/wpf/controls/media/how-to-create-apply-template/unstyled-button.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-eventtriggers.png b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-eventtriggers.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-eventtriggers.png rename to dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-eventtriggers.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-listboxbefore.png b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-listboxbefore.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-listboxbefore.png rename to dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-listboxbefore.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-photosasimages.png b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-photosasimages.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-photosasimages.png rename to dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-photosasimages.png diff --git a/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png new file mode 100644 index 0000000..e03d4f8 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-textblocks.png differ diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-triggers.png b/dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-triggers.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/media/styles-and-templates-overview/stylingintro-triggers.png rename to dotnet-desktop-guide/net/wpf/controls/media/styles-and-templates-overview/stylingintro-triggers.png diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/App.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/App.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/App.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/App.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/App.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/App.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/App.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/CSharpExample.csproj similarity index 88% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/CSharpExample.csproj index 661e3a7..d06a948 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/CSharpExample.csproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/CSharpExample.csproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/MainWindow.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/MainWindow.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/MainWindow.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/MainWindow.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Photo.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Photo.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Photo.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Photo.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/PhotoList.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/PhotoList.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/PhotoList.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/PhotoList.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window1.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window1.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window1.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window1.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window1.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window1.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window2.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window2.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window2.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window2.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window2.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window2.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window3.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window3.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window3.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window3.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window3.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window3.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window3.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window3.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window4.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window4.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window4.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window4.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window4.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window4.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window4.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window4.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window5.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window5.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window5.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window5.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window5.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window5.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window5.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window5.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window6.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window6.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window6.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window6.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window6.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window6.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/Window6.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/Window6.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowExplicitStyle.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowExplicitStyle.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowSingleResource.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowSingleResource.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowSingleResource.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/WindowSingleResource.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/WindowSingleResource.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/flower1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/flower1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/flower1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/flower1.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/flower2.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/flower2.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/flower2.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/flower2.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/leaf1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/leaf1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/leaf1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/leaf1.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/leaf2.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/leaf2.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/leaf2.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/leaf2.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/winter1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/winter1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/csharp/images/winter1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/csharp/images/winter1.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Application.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Application.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Application.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Application.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Application.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Application.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/MainWindow.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/MainWindow.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/MainWindow.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Photo.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Photo.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/Photo.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/Photo.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/VBExample.vbproj b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/VBExample.vbproj similarity index 69% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/VBExample.vbproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/VBExample.vbproj index c453c2b..9f70f29 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/VBExample.vbproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-style/vb/VBExample.vbproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/App.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/App.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/App.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/App.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/App.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/App.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/App.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj similarity index 69% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj index c453c2b..9f70f29 100644 --- a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/CSharpExample.csproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/MainWindow.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/MainWindow.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window1.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window1.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window2.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window2.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window3.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window3.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window3.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window3.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window4.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window4.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window4.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window4.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window5.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window5.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window5.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window5.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window6.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window6.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window6.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window6.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window7.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window7.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/Window7.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Application.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Application.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/Application.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/MainWindow.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj similarity index 69% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj index c453c2b..9f70f29 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-create-apply-style/vb/VBExample.vbproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/how-to-create-apply-template/vb/VBExample.vbproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/App.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/App.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/App.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/App.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/App.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/App.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/App.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/CSharpExample.csproj b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj similarity index 88% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/CSharpExample.csproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj index 661e3a7..d06a948 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/CSharpExample.csproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/CSharpExample.csproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/MainWindow.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/MainWindow.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Photo.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Photo.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Photo.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Photo.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/PhotoList.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/PhotoList.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/PhotoList.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/PhotoList.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window1.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window1.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window1.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window2.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window2.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window2.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window3.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window3.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window3.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window3.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window4.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window4.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window4.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window4.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window5.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window5.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window5.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window5.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window6.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/Window6.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/Window6.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/Window6.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowExplicitStyle.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowExplicitStyle.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/csharp/WindowSingleResource.xaml.cs rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/WindowSingleResource.xaml.cs diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/flower1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/flower1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/flower1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/flower1.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/flower2.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/flower2.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/flower2.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/flower2.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/leaf1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/leaf1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf1.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/leaf2.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf2.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/leaf2.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/leaf2.jpg diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/winter1.jpg b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/winter1.jpg similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/csharp/images/winter1.jpg rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/csharp/images/winter1.jpg diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/Application.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/Application.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Application.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/MainWindow.xaml rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/MainWindow.xaml.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/MainWindow.xaml.vb diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Photo.vb b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Photo.vb similarity index 100% rename from dotnet-desktop-guide/net/wpf/fundamentals/snippets/styles-templates-overview/vb/Photo.vb rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/Photo.vb diff --git a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/VBExample.vbproj b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj similarity index 69% rename from dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/VBExample.vbproj rename to dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj index c453c2b..9f70f29 100644 --- a/dotnet-desktop-guide/net/wpf/themes/snippets/how-to-create-apply-template/vb/VBExample.vbproj +++ b/dotnet-desktop-guide/net/wpf/controls/snippets/styles-templates-overview/vb/VBExample.vbproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows IntroToStylingAndTemplating true IntroToStylingAndTemplating diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md b/dotnet-desktop-guide/net/wpf/controls/styles-templates-overview.md similarity index 90% rename from dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md rename to dotnet-desktop-guide/net/wpf/controls/styles-templates-overview.md index 90ececa..b925b1e 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/styles-templates-overview.md +++ b/dotnet-desktop-guide/net/wpf/controls/styles-templates-overview.md @@ -3,7 +3,7 @@ title: Styles and templates description: Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET. Understand the types of XAML resources related to styles and themes. author: adegeo ms.author: adegeo -ms.date: 09/09/2019 +ms.date: 04/15/2021 ms.topic: overview dev_langs: - "csharp" @@ -16,9 +16,9 @@ Windows Presentation Foundation (WPF) styling and templating refer to a suite of Another feature of the WPF styling model is the separation of presentation and logic. Designers can work on the appearance of an app by using only XAML at the same time that developers work on the programming logic by using C# or Visual Basic. -This overview focuses on the styling and templating aspects of the app and doesn't discuss any data-binding concepts. For information about data binding, see [Data Binding Overview](../data/data-binding-overview.md). +This overview focuses on the styling and templating aspects of the app and doesn't discuss any data-binding concepts. For information about data binding, see [Data Binding Overview](../data/index.md). -It's important to understand resources, which are what enable styles and templates to be reused. For more information about resources, see [XAML Resources](xaml-resources-define.md). +It's important to understand resources, which are what enable styles and templates to be reused. For more information about resources, see [Overview of XAML resources](../systems/xaml-resources-overview.md). [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] @@ -26,7 +26,7 @@ It's important to understand resources, which are what enable styles and templat The sample code provided in this overview is based on a [simple photo browsing application](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating) shown in the following illustration. -![Styled ListView](./media/styles-and-templates-overview/stylingintro-triggers.png "StylingIntro_triggers") +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-triggers.png" alt-text="Styled ListView"::: This simple photo sample uses styling and templating to create a visually compelling user experience. The sample has two elements and a control that is bound to a list of images. @@ -40,15 +40,15 @@ The most common way to declare a style is as a resource in the `Resources` secti For example, the following XAML code declares two styles for a `TextBlock`, one automatically applied to all `TextBlock` elements, and another that must be explicitly referenced. -[!code-xaml[SnippetDefaultTextBlockStyleBasedOn](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetDefaultTextBlockStyleBasedOn)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window2.xaml" id="SnippetDefaultTextBlockStyleBasedOn"::: Here is an example of the styles declared above being used. -[!code-xaml[SnippetTextBlocksExplicit](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetTextBlocksExplicit)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window2.xaml" id="SnippetTextBlocksExplicit"::: -![Styled textblocks](./media/styles-and-templates-overview/stylingintro-textblocks.png) +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-textblocks.png" alt-text="Styled textblocks"::: -For more information, see [Create a style for a control](styles-templates-create-apply-style.md). +For more information, see [Create a style for a control](how-to-create-apply-style.md). ## ControlTemplates @@ -95,7 +95,7 @@ Designers generally allow you to create a copy of an existing template and modif Editing a copy of a template is a great way to learn how templates work. Instead of creating a new blank template, it's easier to edit a copy and change a few aspects of the visual presentation. -For an example, see [Create a template for a control](../themes/how-to-create-apply-template.md). +For an example, see [Create a template for a control](how-to-create-apply-template.md). ### TemplateBinding @@ -109,28 +109,28 @@ If a is declared in the control that is bound to a list of photos. -[!code-xaml[ListBox](./snippets/styles-templates-overview/csharp/Window3.xaml#SnippetListBox)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window3.xaml" id="SnippetListBox"::: This currently looks like the following. -![ListBox before applying template](./media/styles-and-templates-overview/stylingintro-listboxbefore.png "StylingIntro_ListBoxBefore") +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-listboxbefore.png" alt-text="ListBox before applying template"::: Most controls have some type of content, and that content often comes from data that you are binding to. In this sample, the data is the list of photos. In WPF, you use a to define the visual representation of data. Basically, what you put into a determines what the data looks like in the rendered app. In our sample app, each custom `Photo` object has a `Source` property of type string that specifies the file path of the image. Currently, the photo objects appear as file paths. -[!code-csharp[PhotoClass](./snippets/styles-templates-overview/csharp/Photo.cs#PhotoClass)] -[!code-vb[PhotoClass](./snippets/styles-templates-overview/vb/Photo.vb#PhotoClass)] +:::code language="csharp" source="./snippets/styles-templates-overview/csharp/Photo.cs" id="PhotoClass"::: +:::code language="vb" source="./snippets/styles-templates-overview/vb/Photo.vb" id="PhotoClass"::: For the photos to appear as images, you create a as a resource. -[!code-xaml[DataTemplate](./snippets/styles-templates-overview/csharp/Window4.xaml#SnippetDataTemplate)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window4.xaml" id="SnippetDataTemplate"::: Notice that the property is similar to the property of the . If your is in the resources section, when you specify the property to a type and omit an `x:Key`, the is applied whenever that type appears. You always have the option to assign the with an `x:Key` and then set it as a `StaticResource` for properties that take types, such as the property or the property. Essentially, the in the above example defines that whenever there is a `Photo` object, it should appear as an within a . With this , our app now looks like this. -![Photo image](./media/styles-and-templates-overview/stylingintro-photosasimages.png "StylingIntro_PhotosAsImages") +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-photosasimages.png" alt-text="Photo image"::: The data templating model provides other features. For example, if you are displaying collection data that contains other collections using a type such as a or a , there is the . Another data templating feature is the , which allows you to choose a to use based on custom logic. For more information, see [Data Templating Overview](../../../framework/wpf/data/data-templating-overview.md), which provides a more in-depth discussion of the different data templating features. @@ -144,25 +144,25 @@ A that sets property values or starts actions base To demonstrate how to use property triggers, you can make each partially transparent unless it is selected. The following style sets the value of a to `0.5`. When the property is `true`, however, the is set to `1.0`. -[!code-xaml[PropertyTrigger](./snippets/styles-templates-overview/csharp/Window5.xaml#SnippetPropertyTrigger)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window5.xaml" id="SnippetPropertyTrigger"::: This example uses a to set a property value, but note that the class also has the and properties that enable a trigger to perform actions. Notice that the property of the is set to `75`. In the following illustration, the third item is the selected item. -![Styled ListView](./media/styles-and-templates-overview/stylingintro-triggers.png "StylingIntro_triggers") +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-triggers.png" alt-text="Styled ListView"::: ### EventTriggers and Storyboards Another type of trigger is the , which starts a set of actions based on the occurrence of an event. For example, the following objects specify that when the mouse pointer enters the , the property animates to a value of `90` over a `0.2` second period. When the mouse moves away from the item, the property returns to the original value over a period of `1` second. Note how it is not necessary to specify a value for the animation. This is because the animation is able to keep track of the original value. -[!code-xaml[StyleEventTriggers](./snippets/styles-templates-overview/csharp/Window6.xaml#SnippetStyleEventTriggers)] +:::code language="xaml" source="./snippets/styles-templates-overview/csharp/Window6.xaml" id="SnippetStyleEventTriggers"::: For more information, see the [Storyboards overview](../../../framework/wpf/graphics-multimedia/storyboards-overview.md). In the following illustration, the mouse is pointing to the third item. -![Styling sample screenshot](./media/styles-and-templates-overview/stylingintro-eventtriggers.png "StylingIntro_EventTriggers") +:::image type="content" source="./media/styles-and-templates-overview/stylingintro-eventtriggers.png" alt-text="Styling sample screenshot"::: ### MultiTriggers, DataTriggers, and MultiDataTriggers diff --git a/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md b/dotnet-desktop-guide/net/wpf/data/index.md similarity index 89% rename from dotnet-desktop-guide/net/wpf/data/data-binding-overview.md rename to dotnet-desktop-guide/net/wpf/data/index.md index e4adc97..e8f1b1e 100644 --- a/dotnet-desktop-guide/net/wpf/data/data-binding-overview.md +++ b/dotnet-desktop-guide/net/wpf/data/index.md @@ -2,9 +2,8 @@ title: Data binding overview description: Learn about the different data sources you can add to your project in Windows Presentation Foundation for .NET. Data sources can be bound to XAML elements to create dynamic apps. author: adegeo -ms.date: 09/19/2019 +ms.date: 03/25/2021 ms.author: adegeo -ms.topic: overview dev_langs: - "csharp" - "vb" @@ -28,7 +27,7 @@ A typical use of data binding is to place server or local configuration data int For an example of data binding, take a look at the following app UI from the [Data Binding Demo][data-binding-demo], which displays a list of auction items. -![Data binding sample screenshot](./media/data-binding-overview/demo.png "DataBinding_DataBindingDemo") +:::image type="content" source="./media/index/demo.png" alt-text="Data binding sample screenshot"::: The app demonstrates the following features of data binding: @@ -44,7 +43,7 @@ The app demonstrates the following features of data binding: When the user selects the *Add Product* button, the following form comes up. -![Add Product Listing page](./media/data-binding-overview/demo-addproductlisting.png "DataBinding_Demo_AddProductListing") +:::image type="content" source="./media/index/demo-addproductlisting.png" alt-text="Add Product Listing page"::: The user can edit the fields in the form, preview the product listing using the short or detailed preview panes, and select `Submit` to add the new product listing. Any existing grouping, filtering and sorting settings will apply to the new entry. In this particular case, the item entered in the above image will be displayed as the second item within the *Computer* category. @@ -56,7 +55,7 @@ Before going into the different features of data binding outlined above, we will Regardless of what element you are binding and the nature of your data source, each binding always follows the model illustrated by the following figure. -![Diagram that shows the basic data binding model.](./media/data-binding-overview/basic-data-binding-diagram.png) +:::image type="content" source="./media/index/basic-data-binding-diagram.png" alt-text="Diagram that shows the basic data binding model."::: As the figure shows, data binding is essentially the bridge between your binding target and your binding source. The figure demonstrates the following fundamental WPF data binding concepts: @@ -85,11 +84,11 @@ You may want your app to enable users to change the data and propagate it back t This figure illustrates the different types of data flow: -![Data binding data flow](./media/data-binding-overview/databinding-dataflow.png "DataBinding_DataFlow") +:::image type="content" source="./media/index/databinding-dataflow.png" alt-text="Data binding data flow"::: - binding causes changes to the source property to automatically update the target property, but changes to the target property are not propagated back to the source property. This type of binding is appropriate if the control being bound is implicitly read-only. For instance, you may bind to a source such as a stock ticker, or perhaps your target property has no control interface provided for making changes, such as a data-bound background color of a table. If there is no need to monitor the changes of the target property, using the binding mode avoids the overhead of the binding mode. -- binding causes changes to either the source property or the target property to automatically update the other. This type of binding is appropriate for editable forms or other fully interactive UI scenarios. Most properties default to binding, but some dependency properties (typically properties of user-editable controls such as the and [CheckBox.IsChecked](xref:System.Windows.Controls.Primitives.ToggleButton.IsChecked)) default to binding. A programmatic way to determine whether a dependency property binds one-way or two-way by default is to get the property metadata with and then check the Boolean value of the property. +- binding causes changes to either the source property or the target property to automatically update the other. This type of binding is appropriate for editable forms or other fully interactive UI scenarios. Most properties default to binding, but some dependency properties (typically properties of user-editable controls such as the and [CheckBox.IsChecked](xref:System.Windows.Controls.Primitives.ToggleButton.IsChecked) default to binding. A programmatic way to determine whether a dependency property binds one-way or two-way by default is to get the property metadata with and then check the Boolean value of the property. - is the reverse of binding; it updates the source property when the target property changes. One example scenario is if you only need to reevaluate the source value from the UI. @@ -105,13 +104,11 @@ Bindings that are or property determines what triggers the update of the source. The dots of the right arrows in the following figure illustrate the role of the property. -![Diagram that shows the role of the UpdateSourceTrigger property.](./media/data-binding-overview/data-binding-updatesource-trigger.png) +:::image type="content" source="./media/index/data-binding-updatesource-trigger.png" alt-text="Diagram that shows the role of the UpdateSourceTrigger property."::: If the `UpdateSourceTrigger` value is , then the value pointed to by the right arrow of or the bindings is updated as soon as the target property changes. However, if the `UpdateSourceTrigger` value is , then that value only is updated with the new value when the target property loses focus. -Similar to the property, different dependency properties have different default values. The default value for most dependency properties is , while the `TextBox.Text` property has a default value of . `PropertyChanged` means the source updates usually happen whenever the target property changes. Instant changes are fine for CheckBoxes and other simple controls. However, for text fields, updating after every keystroke can diminish performance and denies the user the usual opportunity to backspace and fix typing errors before committing to the new value. - -See the property page for information about how to find the default value of a dependency property. +Similar to the property, different dependency properties have different default values. The default value for most dependency properties is , which causes the source property's value to instantly change when the target property value is changed. Instant changes are fine for and other simple controls. However, for text fields, updating after every keystroke can diminish performance and denies the user the usual opportunity to backspace and fix typing errors before committing to the new value. For example, the `TextBox.Text` property defaults to the `UpdateSourceTrigger` value of which causes the source value to change only when the control element loses focus, not when the `TextBox.Text` property is changed. See the property page for information about how to find the default value of a dependency property. The following table provides an example scenario for each value using the as an example. @@ -123,19 +120,21 @@ The following table provides an example scenario for each object, and each binding usually has four components: a binding target, a target property, a binding source, and a path to the source value to use. This section discusses how to set up a binding. +When a databinding Binding sources are tied to the active for the element. Elements automatically inherit their `DataContext` if they've not explicitly defined one. + Consider the following example, in which the binding source object is a class named *MyData* that is defined in the *SDKSample* namespace. For demonstration purposes, *MyData* has a string property named *ColorName* whose value is set to "Red". Thus, this example generates a button with a red background. -[!code-xaml[BindNonTextProperty](./snippets/data-binding-overview/csharp/AutoConvertPropertyToColor.xaml#BindAutoConvertColor)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/AutoConvertPropertyToColor.xaml" id="BindAutoConvertColor"::: For more information on the binding declaration syntax and examples of how to set up a binding in code, see [Binding Declarations Overview](../../../framework/wpf/data/binding-declarations-overview.md). If we apply this example to our basic diagram, the resulting figure looks like the following. This figure describes a binding because the Background property supports binding by default. -![Diagram that shows the data binding Background property.](./media/data-binding-overview/data-binding-button-background-example.png) +:::image type="content" source="./media/index/data-binding-button-background-example.png" alt-text="Diagram that shows the data binding Background property."::: You may wonder why this binding works even though the *ColorName* property is of type string while the property is of type . This binding uses default type conversion, which is discussed in the [Data conversion](#data-conversion) section. @@ -145,7 +144,7 @@ Notice that in the previous example, the binding source is specified by setting There are several ways to specify the binding source object. Using the property on a parent element is useful when you are binding multiple properties to the same source. However, sometimes it may be more appropriate to specify the binding source on individual binding declarations. For the previous example, instead of using the property, you can specify the binding source by setting the property directly on the binding declaration of the button, as in the following example. -[!code-xaml[BindNonTextPropertyCompactBinding](./snippets/data-binding-overview/csharp/AutoConvertPropertyToColor.xaml#BindAutoConvertColorCompactBinding)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/AutoConvertPropertyToColor.xaml" id="BindAutoConvertColorCompactBinding"::: Other than setting the property on an element directly, inheriting the value from an ancestor (such as the button in the first example), and explicitly specifying the binding source by setting the property on the binding (such as the button the last example), you can also use the property or the property to specify the binding source. The property is useful when you are binding to other elements in your app, such as when you are using a slider to adjust the width of a button. The property is useful when the binding is specified in a or a . For more information, see [How to: Specify the binding source](../../../framework/wpf/data/how-to-specify-the-binding-source.md). @@ -157,7 +156,7 @@ For more information, see the and to the value to use is one of the four necessary components of a binding, in the scenarios that you want to bind to an entire object, the value to use would be the same as the binding source object. In those cases, it is applicable to not specify a . Consider the following example. -[!code-xaml[EmptyBinding](./snippets/data-binding-overview/csharp/EmptyBinding.xaml#EmptyBinding)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/EmptyBinding.xaml" id="EmptyBinding"::: The above example uses the empty binding syntax: {Binding}. In this case, the inherits the DataContext from a parent DockPanel element (not shown in this example). When the path is not specified, the default is to bind to the entire object. In other words, in this example, the path has been left out because we are binding the property to the entire object. (See the [Binding to collections](#binding-to-collections) section for an in-depth discussion.) @@ -171,8 +170,8 @@ Before getting into other features and usages of data binding, it is useful to i Consider the following example, where `myDataObject` is an instance of the `MyData` class, `myBinding` is the source object, and `MyData` is a defined class that contains a string property named `ColorName`. This example binds the text content of `myText`, an instance of , to `ColorName`. -[!code-csharp[CodeOnlyBinding](./snippets/data-binding-overview/csharp/ManualBinding.cs#CodeOnlyBinding)] -[!code-vb[CodeOnlyBinding](./snippets/data-binding-overview/vb/ManualBinding.vb#CodeOnlyBinding)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/ManualBinding.cs" id="CodeOnlyBinding"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/ManualBinding.vb" id="CodeOnlyBinding"::: You can use the same *myBinding* object to create other bindings. For example, you can use the *myBinding* object to bind the text content of a check box to *ColorName*. In that scenario, there will be two instances of sharing the *myBinding* object. @@ -184,22 +183,22 @@ A object is returned by calling property is bound to a string property with the value "Red". This string value works because a type converter is present on the type to convert the string value to a . +In the [Create a binding](#create-a-binding) section, the button is red because its property is bound to a string property with the value "Red". This string value works because a type converter is present on the type to convert the string value to a . -Adding this information to the figure in the [Creating a Binding](#creating-a-binding) section looks like this. +Adding this information to the figure in the [Create a binding](#create-a-binding) section looks like this. -![Diagram that shows the data binding Default property.](./media/data-binding-overview/data-binding-button-default-conversion.png) +:::image type="content" source="./media/index/data-binding-button-default-conversion.png" alt-text="Diagram that shows the data binding Default property."::: However, what if instead of having a property of type string your binding source object has a *Color* property of type ? In that case, in order for the binding to work you would need to first turn the *Color* property value into something that the property accepts. You would need to create a custom converter by implementing the interface, as in the following example. -[!code-csharp[CodeOnlyBinding](./snippets/data-binding-overview/csharp/ColorBrushConverter.cs#ColorBrushConverter)] -[!code-vb[CodeOnlyBinding](./snippets/data-binding-overview/vb/ColorBrushConverter.vb#ColorBrushConverter)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/ColorBrushConverter.cs" id="ColorBrushConverter"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/ColorBrushConverter.vb" id="ColorBrushConverter"::: See for more information. Now the custom converter is used instead of default conversion, and our diagram looks like this. -![Diagram that shows the data binding custom converter.](./media/data-binding-overview/data-binding-converter-color-example.png) +:::image type="content" source="./media/index/data-binding-converter-color-example.png" alt-text="Diagram that shows the data binding custom converter."::: To reiterate, default conversions may be available because of type converters that are present in the type being bound to. This behavior will depend on which type converters are available in the target. If in doubt, create your own converter. @@ -219,7 +218,7 @@ A binding source object can be treated either as a single object whose propertie Fortunately, our basic diagram still applies. If you are binding an to a collection, the diagram looks like this. -![Diagram that shows the data binding ItemsControl object.](./media/data-binding-overview/data-binding-itemscontrol.png) +:::image type="content" source="./media/index/data-binding-itemscontrol.png" alt-text="Diagram that shows the data binding ItemsControl object."::: As shown in this diagram, to bind an to a collection object, property is the property to use. You can think of `ItemsSource` as the content of the . The binding is because the `ItemsSource` property supports `OneWay` binding by default. @@ -245,11 +244,11 @@ Because views do not change the underlying source collections, each source colle One way to create and use a view is to instantiate the view object directly and then use it as the binding source. For example, consider the [Data binding demo][data-binding-demo] app shown in the [What is data binding](#what-is-data-binding) section. The app is implemented such that the binds to a view over the data collection instead of the data collection directly. The following example is extracted from the [Data binding demo][data-binding-demo] app. The class is the XAML proxy of a class that inherits from . In this particular example, the of the view is bound to the *AuctionItems* collection (of type ) of the current app object. -[!code-xaml[CollectionView](./snippets/data-binding-overview/csharp/CollectionView.xaml#CollectionView)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/CollectionView.xaml" id="CollectionView"::: The resource *listingDataView* then serves as the binding source for elements in the app, such as the . -[!code-xaml[ListBoxCollectionView](./snippets/data-binding-overview/csharp/CollectionView.xaml#ListBoxCollectionView)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/CollectionView.xaml" id="ListBoxCollectionView"::: To create another view for the same collection, you can create another instance and give it a different `x:Key` name. @@ -277,20 +276,20 @@ As mentioned before, views can apply a sort order to a collection. As it exists The following example shows the sorting logic of the "Sort by category and date" of the app UI in the [What is data binding](#what-is-data-binding) section. -[!code-csharp[AddSortChecked](./snippets/data-binding-overview/csharp/CollectionView.xaml.cs#AddSortChecked)] -[!code-vb[AddSortChecked](./snippets/data-binding-overview/vb/CollectionView.xaml.vb#AddSortChecked)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/CollectionView.xaml.cs" id="AddSortChecked"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/CollectionView.xaml.vb" id="AddSortChecked"::: #### Filtering Views can also apply a filter to a collection, so that the view shows only a certain subset of the full collection. You might filter on a condition in the data. For instance, as is done by the app in the [What is data binding](#what-is-data-binding) section, the "Show only bargains" contains logic to filter out items that cost $25 or more. The following code is executed to set *ShowOnlyBargainsFilter* as the event handler when that is selected. -[!code-csharp[ListingViewFilter](./snippets/data-binding-overview/csharp/CollectionView.xaml.cs#ListingViewFilter)] -[!code-vb[ListingViewFilter](./snippets/data-binding-overview/vb/CollectionView.xaml.vb#ListingViewFilter)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/CollectionView.xaml.cs" id="ListingViewFilter"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/CollectionView.xaml.vb" id="ListingViewFilter"::: The *ShowOnlyBargainsFilter* event handler has the following implementation. -[!code-csharp[FilterEvent](./snippets/data-binding-overview/csharp/CollectionView.xaml.cs#FilterEvent)] -[!code-vb[FilterEvent](./snippets/data-binding-overview/vb/CollectionView.xaml.vb#FilterEvent)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/CollectionView.xaml.cs" id="FilterEvent"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/CollectionView.xaml.vb" id="FilterEvent"::: If you are using one of the classes directly instead of , you would use the property to specify a callback. For an example, see [Filter Data in a View](../../../framework/wpf/data/how-to-filter-data-in-a-view.md). @@ -300,8 +299,8 @@ Except for the internal class that views an . -[!code-csharp[ListingGroupCheck](./snippets/data-binding-overview/csharp/CollectionView.xaml.cs#ListingGroupCheck)] -[!code-vb[ListingGroupCheck](./snippets/data-binding-overview/vb/CollectionView.xaml.vb#ListingGroupCheck)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/CollectionView.xaml.cs" id="ListingGroupCheck"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/CollectionView.xaml.vb" id="ListingGroupCheck"::: For another grouping example, see [Group Items in a ListView That Implements a GridView](../../../framework/wpf/controls/how-to-group-items-in-a-listview-that-implements-a-gridview.md). @@ -331,7 +330,7 @@ The notion of a current item is useful not only for navigation of items in a col You can implement the master-detail scenario simply by having two or more controls bound to the same view. The following example from the [Data binding demo][data-binding-demo] shows the markup of the and the you see on the app UI in the [What is data binding](#what-is-data-binding) section. -[!code-xaml[ListBoxContentControl](./snippets/data-binding-overview/csharp/CollectionView.xaml#ListBoxContentControl)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/CollectionView.xaml" id="ListBoxContentControl"::: Notice that both of the controls are bound to the same source, the *listingDataView* static resource (see the definition of this resource in the [How to create a view section](#how-to-create-a-view)). This binding works because when a singleton object (the in this case) is bound to a collection view, it automatically binds to the of the view. The objects automatically synchronize currency and selection. If your list control is not bound to a object as in this example, then you would need to set its property to `true` for this to work. @@ -343,13 +342,13 @@ You may have noticed that the above example uses a template. In fact, the data w Without the use of data templates, our app UI in the [What is data binding](#what-is-data-binding) section would look like the following. -![Data Binding Demo without Data Templates](./media/data-binding-overview/demo-no-template.png) +:::image type="content" source="./media/index/demo-no-template.png" alt-text="Data Binding Demo without Data Templates"::: As shown in the example in the previous section, both the control and the are bound to the entire collection object (or more specifically, the view over the collection object) of *AuctionItem*s. Without specific instructions of how to display the data collection, the displays the string representation of each object in the underlying collection, and the displays the string representation of the object it is bound to. To solve that problem, the app defines . As shown in the example in the previous section, the explicitly uses the *detailsProductListingTemplate* data template. The control implicitly uses the following data template when displaying the *AuctionItem* objects in the collection. -[!code-xaml[AuctionItemDataTemplate](./snippets/data-binding-overview/csharp/CollectionView.xaml#AuctionItemDataTemplate)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/CollectionView.xaml" id="AuctionItemDataTemplate"::: With the use of those two DataTemplates, the resulting UI is the one shown in the [What is data binding](#what-is-data-binding) section. As you can see from that screenshot, in addition to letting you place data in your controls, DataTemplates allow you to define compelling visuals for your data. For example, s are used in the above so that *AuctionItem*s with *SpecialFeatures* value of *HighLight* would be displayed with an orange border and a star. @@ -363,7 +362,7 @@ Most app that take user input need to have validation logic to ensure that the u The WPF data binding model allows you to associate with your object. For example, the following example binds a to a property named `StartPrice` and adds a object to the property. -[!code-xaml[TextboxStartPrice](./snippets/data-binding-overview/csharp/DataValidation.xaml#TextboxStartPrice)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/DataValidation.xaml" id="TextboxStartPrice"::: A object checks whether the value of a property is valid. WPF has two types of built-in objects: @@ -373,12 +372,12 @@ A object checks whether the value You can also create your own validation rule by deriving from the class and implementing the method. The following example shows the rule used by the *Add Product Listing* "Start Date" from the [What is data binding](#what-is-data-binding) section. -[!code-csharp[FutureDateRule](./snippets/data-binding-overview/csharp/FutureDateRule.cs#FutureDateRule)] -[!code-vb[FutureDateRule](./snippets/data-binding-overview/vb/FutureDateRule.vb#FutureDateRule)] +:::code language="csharp" source="./snippets/data-binding-overview/csharp/FutureDateRule.cs" id="FutureDateRule"::: +:::code language="vb" source="./snippets/data-binding-overview/vb/FutureDateRule.vb" id="FutureDateRule"::: The *StartDateEntryForm* uses this *FutureDateRule*, as shown in the following example. -[!code-xaml[TextboxStartDate](./snippets/data-binding-overview/csharp/DataValidation.xaml#TextboxStartDate)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/DataValidation.xaml" id="TextboxStartDate"::: Because the value is , the binding engine updates the source value on every keystroke, which means it also checks every rule in the collection on every keystroke. We discuss this further in the Validation Process section. @@ -386,21 +385,21 @@ Because the value is < If the user enters an invalid value, you may want to provide some feedback about the error on the app UI. One way to provide such feedback is to set the attached property to a custom . As shown in the previous subsection, the *StartDateEntryForm* uses an called *validationTemplate*. The following example shows the definition of *validationTemplate*. -[!code-xaml[ControlTemplate](./snippets/data-binding-overview/csharp/DataValidation.xaml#ControlTemplate)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/DataValidation.xaml" id="ControlTemplate"::: The element specifies where the control being adorned should be placed. In addition, you may also use a to display the error message. Both the *StartDateEntryForm* and the *StartPriceEntryForm*es use the style *textStyleTextBox*, which creates a that displays the error message. The following example shows the definition of *textStyleTextBox*. The attached property is `true` when one or more of the bindings on the properties of the bound element are in error. -[!code-xaml[TextBoxStyle](./snippets/data-binding-overview/csharp/DataValidation.xaml#TextBoxStyle)] +:::code language="xaml" source="./snippets/data-binding-overview/csharp/DataValidation.xaml" id="TextBoxStyle"::: With the custom and the , the *StartDateEntryForm* looks like the following when there is a validation error. -![Data binding validation error](./media/data-binding-overview/demo-validation-date.png "DataBindingDemo_Validation") +:::image type="content" source="./media/index/demo-validation-date.png" alt-text="Data binding validation error for date"::: If your has associated validation rules but you do not specify an on the bound control, a default will be used to notify users when there is a validation error. The default is a control template that defines a red border in the adorner layer. With the default and the , the UI of the *StartPriceEntryForm* looks like the following when there is a validation error. -![Data binding validation error default](./media/data-binding-overview/demo-validation-price.png "DataBindingDemo_ValidationDefault") +:::image type="content" source="./media/index/demo-validation-price.png" alt-text="Data binding validation error for price"::: For an example of how to provide logic to validate all controls in a dialog box, see the Custom Dialog Boxes section in the [Dialog boxes overview](../../../framework/wpf/app-development/dialog-boxes-overview.md). @@ -436,11 +435,7 @@ You can set the attached property -- [Bind to the results of a LINQ query](../../../framework/wpf/data/how-to-bind-to-the-results-of-a-linq-query.md) -- [Data binding](../../../framework/wpf/advanced/optimizing-performance-data-binding.md) - [Data binding demo][data-binding-demo] -- [How-to articles](../../../framework/wpf/data/data-binding-how-to-topics.md) -- [Bind to an ADO.NET data source](../../../framework/wpf/data/how-to-bind-to-an-ado-net-data-source.md) +- [data-binding-demo]: https://github.com/microsoft/WPF-Samples/tree/master/Sample%20Applications/DataBindingDemo "data binding demo app" diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/basic-data-binding-diagram.png b/dotnet-desktop-guide/net/wpf/data/media/index/basic-data-binding-diagram.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/basic-data-binding-diagram.png rename to dotnet-desktop-guide/net/wpf/data/media/index/basic-data-binding-diagram.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-button-background-example.png b/dotnet-desktop-guide/net/wpf/data/media/index/data-binding-button-background-example.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-button-background-example.png rename to dotnet-desktop-guide/net/wpf/data/media/index/data-binding-button-background-example.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-button-default-conversion.png b/dotnet-desktop-guide/net/wpf/data/media/index/data-binding-button-default-conversion.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-button-default-conversion.png rename to dotnet-desktop-guide/net/wpf/data/media/index/data-binding-button-default-conversion.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-converter-color-example.png b/dotnet-desktop-guide/net/wpf/data/media/index/data-binding-converter-color-example.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-converter-color-example.png rename to dotnet-desktop-guide/net/wpf/data/media/index/data-binding-converter-color-example.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-itemscontrol.png b/dotnet-desktop-guide/net/wpf/data/media/index/data-binding-itemscontrol.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-itemscontrol.png rename to dotnet-desktop-guide/net/wpf/data/media/index/data-binding-itemscontrol.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-updatesource-trigger.png b/dotnet-desktop-guide/net/wpf/data/media/index/data-binding-updatesource-trigger.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/data-binding-updatesource-trigger.png rename to dotnet-desktop-guide/net/wpf/data/media/index/data-binding-updatesource-trigger.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/databinding-dataflow.png b/dotnet-desktop-guide/net/wpf/data/media/index/databinding-dataflow.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/databinding-dataflow.png rename to dotnet-desktop-guide/net/wpf/data/media/index/databinding-dataflow.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-addproductlisting.png b/dotnet-desktop-guide/net/wpf/data/media/index/demo-addproductlisting.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-addproductlisting.png rename to dotnet-desktop-guide/net/wpf/data/media/index/demo-addproductlisting.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-no-template.png b/dotnet-desktop-guide/net/wpf/data/media/index/demo-no-template.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-no-template.png rename to dotnet-desktop-guide/net/wpf/data/media/index/demo-no-template.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-validation-date.png b/dotnet-desktop-guide/net/wpf/data/media/index/demo-validation-date.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-validation-date.png rename to dotnet-desktop-guide/net/wpf/data/media/index/demo-validation-date.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-validation-price.png b/dotnet-desktop-guide/net/wpf/data/media/index/demo-validation-price.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo-validation-price.png rename to dotnet-desktop-guide/net/wpf/data/media/index/demo-validation-price.png diff --git a/dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo.png b/dotnet-desktop-guide/net/wpf/data/media/index/demo.png similarity index 100% rename from dotnet-desktop-guide/net/wpf/data/media/data-binding-overview/demo.png rename to dotnet-desktop-guide/net/wpf/data/media/index/demo.png diff --git a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml index 265886b..a35135e 100644 --- a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml +++ b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/DataValidation.xaml @@ -24,7 +24,7 @@ + Value="{Binding (Validation.Errors).CurrentItem.ErrorContent, RelativeSource={RelativeSource Self}}" /> diff --git a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj index 248170e..4139a3b 100644 --- a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj +++ b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/csharp/bindings.csproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows true diff --git a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj index 6eab484..7c8a6e2 100644 --- a/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj +++ b/dotnet-desktop-guide/net/wpf/data/snippets/data-binding-overview/vb/bindings.vbproj @@ -1,8 +1,8 @@ - + WinExe - netcoreapp3.1 + net5.0-windows bindings true diff --git a/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md b/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md index 6097fa0..0f37f99 100644 --- a/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md +++ b/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md @@ -29,7 +29,7 @@ Here's a preview of the app you'll build while following this tutorial: ## Prerequisites -- [Visual Studio 2019 version 16.8.4 or later versions](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+wpf) +- [Visual Studio 2019 version 16.9 or later versions](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+wpf) - Select the [Visual Studio Desktop workload](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-workloads) - Select the [.NET 5 individual component](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-individual-components) diff --git a/dotnet-desktop-guide/net/wpf/index.yml b/dotnet-desktop-guide/net/wpf/index.yml index b2ca872..34d810f 100644 --- a/dotnet-desktop-guide/net/wpf/index.yml +++ b/dotnet-desktop-guide/net/wpf/index.yml @@ -1,15 +1,16 @@ ### YamlMime:Landing -title: Windows Presentation Foundation (WPF) documentation -summary: Learn about using Windows Presentation Foundation, an open-source, graphical user interface for Windows, on .NET Core. +title: Windows Presentation Foundation documentation +summary: Learn about using Windows Presentation Foundation (WPF), an open-source, graphical user interface for Windows, on .NET 5. metadata: - title: Windows Presentation Foundation (WPF) for .NET Core documentation - description: Learn about using Windows Presentation Foundation, an open-source, graphical user interface for Windows, on .NET Core. + title: Windows Presentation Foundation for .NET 5 documentation + description: Learn about using Windows Presentation Foundation (WPF), an open-source, graphical user interface for Windows, on .NET 5. ms.topic: landing-page - ms.date: 03/25/2020 + ms.date: 04/15/2021 -# linkListType: architecture | concept | deploy | download | get-started | how-to-guide | learn | overview | quickstart | reference | sample | tutorial | video | whats-new +# linkListType: architecture | concept | deploy | download | get-started | how-to-guide | learn | overview +# quickstart | reference | sample | tutorial | video | whats-new landingContent: @@ -18,48 +19,63 @@ landingContent: linkLists: - linkListType: overview links: - - text: Windows Presentation Foundation overview + - text: WPF overview url: overview/index.md - - text: XAML in Windows Presentation Foundation - url: fundamentals/xaml.md - - # Card - - title: Get started with WPF - linkLists: - - linkListType: concept + - linkListType: whats-new links: - - text: Differences from WPF on .NET Framework + - text: Differences from .NET Framework url: migration/differences-from-net-framework.md - - text: Migrate from Framework to Core - url: migration/convert-project-from-net-framework.md - linkListType: tutorial links: - - text: Create a WPF application - url: /visualstudio/get-started/csharp/tutorial-wpf?bc=%252fdotnet%252fbreadcrumb%252ftoc.json&toc=%252fdotnet%252fdesktop-wpf%252ftoc.json + - text: Create a new app + url: get-started/create-app-visual-studio.md + - text: Migrate from .NET Framework + url: /dotnet/core/porting/upgrade-assistant-wpf-framework + - linkListType: download + links: + - text: Visual Studio 2019 version 16.9 + url: https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+wpf - # Card - - title: Fundamentals - XAML - linkLists: - - linkListType: concept - links: - - text: Define XAML resources - url: fundamentals/xaml-resources-define.md - - text: Styles and templates - url: fundamentals/styles-templates-overview.md - - linkListType: how-to-guide - links: - - text: Create and apply a style - url: fundamentals/styles-templates-create-apply-style.md - - text: Create and apply a template - url: themes/how-to-create-apply-template.md - - linkListType: reference - links: - - text: XAML language reference - url: ../../xaml-services/index.md - - - title: Fundamentals - Data + - title: WPF windows linkLists: - linkListType: overview links: - - text: Data binding - url: data/data-binding-overview.md + - text: About WPF windows + url: windows/index.md + - text: About dialog boxes + url: windows/dialog-boxes-overview.md + - linkListType: how-to-guide + links: + - text: Open a message box + url: windows/how-to-open-message-box.md + - text: Open a common dialog box + url: windows/how-to-open-common-system-dialog-box.md + - text: Get or set the main app window + url: windows/how-to-open-common-system-dialog-box.md + + - title: Control styles and templates + linkLists: + - linkListType: overview + links: + - text: About styles and templates + url: controls/styles-templates-overview.md + - linkListType: how-to-guide + links: + - text: Create a style + url: controls/how-to-create-apply-style.md + - text: Create a template + url: controls/how-to-create-apply-template.md + + - title: Data binding + linkLists: + - linkListType: overview + links: + - text: About data binding + url: data/index.md + + - title: XAML in WPF + linkLists: + - linkListType: overview + links: + - text: About XAML + url: xaml/index.md diff --git a/dotnet-desktop-guide/net/wpf/migration/convert-project-from-net-framework.md b/dotnet-desktop-guide/net/wpf/migration/convert-project-from-net-framework.md index b61f091..12a3e52 100644 --- a/dotnet-desktop-guide/net/wpf/migration/convert-project-from-net-framework.md +++ b/dotnet-desktop-guide/net/wpf/migration/convert-project-from-net-framework.md @@ -11,6 +11,9 @@ ms.topic: how-to This article covers the steps necessary to migrate a Windows Presentation Foundation (WPF) app from .NET Framework to .NET Core 3.0. If you don't have a WPF app on hand to port, but would like to try out the process, you can use the **Bean Trader** sample app available on [GitHub](https://github.com/dotnet/windows-desktop/tree/main/Samples/BeanTrader). The original app (targeting .NET Framework 4.7.2) is available in the NetFx\BeanTraderClient folder. First we'll explain the steps necessary to port apps in general, and then we'll walk through the specific changes that apply to the **Bean Trader** sample. +> [!TIP] +> Try the [.NET Upgrade Assistant](/dotnet/core/porting/upgrade-assistant-wpf-framework) to help migrate your own project. + [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] To migrate to .NET Core, you must first: diff --git a/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md b/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md index a49ae85..2c96054 100644 --- a/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md +++ b/dotnet-desktop-guide/net/wpf/migration/differences-from-net-framework.md @@ -2,29 +2,29 @@ title: Differences between .NET Framework and .NET description: Describes the differences between the .NET Framework implementation of Windows Presentation Foundation (WPF) and .NET WPF. When migrating your app, you should consider these incompatibilities. author: adegeo -ms.date: 09/21/2019 +ms.date: 01/29/2021 ms.author: adegeo ms.topic: conceptual --- # Differences in WPF .NET -This article describes the differences between Windows Presentation Foundation (WPF) on .NET Core and .NET Framework. WPF for .NET Core is an [open-source framework](https://github.com/dotnet/wpf) forked from the original WPF for .NET Framework source code. +This article describes the differences between Windows Presentation Foundation (WPF) on .NET 5 (or .NET Core 3.1) and .NET Framework. WPF for .NET 5 is an [open-source framework](https://github.com/dotnet/wpf) forked from the original WPF for .NET Framework source code. -There are a few features of .NET Framework that .NET Core doesn't support. For more information on unsupported technologies, see [.NET Framework technologies unavailable on .NET Core](/dotnet/core/porting/net-framework-tech-unavailable). +There are a few features of .NET Framework that .NET 5 doesn't support. For more information on unsupported technologies, see [.NET Framework technologies unavailable on .NET 5 and .NET Core](/dotnet/core/porting/net-framework-tech-unavailable). [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] ## SDK-style projects -.NET Core uses SDK-style project files. These project files are different from the traditional .NET Framework project files managed by Visual Studio. To migrate your .NET Framework WPF apps to .NET Core, you must convert your projects. For more information, see [Migrate WPF apps to .NET Core 3.0](convert-project-from-net-framework.md). +.NET 5 uses SDK-style project files. These project files are different from the traditional .NET Framework project files managed by Visual Studio. To migrate your .NET Framework WPF apps to .NET 5, you must convert your projects. For more information, see [Migrate WPF apps to .NET 5](convert-project-from-net-framework.md). ## NuGet package references If your .NET Framework app lists its NuGet dependencies in a *packages.config* file, migrate to the [``](/nuget/consume-packages/package-references-in-project-files) format: -1. In Visual Studio, open the **Solution Explorer** pane. -1. In your WPF project, right-click **packages.config** > **Migrate packages.config to PackageReference**. +01. In Visual Studio, open the **Solution Explorer** pane. +01. In your WPF project, right-click **packages.config** > **Migrate packages.config to PackageReference**. ![Upgrading to PackageReference](media/differences-from-net-framework/package-reference-migration.png) @@ -34,7 +34,7 @@ When your project uses ``, packages aren't stored locally in a ## Code Access Security -Code Access Security (CAS) is not supported by .NET Core or WPF for .NET Core. All CAS-related functionality is treated under the assumption of full-trust. WPF for .NET Core removes CAS-related code. The public API surface of these types still exists to ensure that calls into these types succeed. +Code Access Security (CAS) is not supported by .NET 5. All CAS-related functionality is treated under the assumption of full-trust. WPF for .NET 5 removes CAS-related code. The public API surface of these types still exists to ensure that calls into these types succeed. Publicly defined CAS-related types were moved out of the WPF assemblies and into the Core .NET library assemblies. The WPF assemblies have type-forwarding set to the new location of the moved types. @@ -52,4 +52,4 @@ Publicly defined CAS-related types were moved out of the WPF assemblies and into ## Next steps -- [Learn how to port a .NET Framework WPF app to .NET Core.](convert-project-from-net-framework.md) +- [Migrate WPF apps to .NET 5](convert-project-from-net-framework.md) diff --git a/dotnet-desktop-guide/net/wpf/overview/index.md b/dotnet-desktop-guide/net/wpf/overview/index.md index b1b0672..6a15db5 100644 --- a/dotnet-desktop-guide/net/wpf/overview/index.md +++ b/dotnet-desktop-guide/net/wpf/overview/index.md @@ -1,145 +1,492 @@ --- title: What is Windows Presentation Foundation -description: This article gives an overview about what Windows Presentation Foundation (WPF) is as it relates to .NET and what features are provided. -ms.date: 07/18/2019 +description: This article gives an overview of WPF with .NET Core and .NET 5. +ms.date: 01/14/2021 ms.topic: overview +dev_langs: + - "csharp" + - "vb" #Customer intent: As a developer, I want to understand the components of WPF so that I can understand the overall picture of WPF. --- -# What is Windows Presentation Foundation (WPF .NET) +# Desktop Guide (WPF .NET) -Welcome to the Desktop Guide for Windows Presentation Foundation (WPF), a UI framework that creates desktop client applications for Windows. The WPF development platform supports a broad set of application development features, including an application model, controls, graphics, and data binding. WPF uses Extensible Application Markup Language (XAML) to provide a declarative model for application programming. +Welcome to the Desktop Guide for Windows Presentation Foundation (WPF), a UI framework that is resolution-independent and uses a vector-based rendering engine, built to take advantage of modern graphics hardware. WPF provides a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout, 2D and 3D graphics, animation, styles, templates, documents, media, text, and typography. WPF is part of .NET, so you can build applications that incorporate other elements of the .NET API. [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] There are two implementations of WPF: -01. The open-source implementation hosted on [GitHub](https://github.com/dotnet/wpf). This version runs on .NET Core 3.0. The WPF Visual Designer for XAML requires, at a minimum, [Visual Studio 2019 version 16.3](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide). +01. **.NET** version (this guide): -01. The .NET Framework implementation that's supported by Visual Studio 2019 and Visual Studio 2017. + An open-source implementation of WPF hosted on [GitHub](https://github.com/dotnet/wpf), which runs on .NET 5 or higher (including .NET Core 3.1). The XAML designer requires, at a minimum, [Visual Studio 2019 version 16.8](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+wpf). -This Desktop Guide is written for .NET Core 3.0 and WPF. For more information about the existing documentation for WPF with the .NET Framework, see [Framework Windows Presentation Foundation](../../../framework/wpf/index.md). + Even though .NET is a cross-platform technology, WPF isn't and only runs on Windows. -## XAML +01. **.NET Framework 4** version: -XAML is a declarative XML-based language that WPF uses for things such as defining resources or UI elements. Elements defined in XAML represent the instantiation of objects from an assembly. XAML is unlike most other markup languages, which are interpreted at runtime without a direct tie to a backing type system. + The .NET Framework implementation of WPF that's supported by Visual Studio 2019 and Visual Studio 2017. -The following example shows how you would create a button as part of a UI. This example is intended to give you an idea of how XAML represents an object, where `Button` is the type and `Content` is a property. + .NET Framework 4 is a Windows-only version of .NET and is considered a Windows Operating System component. This version of WPF is distributed with .NET Framework. For more information about the .NET Framework version of WPF, see [Introduction to WPF for .NET Framework](../../../framework/wpf/introduction-to-wpf.md?view=netframeworkdesktop-4.8&preserve-view=true). + +This overview is intended for newcomers and covers the key capabilities and concepts of WPF. To learn how to create a WPF app, see [Tutorial: Create a new WPF app](../get-started/create-app-visual-studio.md). + +## Why migrate from .NET Framework + +WPF for .NET 5.0 provides new features and enhancements over .NET Framework. To learn how to migrate an app, see [How to migrate a WPF desktop app to .NET 5](../migration/convert-project-from-net-framework.md). + +## Program with WPF + +WPF exists as a subset of .NET types that are, mostly located in the namespace. If you have previously built applications with .NET with frameworks like ASP.NET and Windows Forms, the fundamental WPF programming experience should be familiar, you: + +- Instantiate classes +- Set properties +- Call methods +- Handle events + +WPF includes more programming constructs that enhance properties and events: [dependency properties](../../../framework/wpf/advanced/dependency-properties-overview.md) and [routed events](../../../framework/wpf/advanced/routed-events-overview.md). + +## Markup and code-behind + +WPF lets you develop an application using both *markup* and *code-behind*, an experience with which ASP.NET developers should be familiar. You generally use XAML markup to implement the appearance of an application while using managed programming languages (code-behind) to implement its behavior. This separation of appearance and behavior has the following benefits: + +- Development and maintenance costs are reduced because appearance-specific markup isn't tightly coupled with behavior-specific code. + +- Development is more efficient because designers can implement an application's appearance simultaneously with developers who are implementing the application's behavior. + +- [Globalization and localization](../../../framework/wpf/advanced/wpf-globalization-and-localization-overview.md) for WPF applications is simplified. + +### Markup + +XAML is an XML-based markup language that implements an application's appearance declaratively. You typically use it to define windows, dialog boxes, pages, and user controls, and to fill them with controls, shapes, and graphics. + +The following example uses XAML to implement the appearance of a window that contains a single button: ```xaml - - + + ``` - +Specifically, this XAML defines a window and a button by using the `Window` and `Button` elements. Each element is configured with attributes, such as the `Window` element's `Title` attribute to specify the window's title-bar text. At run time, WPF converts the elements and attributes that are defined in markup to instances of WPF classes. For example, the `Window` element is converted to an instance of the class whose property is the value of the `Title` attribute. -### XAML extensions +The following figure shows the user interface (UI) that is defined by the XAML in the previous example: -XAML provides syntax for markup extensions. Markup extensions can be used to provide values for properties in attribute form, property-element form, or both. +:::image type="content" source="media/index/markup-window-button.png" alt-text="A window that contains a button"::: -For example, the previous XAML code defined a button with the visible content set to the literal string `"Click Me!"`, but the content can be instead set by a supported markup extension. A markup extension is defined with opening and closing curly braces `{ }`. The type of markup extension is then identified by the string token immediately following the opening curly brace. +Since XAML is XML-based, the UI that you compose with it's assembled in a hierarchy of nested elements that is known as an [element tree](../../../framework/wpf/advanced/trees-in-wpf.md). The element tree provides a logical and intuitive way to create and manage UIs. + +### Code-behind + +The main behavior of an application is to implement the functionality that responds to user interactions. For example clicking a menu or button, and calling business logic and data access logic in response. In WPF, this behavior is implemented in code that is associated with markup. This type of code is known as code-behind. The following example shows the updated markup from the previous example and the code-behind: ```xaml - - + + ``` -WPF provides different markup extensions for XAML such as `{Binding}` for data binding. - -For more information, see [Markup Extensions and WPF XAML](../../../framework/wpf/advanced/markup-extensions-and-wpf-xaml.md). - -## Property system - -WPF provides a set of services that can be used to extend the functionality of a type's [property](/dotnet/standard/base-types/common-type-system#properties). Collectively, these services are referred to as the *WPF property system*. A property that is backed by the WPF property system is known as a dependency property. - -Dependency properties extend property functionality by providing the type that backs a property. The dependency property type is an alternative implementation of the standard pattern of backing the property with a private field. - -### Dependency property - -In WPF, dependency properties are typically exposed as standard .NET [properties](/dotnet/standard/base-types/common-type-system#properties). At a basic level, you could interact with these properties directly and never know that they're implemented as a dependency property. - -The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs. These other inputs might include system properties such as themes and user preferences, or just-in-time property from data binding and animations. - -A dependency property can be implemented to provide validation, default values, and callbacks that monitor changes to other properties. Derived classes can also change some specific characteristics of an existing property by overriding dependency property metadata, rather than creating a new property or overriding an existing property. - -### Dependency object - -Another type that is key to the WPF property system is the . This type defines the base class that can register and own a dependency property. The and methods provide the backing implementation of the dependency property for the dependency object instance. - -The following example shows a dependency object that defines a single dependency property identifier named `ValueProperty`. The dependency property is created with the `Value` .NET property. +The updated markup defines the `xmlns:x` namespace and maps it to the schema that adds support for the code-behind types. The `x:Class` attribute is used to associate a code-behind class to this specific XAML markup. Considering this attribute is declared on the `` element, the code-behind class must inherit from the `Window` class. ```csharp -public class TextField: DependencyObject -{ - public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value", typeof(string), typeof(TextField), new PropertyMetadata("")); +using System.Windows; - public string Value +namespace SDKSample +{ + public partial class AWindow : Window { - get { return (string)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } + public AWindow() + { + // InitializeComponent call is required to merge the UI + // that is defined in markup with this class, including   + // setting properties and registering event handlers + InitializeComponent(); + } + + void button_Click(object sender, RoutedEventArgs e) + { + // Show message box when button is clicked. + MessageBox.Show("Hello, Windows Presentation Foundation!"); + } } } ``` -The dependency property is defined as a static member of a dependency object type, such as `TextField` in example above. The dependency property must be registered with the dependency object. +```vb +Namespace SDKSample -The `Value` property in the example above wraps the dependency property, providing the standard .NET property pattern you're probably used to. + Partial Public Class AWindow + Inherits System.Windows.Window - + Public Sub New() -## Events + ' InitializeComponent call is required to merge the UI + ' that is defined in markup with this class, including   + ' setting properties and registering event handlers + InitializeComponent() -WPF provides an eventing system that is layered on top of the .NET common language runtime (CLR) events you're familiar with. These WPF events are called routed events. + End Sub -A routed event is a CLR event that is backed by an instance of the `RoutedEvent` class and registered with the WPF event system. The `RoutedEvent` instance obtained from event registration is typically retained as a `public static readonly` field member of the class that registers, and thus *owns* the routed event. The connection to the identically named CLR event (which is sometimes termed the *wrapper* event) is accomplished by overriding the `add` and `remove` implementations for the CLR event. The routed event backing and connection mechanism is conceptually similar to how a [dependency property](#dependency-property) is a CLR property that is backed by the `DependencyProperty` class and registered with the WPF property system. + Private Sub button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) -The main advantage of the routed event system is that events are *bubbled up* the control element tree looking for a handler. For example, because WPF has a rich content model, you set an image control as the content of a button control. When the mouse is clicked on the image control, you would expect it to consume the mouse events, and thus break the hit-tests that cause a button to invoke the `Click` event. In a traditional CLR eventing model, you would work around this limitation by attaching the same handler to both the image and the button. But with the routed event system, the mouse events invoked on the image control (such as selecting it) bubble up to the parent button control. + ' Show message box when button is clicked. + MessageBox.Show("Hello, Windows Presentation Foundation!") - + End Sub + + End Class + +End Namespace +``` + +`InitializeComponent` is called from the code-behind class's constructor to merge the UI that is defined in markup with the code-behind class. (`InitializeComponent` is generated for you when your application is built, which is why you don't need to implement it manually.) The combination of `x:Class` and `InitializeComponent` ensure that your implementation is correctly initialized whenever it's created. + +Notice that in the markup the ` + + + + + + + + + +``` + +Because this style targets all controls, the style is automatically applied to all the buttons in the window, as shown in the following figure: + +:::image type="content" source="media/index/styles-buttons.png" alt-text="Two orange buttons"::: + +For more information, see [Styles and templates](../controls/styles-templates-overview.md). + +### Resources + +Controls in an application should share the same appearance, which can include anything from fonts and background colors to control templates, data templates, and styles. You can use WPF's support for user interface resources to encapsulate these resources in a single location for reuse. + +The following example defines a common background color that is shared by a and a : + +```xaml + + + + + + + + + + + + + +``` + +For more information, see [How to define and reference a WPF resource](../systems/xaml-resources-how-to-define-and-reference.md). + +### Custom controls + +Although WPF provides a host of customization support, you may encounter situations where existing WPF controls do not meet the needs of either your application or its users. This can occur when: + +- The user interface that you require cannot be created by customizing the look and feel of existing WPF implementations. +- The behavior that you require isn't supported (or not easily supported) by existing WPF implementations. + +At this point, however, you can take advantage of one of three WPF models to create a new control. Each model targets a specific scenario and requires your custom control to derive from a particular WPF base class. The three models are listed here: + +- **User Control Model**\ +A custom control derives from and is composed of one or more other controls. + +- **Control Model** +A custom control derives from and is used to build implementations that separate their behavior from their appearance using templates, much like most WPF controls. Deriving from allows you more freedom for creating a custom user interface than user controls, but it may require more effort. + +- **Framework Element Model**.\ +A custom control derives from when its appearance is defined by custom rendering logic (not templates). + +For more information on custom controls, see [Control authoring overview](../../../framework/wpf/controls/control-authoring-overview.md). + +## See also + +- [Tutorial: Create a new WPF app](../get-started/create-app-visual-studio.md) +- [Migrate a WPF app to .NET Core](../migration/convert-project-from-net-framework.md) +- [Overview of WPF windows](../windows/index.md) +- [Data binding overview](../data/index.md) +- [XAML overview](../xaml/index.md) diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/animation-cube.gif b/dotnet-desktop-guide/net/wpf/overview/media/index/animation-cube.gif new file mode 100644 index 0000000..f57c34f Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/animation-cube.gif differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/code.zip b/dotnet-desktop-guide/net/wpf/overview/media/index/code.zip new file mode 100644 index 0000000..a97d40e Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/code.zip differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-applied.png b/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-applied.png new file mode 100644 index 0000000..0a52fe8 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-applied.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-normal.png b/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-normal.png new file mode 100644 index 0000000..ba56289 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/data-template-listbox-normal.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/databinding-basic-diagram.png b/dotnet-desktop-guide/net/wpf/overview/media/index/databinding-basic-diagram.png new file mode 100644 index 0000000..11951cd Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/databinding-basic-diagram.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/dockpanel-page.png b/dotnet-desktop-guide/net/wpf/overview/media/index/dockpanel-page.png new file mode 100644 index 0000000..b3d9fc0 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/dockpanel-page.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-3d.png b/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-3d.png new file mode 100644 index 0000000..613e96b Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-3d.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-brushes.png b/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-brushes.png new file mode 100644 index 0000000..7eb4abb Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/graphics-brushes.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button-clicked.png b/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button-clicked.png new file mode 100644 index 0000000..a500fb9 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button-clicked.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button.png b/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button.png new file mode 100644 index 0000000..b534c96 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/markup-window-button.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/styles-buttons.png b/dotnet-desktop-guide/net/wpf/overview/media/index/styles-buttons.png new file mode 100644 index 0000000..02028dc Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/styles-buttons.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/template-button.png b/dotnet-desktop-guide/net/wpf/overview/media/index/template-button.png new file mode 100644 index 0000000..89f6308 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/template-button.png differ diff --git a/dotnet-desktop-guide/net/wpf/overview/media/index/text.png b/dotnet-desktop-guide/net/wpf/overview/media/index/text.png new file mode 100644 index 0000000..f132b08 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/overview/media/index/text.png differ diff --git a/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/after.png b/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/after.png new file mode 100644 index 0000000..b9d9f91 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/after.png differ diff --git a/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/before.png b/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/before.png new file mode 100644 index 0000000..363f82f Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/systems/media/xaml-resources-how-to-define-and-reference/before.png differ diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml new file mode 100644 index 0000000..9ea450d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml.cs new file mode 100644 index 0000000..32487c0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/App.xaml.cs @@ -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 csharp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml new file mode 100644 index 0000000..977af73 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..598f635 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/MainWindow.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace csharp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + // + private void myButton_Click(object sender, RoutedEventArgs e) + { + Button button = (Button)sender; + button.Background = (Brush)this.FindResource("RainbowBrush"); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/resources.csproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/resources.csproj new file mode 100644 index 0000000..bc339b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/csharp/resources.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net5.0-windows + true + + + + + Code + ResExample - Copy.xaml.cs + + + Code + ResExample.xaml.cs + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml new file mode 100644 index 0000000..73b6071 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml.vb new file mode 100644 index 0000000..f3e8ffd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml new file mode 100644 index 0000000..809ef9a --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..df621b9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/MainWindow.xaml.vb @@ -0,0 +1,8 @@ +Class MainWindow + ' + Private Sub myButton_Click(sender As Object, e As RoutedEventArgs) + Dim buttonControl = DirectCast(sender, Button) + buttonControl.Background = DirectCast(Me.FindResource("RainbowBrush"), Brush) + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/vb.vbproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/vb.vbproj new file mode 100644 index 0000000..76fe06c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-and-code/vb/vb.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + vb + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml new file mode 100644 index 0000000..9ea450d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml.cs new file mode 100644 index 0000000..32487c0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/App.xaml.cs @@ -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 csharp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml new file mode 100644 index 0000000..49a64ac --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..6c9f08b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace csharp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + // + private void Button_Click(object sender, RoutedEventArgs e) + { + // Create colors + Color purple = (Color)ColorConverter.ConvertFromString("#4E1A3D"); + Color white = Colors.White; + Color salmon = Colors.Salmon; + + // Create a new style for a button + var buttonStyle = new Style(typeof(Button)); + + // Set the properties of the style + buttonStyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(purple))); + buttonStyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(white))); + buttonStyle.Setters.Add(new Setter(Control.BorderBrushProperty, new LinearGradientBrush(purple, salmon, 45d))); + buttonStyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(5))); + + // + // Set this style as a resource. Any DynamicResource tied to this key will be updated. + this.Resources["buttonStyle1"] = buttonStyle; + // + + // + // Set this style directly to a button + ((Button)sender).Style = buttonStyle; + // + } + // + + private void ButtonFind_Click(object sender, RoutedEventArgs e) + { + Button myButton = (Button)sender; + + // + myButton.Style = myButton.TryFindResource("buttonStyle1") as Style; + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml new file mode 100644 index 0000000..161aa9d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + Title + Label + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml.cs new file mode 100644 index 0000000..2a18ff7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace resources +{ + /// + /// Interaction logic for ResExample.xaml + /// + public partial class ResExample : Window + { + public ResExample() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/resources.csproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/resources.csproj new file mode 100644 index 0000000..bc339b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/csharp/resources.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net5.0-windows + true + + + + + Code + ResExample - Copy.xaml.cs + + + Code + ResExample.xaml.cs + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml new file mode 100644 index 0000000..73b6071 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml.vb new file mode 100644 index 0000000..f3e8ffd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml new file mode 100644 index 0000000..407bd64 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..76302f2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb @@ -0,0 +1,40 @@ +Class MainWindow + ' + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + + 'Create colors + Dim purple = DirectCast(ColorConverter.ConvertFromString("#4E1A3D"), Color) + Dim white = Colors.White + Dim salmon = Colors.Salmon + + 'Create a new style for a button + Dim buttonStyle As New Style() + + 'Set the properties of the style + buttonStyle.Setters.Add(New Setter(Control.BackgroundProperty, New SolidColorBrush(purple))) + buttonStyle.Setters.Add(New Setter(Control.ForegroundProperty, New SolidColorBrush(white))) + buttonStyle.Setters.Add(New Setter(Control.BorderBrushProperty, New LinearGradientBrush(purple, salmon, 45D))) + buttonStyle.Setters.Add(New Setter(Control.BorderThicknessProperty, New Thickness(5))) + + ' + 'Set this style as a resource. Any DynamicResource looking for this key will be updated. + Me.Resources("buttonStyle1") = buttonStyle + ' + + ' + 'Set this style directly to a button + DirectCast(sender, Button).Style = buttonStyle + ' + + End Sub + ' + + Private Sub ButtonFind_Click(sender As Object, e As RoutedEventArgs) + Dim myButton As Button = DirectCast(sender, Button) + + ' + myButton.Style = myButton.TryFindResource("buttonStyle1") + ' + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/styles.vbproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/styles.vbproj new file mode 100644 index 0000000..76fe06c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-define-and-reference/vb/styles.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + vb + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml new file mode 100644 index 0000000..461a7bb --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml.cs new file mode 100644 index 0000000..c9b6cbd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/App.xaml.cs @@ -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 SampleApplication +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml new file mode 100644 index 0000000..bb5665e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..97150d9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SampleApplication +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + // + private void Button_Click(object sender, RoutedEventArgs e) + { + // Create colors + Color purple = (Color)ColorConverter.ConvertFromString("#4E1A3D"); + Color white = Colors.White; + Color salmon = Colors.Salmon; + + // Create a new style for a button + var buttonStyle = new Style(typeof(Button)); + + // Set the properties of the style + buttonStyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(purple))); + buttonStyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(white))); + buttonStyle.Setters.Add(new Setter(Control.BorderBrushProperty, new LinearGradientBrush(purple, salmon, 45d))); + buttonStyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(5))); + + // + // Set this style as a resource. Any DynamicResource tied to this key will be updated. + this.Resources["buttonStyle1"] = buttonStyle; + // + + // + // Set this style directly to a button + ((Button)sender).Style = buttonStyle; + // + } + // + + private void ButtonFind_Click(object sender, RoutedEventArgs e) + { + Button myButton = (Button)sender; + + // + myButton.Style = myButton.TryFindResource("buttonStyle1") as Style; + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/resources.csproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/resources.csproj new file mode 100644 index 0000000..bc339b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/csharp/resources.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net5.0-windows + true + + + + + Code + ResExample - Copy.xaml.cs + + + Code + ResExample.xaml.cs + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml new file mode 100644 index 0000000..67e0d31 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml.vb new file mode 100644 index 0000000..f3e8ffd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml new file mode 100644 index 0000000..893c7ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..76302f2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/MainWindow.xaml.vb @@ -0,0 +1,40 @@ +Class MainWindow + ' + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + + 'Create colors + Dim purple = DirectCast(ColorConverter.ConvertFromString("#4E1A3D"), Color) + Dim white = Colors.White + Dim salmon = Colors.Salmon + + 'Create a new style for a button + Dim buttonStyle As New Style() + + 'Set the properties of the style + buttonStyle.Setters.Add(New Setter(Control.BackgroundProperty, New SolidColorBrush(purple))) + buttonStyle.Setters.Add(New Setter(Control.ForegroundProperty, New SolidColorBrush(white))) + buttonStyle.Setters.Add(New Setter(Control.BorderBrushProperty, New LinearGradientBrush(purple, salmon, 45D))) + buttonStyle.Setters.Add(New Setter(Control.BorderThicknessProperty, New Thickness(5))) + + ' + 'Set this style as a resource. Any DynamicResource looking for this key will be updated. + Me.Resources("buttonStyle1") = buttonStyle + ' + + ' + 'Set this style directly to a button + DirectCast(sender, Button).Style = buttonStyle + ' + + End Sub + ' + + Private Sub ButtonFind_Click(sender As Object, e As RoutedEventArgs) + Dim myButton As Button = DirectCast(sender, Button) + + ' + myButton.Style = myButton.TryFindResource("buttonStyle1") + ' + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/styles.vbproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/styles.vbproj new file mode 100644 index 0000000..8c0990e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-application/vb/styles.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + SampleApplication + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml new file mode 100644 index 0000000..f04909e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml @@ -0,0 +1,6 @@ + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml.cs new file mode 100644 index 0000000..c9b6cbd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/App.xaml.cs @@ -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 SampleApplication +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml new file mode 100644 index 0000000..aaea429 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..061c672 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SampleApplication +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + // + var myButton = new Button() + { + Content = "SystemFonts", + Background = SystemColors.ControlDarkDarkBrush, + FontSize = SystemFonts.IconFontSize, + FontWeight = SystemFonts.MessageFontWeight, + FontFamily = SystemFonts.CaptionFontFamily + }; + + mainStackPanel.Children.Add(myButton); + // + } + + private void Button_Click_2(object sender, RoutedEventArgs e) + { + // + var myButton = new Button() + { + Content = "SystemParameters", + FontSize = 8, + Background = SystemColors.ControlDarkDarkBrush, + Height = SystemParameters.CaptionHeight, + Width = SystemParameters.CaptionWidth, + }; + + mainStackPanel.Children.Add(myButton); + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/resources.csproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/resources.csproj new file mode 100644 index 0000000..bc339b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/csharp/resources.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net5.0-windows + true + + + + + Code + ResExample - Copy.xaml.cs + + + Code + ResExample.xaml.cs + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml new file mode 100644 index 0000000..67e0d31 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml.vb new file mode 100644 index 0000000..f3e8ffd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml new file mode 100644 index 0000000..a7b3f46 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..ad51246 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml.vb @@ -0,0 +1,31 @@ +Class MainWindow + Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs) + ' + Dim myButton = New Button() With + { + .Content = "SystemFonts", + .Background = SystemColors.ControlDarkDarkBrush, + .FontSize = SystemFonts.IconFontSize, + .FontWeight = SystemFonts.MessageFontWeight, + .FontFamily = SystemFonts.CaptionFontFamily + } + + mainStackPanel.Children.Add(myButton) + ' + End Sub + + Private Sub Button_Click_2(sender As Object, e As RoutedEventArgs) + ' + Dim myButton = New Button() With + { + .Content = "SystemParameters", + .FontSize = 8, + .Background = SystemColors.ControlDarkDarkBrush, + .Height = SystemParameters.CaptionHeight, + .Width = SystemParameters.CaptionWidth + } + + mainStackPanel.Children.Add(myButton) + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/styles.vbproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/styles.vbproj new file mode 100644 index 0000000..8c0990e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-how-to-use-system/vb/styles.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + SampleApplication + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml new file mode 100644 index 0000000..9ea450d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml.cs new file mode 100644 index 0000000..32487c0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/App.xaml.cs @@ -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 csharp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml new file mode 100644 index 0000000..b515f4c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml.cs new file mode 100644 index 0000000..3bc10c1 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ImplicitStyle.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace resources +{ + /// + /// Interaction logic for ImplicitStyle.xaml + /// + public partial class ImplicitStyle : Page + { + public ImplicitStyle() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml new file mode 100644 index 0000000..5ea2cad --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..b1fa77c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace csharp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml new file mode 100644 index 0000000..b810b5c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + Title + Label + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml.cs b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml.cs new file mode 100644 index 0000000..2a18ff7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/ResExample.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace resources +{ + /// + /// Interaction logic for ResExample.xaml + /// + public partial class ResExample : Window + { + public ResExample() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/resources.csproj b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/resources.csproj new file mode 100644 index 0000000..bc339b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/snippets/xaml-resources-overview/csharp/resources.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net5.0-windows + true + + + + + Code + ResExample - Copy.xaml.cs + + + Code + ResExample.xaml.cs + + + + diff --git a/dotnet-desktop-guide/net/wpf/systems/xaml-resources-and-code.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-and-code.md new file mode 100644 index 0000000..a0746a2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-and-code.md @@ -0,0 +1,57 @@ +--- +title: WPF resources in code +description: Learn about how Windows Presentation Foundation (WPF) resources, typically defined and used in XAML, can be used in code. Resources can be accessed, created, and managed in code. +author: adegeo +ms.author: adegeo +ms.date: 04/01/2021 +ms.topic: overview +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "keys [WPF], using objects as" + - "resources [WPF], accessing from procedural code" + - "procedural code [WPF], creating resources with" + - "procedural code [WPF], accessing resources from" + - "resources [WPF], creating with procedural code" +--- + +# Resources in code (WPF .NET) + +This overview concentrates on how Windows Presentation Foundation (WPF) resources can be accessed or created using code rather than XAML syntax. For more information on general resource usage and resources from a XAML syntax perspective, see [Overview of XAML resources](xaml-resources-overview.md). + +## Accessing resources from code + +The keys that identify XAML defined resources are also used to retrieve specific resources if you request the resource in code. The simplest way to retrieve a resource from code is to call either the or the method from framework-level objects in your application. The behavioral difference between these methods is what happens if the requested key isn't found. raises an exception. won't raise an exception but returns `null`. Each method takes the resource key as an input parameter, and returns a loosely typed object. + +Typically, a resource key is a string, but there are [occasional nonstring usages](#using-objects-as-keys). The lookup logic for code resource resolution is the same as the dynamic resource reference XAML case. The search for resources starts from the calling element, then continues through parent elements in the logical tree. The lookup continues onwards into application resources, themes, and system resources if necessary. A code request for a resource will properly account for changes to those resources that happened during runtime. + +The following code example demonstrates a event handler that finds a resource by key, and uses the returned value to set a property. + +:::code language="csharp" source="./snippets/xaml-resources-and-code/csharp/MainWindow.xaml.cs" id="ButtonBrush"::: +:::code language="vb" source="./snippets/xaml-resources-and-code/vb/MainWindow.xaml.vb" id="ButtonBrush"::: + +An alternative method for assigning a resource reference is . This method takes two parameters: the key of the resource, and the identifier for a particular dependency property that's present on the element instance to which the resource value should be assigned. Functionally, this method is the same and has the advantage of not requiring any casting of return values. + +Still another way to access resources programmatically is to access the contents of the property as a dictionary. Resource dictionaries are used to add new resources to existing collections, check to see if a given key name is already used by the collection, and other operations. If you're writing a WPF application entirely in code, you can also create the entire collection in code, assign resources to it. The collection can then be assigned to the property of an element. This is described in the next section. + +You can index within any given collection, using a specific key as the index. Resources accessed in this way don't follow the normal runtime rules of resource resolution. You're only accessing that particular collection. Resource lookup doesn't traverse the resource scope to the root or the application if no valid object was found at the requested key. However, this approach may have performance advantages in some cases precisely because the scope of the search for the key is more constrained. For more information about how to work with a resource dictionary directly, see the class. + +## Creating resources with code + +If you want to create an entire WPF application in code, you might also want to create any resources in that application in code. To achieve this, create a new instance, and then add all the resources to the dictionary using successive calls to . Then, assign the created to set the property on an element that's present in a page scope, or the . You could also maintain the as a standalone object without adding it to an element. However, if you do this, you must access the resources within it by item key, as if it were a generic dictionary. A that's not attached to an element `Resources` property wouldn't exist as part of the element tree and has no scope in a lookup sequence that can be used by and related methods. + +## Using objects as keys + +Most resource usages will set the key of the resource to be a string. However, various WPF features deliberately use the object type as a key instead of a string. The capability of having the resource be keyed by an object type is used by the WPF style and theming support. The styles and themes that become the default for an otherwise non-styled control are each keyed by the of the control that they should apply to. + +Being keyed by type provides a reliable lookup mechanism that works on default instances of each control type. The type can be detected by reflection and used for styling derived classes even though the derived type otherwise has no default style. You can specify a key for a resource defined in XAML by using the [x:Type Markup Extension](/dotnet/desktop-wpf/xaml-services/xtype-markup-extension). Similar extensions exist for other nonstring key usages that support WPF features, such as [ComponentResourceKey Markup Extension](../../../framework/wpf/advanced/componentresourcekey-markup-extension.md). + +For more information, see [Styles, DataTemplates, and implicit keys](xaml-resources-overview.md#styles-datatemplates-and-implicit-keys). + +## See also + +- [Overview of XAML resources](xaml-resources-overview.md) +- [How to define and reference a WPF resource](xaml-resources-how-to-define-and-reference.md) +- [How to use system resources](xaml-resources-how-to-use-system.md) +- [How to use application resources](xaml-resources-how-to-use-application.md) diff --git a/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-define-and-reference.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-define-and-reference.md new file mode 100644 index 0000000..35f0abe --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-define-and-reference.md @@ -0,0 +1,104 @@ +--- +title: "How to define and reference a resource" +description: Learn how to define and reference Windows Presentation Foundation (WPF) resources through XAML and code. +author: adegeo +ms.author: adegeo +ms.date: 04/02/2021 +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "resources [WPF], defining" + - "defining resources [WPF]" + - "resources [WPF], referencing" + - "referencing resources [WPF]" +#no-loc: [TextBlock, Setter] +--- + +# How to define and reference a WPF resource (WPF .NET) + +This example shows how to define a resource and reference it. A resource can be referenced through XAML or through code. + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +## XAML example + +The following example defines two types of resources: a resource, and several resources. + +:::code language="xaml" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml" id="ResDefine"::: + +### Resources + +The resource `MyBrush` is used to provide the value of several properties that each take a type value. This resource is referenced through the `x:Key` value. + +:::code language="xaml" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml" id="ResUsed"::: + +In the previous example, the `MyBrush` resource is accessed with the [StaticResource Markup Extension](../../../framework/wpf/advanced/staticresource-markup-extension.md). The resource is assigned to a property that can accept the type of resource being defined. In this case the , , and properties. + +All resources in a resource diction must provide a key. When styles are defined though, they can omit the key, as explained in the [next section](#style-resources). + +Resources are also requested by the order found within the dictionary if you use the [StaticResource Markup Extension](../../../framework/wpf/advanced/staticresource-markup-extension.md) to reference them from within another resource. Make sure that any resource that you reference is defined in the collection earlier than where that resource is requested. For more information, see [Static resources](xaml-resources-overview.md#static-resources). + +If necessary, you can work around the strict creation order of resource references by using a [DynamicResource Markup Extension](../../../framework/wpf/advanced/dynamicresource-markup-extension.md) to reference the resource at runtime instead, but you should be aware that this `DynamicResource` technique has performance consequences. For more information, see [Dynamic resources](xaml-resources-overview.md#dynamic-resources). + +### Style resources + +The following example references styles implicitly and explicitly: + +:::code language="xaml" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/ResExample.xaml" id="ResUsed"::: + +In the previous code example, the resources `TitleText` and `Label`, each target a particular control type. In this case, they both target a . The styles set a variety of different properties on the targeted controls when that style resource is referenced by its resource key for the property. + +The style though that targets a control doesn't define a key. When a key is omitted, the type of object being targeted by the property is implicitly used as the key for the style. When a style is keyed to a type, it becomes the default style for all controls of that type, as long as these controls are within scope of the style. For more information, see [Styles, DataTemplates, and implicit keys](xaml-resources-overview.md#styles-datatemplates-and-implicit-keys). + +## Code examples + +The following code snippets demonstrate creating and setting resources through code + +### Create a style resource + +Creating a resource and assigning it to a resource dictionary can happen at any time. However, only XAML elements that use the DynamicResource syntax will be automatically updated with the resource after it's created. + +Take for example the following Window. It has four buttons. The forth button is using a [DynamicResource](xaml-resources-overview.md#dynamic-resources) to style itself. However, this resource doesn't yet exist, so it just looks like a normal button: + +:::code language="xaml" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml" id="MainXaml"::: + +:::image type="content" source="media/xaml-resources-how-to-define-and-reference/before.png" alt-text="A window before a style is applied to a button"::: + +The following code is invoked when the first button is clicked and performs the following tasks: + +- Creates some colors for easy reference. +- Creates a new style. +- Assigns setters to the style. +- Adds the style as a resource named `buttonStyle1` to the window's resource dictionary. +- Assigns the style directly to the button raising the `Click` event. + +:::code language="csharp" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs" id="CreateStyleCode"::: +:::code language="vb" source="./snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb" id="CreateStyleCode"::: + +After the code runs, the window is updated: + +:::image type="content" source="media/xaml-resources-how-to-define-and-reference/after.png" alt-text="A window after a style is applied to a button"::: + +Notice that the forth button's style was updated. The style was automatically applied because the button used the [DynamicResource Markup Extension](../../../framework/wpf/advanced/dynamicresource-markup-extension.md) to reference a style that didn't yet exist. Once the style was created and added to the resources of the window, it was applied to the button. For more information, see [Dynamic resources](xaml-resources-overview.md#dynamic-resources). + +### Find a resource + +The following code traverses the logical tree of the XAML object in which is run, to find the specified resource. The resource might be defined on the object itself, it's parent, all the way to the root, the application itself. The following code searches for a resource, starting with the button itself: + +:::code language="csharp" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs" id="FindResource"::: +:::code language="vb" source="./snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb" id="FindResource"::: + +### Explicitly reference a resource + +When you have reference to a resource, either by searching for it or by creating it, it can be assigned to a property directly: + +:::code language="csharp" source="./snippets/xaml-resources-how-to-define-and-reference/csharp/MainWindow.xaml.cs" id="SetResource"::: +:::code language="vb" source="./snippets/xaml-resources-how-to-define-and-reference/vb/MainWindow.xaml.vb" id="SetResource"::: + +## See also + +- [Overview of XAML resources](xaml-resources-overview.md) +- [Styles and templates](../controls/styles-templates-overview.md) +- [How to use system resources](xaml-resources-how-to-use-system.md) +- [How to use application resources](xaml-resources-how-to-use-application.md) diff --git a/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-application.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-application.md new file mode 100644 index 0000000..c231866 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-application.md @@ -0,0 +1,34 @@ +--- +title: "How to use application resources" +description: Learn how to define and reference Windows Presentation Foundation (WPF) application-scoped resources in XAML. +author: adegeo +ms.author: adegeo +ms.date: 04/08/2021 +helpviewer_keywords: + - "application resources [WPF]" + - "resources [WPF], application resources" +#no-loc: [App.xaml, Application.xaml] +--- + +# How to use application resources (WPF .NET) + +This example demonstrates how to use application-defined resources. Resources can be defined at the application level, generally through the _App.xaml_ or _Application.xaml_ file, whichever one your project uses. Resources that are defined by the application are globally scoped and accessible by all parts of the application. + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +## Example + +The following example shows an application definition file. The application definition file defines a resource section (a value for the property). Resources defined at the application level can be accessed by all other pages that are part of the application. In this case, the resource is a declared style. Because a complete style that includes a control template can be lengthy, this example omits the control template that is defined within the property setter of the style. + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-application/csharp/App.xaml" id="AppResources"::: + +The following example shows a XAML page that references an application-level resource from the previous example. The resource is referenced with a [StaticResource Markup Extension](../../../framework/wpf/advanced/staticresource-markup-extension.md) that specifies the unique resource key for the resource. The resource "FancyBorder" isn't found in the scope of the current object and window, so the resource lookup continues beyond the current page and into application-level resources. + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-application/csharp/MainWindow.xaml" id="AppResourcesExample"::: + +## See also + +- [Overview of XAML resources](xaml-resources-overview.md) +- [Resources in code](xaml-resources-and-code.md) +- [How to define and reference a WPF resource](xaml-resources-how-to-define-and-reference.md) +- [How to use system resources](xaml-resources-how-to-use-system.md) diff --git a/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-system.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-system.md new file mode 100644 index 0000000..88b35a4 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-how-to-use-system.md @@ -0,0 +1,78 @@ +--- +title: "How to use system resources" +description: Learn how to define and reference Windows Presentation Foundation (WPF) Windows Operating System resources in XAML. +author: adegeo +ms.author: adegeo +ms.date: 04/09/2021 +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "resource keys [WPF], SystemFonts class" + - "resource keys [WPF], SystemParameters class" + - "system fonts [WPF]" + - "classes [WPF], SystemParameters" + - "classes [WPF], SystemFonts" +#no-loc: [App.xaml, Application.xaml] +--- + +# How to use system resources (WPF .NET) + +This example demonstrates how to use system-defined resources. System resources are provided by WPF and allow access to operating system resources, such as fonts, colors, and icons. System resources expose several system-defined values as both resources and properties to help you create visuals that are consistent with Windows. + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +## Fonts + +Use the class to reference the fonts used by the operating system. This class contains system font values as static properties, and properties that reference resource keys that can be used to access those values dynamically at run time. For example, is a value, and is a corresponding resource key. + +The following example shows how to access and use the properties of as static values to style or customize a text block: + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml" id="SystemFont"::: + +To use the values of in code, you don't have to use either a static value or a dynamic resource reference. Instead, use the non-key properties of the class. Although the non-key properties are apparently defined as static properties, the run-time behavior of WPF as hosted by the system will reevaluate the properties in real time and will properly account for user-driven changes to system values. The following example shows how to specify the font settings of a button: + +:::code language="csharp" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml.cs" id="SystemFont"::: +:::code language="vb" source="./snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml.vb" id="SystemFont"::: + +### Dynamic fonts in XAML + +System font metrics can be used as either static or dynamic resources. Use a dynamic resource if you want the font metric to update automatically while the application runs; otherwise, use a static resource. + +> [!NOTE] +> Dynamic resources have the keyword `Key` appended to the property name. + +The following example shows how to access and use system font dynamic resources to style or customize a text block: + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml" id="SystemFontDynamic"::: + +## Parameters + +Use the class to reference system-level properties, such as the size of the primary display. This class contains both system parameter value properties, and resource keys that bind to the values. For example, is a property value and is the corresponding resource key. + +The following example shows how to access and use the static values of to style or customize a button. This markup example sizes a button by applying values to a button: + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml" id="SystemParams"::: + +To use the values of in code, you don't have to use either static references or dynamic resource references. Instead, use the values of the class. Although the non-key properties are apparently defined as static properties, the run-time behavior of WPF as hosted by the system will reevaluate the properties in real time, and will properly account for user-driven changes to system values. The following example shows how to set the width and height of a button by using values: + +:::code language="csharp" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml.cs" id="SystemParams"::: +:::code language="vb" source="./snippets/xaml-resources-how-to-use-system/vb/MainWindow.xaml.vb" id="SystemParams"::: + +### Dynamic parameters in XAML + +System parameter metrics can be used as either static or dynamic resources. Use a dynamic resource if you want the parameter metric to update automatically while the application runs; otherwise, use a static resource. + +> [!NOTE] +> Dynamic resources have the keyword `Key` appended to the property name. + +The following example shows how to access and use system parameter dynamic resources to style or customize a button. This XAML example sizes a button by assigning values to the button's width and height. + +:::code language="xaml" source="./snippets/xaml-resources-how-to-use-system/csharp/MainWindow.xaml" id="SystemParamsDynamic"::: + +## See also + +- [Overview of XAML resources](xaml-resources-overview.md) +- [Resources in code](xaml-resources-and-code.md) +- [How to define and reference a WPF resource](xaml-resources-how-to-define-and-reference.md) +- [How to use application resources](xaml-resources-how-to-use-application.md) diff --git a/dotnet-desktop-guide/net/wpf/systems/xaml-resources-merged-dictionaries.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-merged-dictionaries.md new file mode 100644 index 0000000..6f73cb1 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-merged-dictionaries.md @@ -0,0 +1,82 @@ +--- +title: Merged resource dictionaries +description: Learn about Windows Presentation Foundation (WPF) for .NET merged resource dictionaries. Define and reference XAML resources outside of a compiled WPF application. +author: adegeo +ms.author: adegeo +ms.date: 03/30/2021 +ms.topic: conceptual +helpviewer_keywords: + - "merged resource dictionaries [WPF]" + - "dictionaries [WPF], merged resources" +--- + +# Merged resource dictionaries (WPF .NET) + +Windows Presentation Foundation (WPF) resources support a merged resource dictionary feature. This feature provides a way to define the resources portion of a WPF application outside of the compiled XAML application. Resources can then be shared across applications and are also more conveniently isolated for localization. + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +## Create a merged dictionary + +In markup, you use the following syntax to introduce a merged resource dictionary into a page: + +```xaml + + + + + + + + +``` + +The element doesn't have an [x:Key Directive](../../../xaml-services/xkey-directive.md), which is generally required for all items in a resource collection. But another `ResourceDictionary` reference within the collection is a special case, reserved for this merged resource dictionary scenario. Further, the `ResourceDictionary` that introduces a merged resource dictionary can't have an [x:Key Directive](../../../xaml-services/xkey-directive.md). + +Typically, each within the collection specifies a attribute. The value of `Source` should be a uniform resource identifier (URI) that resolves to the location of the resources file to be merged. The destination of that URI must be another XAML file, with `ResourceDictionary` as its root element. + +> [!NOTE] +> It's legal to define resources within a that's specified as a merged dictionary, either as an alternative to specifying , or in addition to whatever resources are included from the specified source. However, this isn't a common scenario. The main scenario for merged dictionaries is to merge resources from external file locations. If you want to specify resources within the markup for a page, define these in the main `ResourceDictionary` and not in the merged dictionaries. + +## Merged dictionary behavior + +Resources in a merged dictionary occupy a location in the resource lookup scope that's just after the scope of the main resource dictionary they are merged into. Although a resource key must be unique within any individual dictionary, a key can exist multiple times in a set of merged dictionaries. In this case, the resource that's returned will come from the last dictionary found sequentially in the collection. If the collection was defined in XAML, then the order of the merged dictionaries in the collection is the order of the elements as provided in the markup. If a key is defined in the primary dictionary and also in a dictionary that was merged, then the resource that's returned will come from the primary dictionary. These scoping rules apply equally for both static resource references and dynamic resource references. + +## Merged dictionaries and code + +Merged dictionaries can be added to a `Resources` dictionary through code. The default, initially empty that exists for any `Resources` property also has a default, initially empty collection property. To add a merged dictionary through code, you obtain a reference to the desired primary `ResourceDictionary`, get its `MergedDictionaries` property value, and call `Add` on the generic `Collection` that's contained in `MergedDictionaries`. The object you add must be a new `ResourceDictionary`. + +In code, you don't set the property. Instead, you must obtain a `ResourceDictionary` object by either creating one or loading one. One way to load an existing `ResourceDictionary` to call on an existing XAML file stream that has a `ResourceDictionary` root, then casting the return value to `ResourceDictionary`. + +## Merged dictionary URIs + +There are several techniques for how to include a merged resource dictionary, which are indicated by the uniform resource identifier (URI) format that you use. Broadly speaking, these techniques can be divided into two categories: resources that are compiled as part of the project, and resources that aren't compiled as part of the project. + +For resources that are compiled as part of the project, you can use a relative path that refers to the resource location. The relative path is evaluated during compilation. Your resource must be defined as part of the project as a **Resource** build action. If you include a resource _.xaml_ file in the project as **Resource**, you don't need to copy the resource file to the output directory, the resource is already included within the compiled application. You can also use **Content** build action, but you must then copy the files to the output directory and also deploy the resource files in the same path relationship to the executable. + +> [!NOTE] +> Don't use the **Embedded Resource** build action. The build action itself is supported for WPF applications, but the resolution of doesn't incorporate , and thus cannot separate the individual resource out of the stream. You could still use **Embedded Resource** for other purposes so long as you also used to access the resources. + + + +A related technique is to use a **Pack URI** to a XAML file, and refer to it as **Source**. **Pack URI** enables references to components of referenced assemblies and other techniques. For more information on **Pack URIs**, see [WPF Application Resource, Content, and Data Files](../../../framework/wpf/app-development/wpf-application-resource-content-and-data-files.md). + +For resources that aren't compiled as part of the project, the URI is evaluated at run time. You can use a common URI transport such as _file:_ or _http:_ to refer to the resource file. The disadvantage of using the non-compiled resource approach is that _file:_ access requires additional deployment steps, and _http:_ access implies the Internet security zone. + +## Reusing merged dictionaries + +You can reuse or share merged resource dictionaries between applications, because the resource dictionary to merge can be referenced through any valid uniform resource identifier (URI). Exactly how you do this depends on your application deployment strategy and which application model you follow. The [previously mentioned **Pack URI** strategy](#packuri) provides a way to commonly source a merged resource across multiple projects during development by sharing an assembly reference. In this scenario the resources are still distributed by the client, and at least one of the applications must deploy the referenced assembly. It's also possible to reference merged resources through a distributed URI that uses the _http:_ protocol. + +Writing merged dictionaries as local application files or to local shared storage is another possible merged dictionary and application deployment scenario. + +## Localization + +If resources that need to be localized are isolated to dictionaries that are merged into primary dictionaries, and kept as loose XAML, these files can be localized separately. This technique is a lightweight alternative to localizing the satellite resource assemblies. For details, see [WPF Globalization and Localization Overview](../../../framework/wpf/advanced/wpf-globalization-and-localization-overview.md). + +## See also + +- +- [Overview of XAML resources](xaml-resources-overview.md) +- [Resources in code](xaml-resources-and-code.md) +- [WPF Application Resource, Content, and Data Files](../../../framework/wpf/app-development/wpf-application-resource-content-and-data-files.md) +- [WPF Globalization and Localization Overview](../../../framework/wpf/advanced/wpf-globalization-and-localization-overview.md) diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-overview.md similarity index 69% rename from dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md rename to dotnet-desktop-guide/net/wpf/systems/xaml-resources-overview.md index 1508623..dbb9833 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/xaml-resources-define.md +++ b/dotnet-desktop-guide/net/wpf/systems/xaml-resources-overview.md @@ -1,10 +1,13 @@ --- -title: Define XAML resources -description: Learn about XAML resources in WPF for .NET. Understand the types of XAML resources and learn how to define XAML resources. +title: XAML resources overview +description: Learn what a Windows Presentation Foundation (WPF) resource is. WPF provides a resource system, both in XAML and in code, that allows to you create, reference, and reuse resources. author: adegeo ms.author: adegeo -ms.date: 08/21/2019 +ms.date: 03/31/2021 ms.topic: overview +dev_langs: + - "csharp" + - "vb" --- # Overview of XAML resources (WPF .NET) @@ -12,31 +15,36 @@ ms.topic: overview A resource is an object that can be reused in different places in your app. Examples of resources include brushes and styles. This overview describes how to use resources in Extensible Application Markup Language (XAML). You can also create and access resources by using code. > [!NOTE] -> XAML resources described in this article are different from *app resources* which are generally files added to an app, such as content, data, or embedded files. +> XAML resources described in this article are different from *app resources*, which are generally files added to an app, such as content, data, or embedded files. [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] -## Using resources in XAML +## Use resources in XAML The following example defines a as a resource on the root element of a page. The example then references the resource and uses it to set properties of several child elements, including an , a , and a . -[!code-xaml[FEResourceSH_snip#XAML](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xaml)] +:::code language="xaml" source="./snippets/xaml-resources-overview/csharp/ResExample.xaml"::: -Every framework-level element ( or ) has a property, which is a type that contains defined resources. You can define resources on any element, such as a . However, resources are most often defined on the root element, which is in the example. +Every framework-level element ( or ) has a property, which is a type that contains defined resources. You can define resources on any element, such as a . However, resources are most often defined on the root element, which is in the example. Each resource in a resource dictionary must have a unique key. When you define resources in markup, you assign the unique key through the [x:Key Directive](../../../xaml-services/xkey-directive.md). Typically, the key is a string; however, you can also set it to other object types by using the appropriate markup extensions. Non-string keys for resources are used by certain feature areas in WPF, notably for styles, component resources, and data styling. You can use a defined resource with the resource markup extension syntax that specifies the key name of the resource. For example, use the resource as the value of a property on another element. -[!code-xaml[FEResourceSH_snip#KeyNameUsage](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page2.xaml#keynameusage)] +```xaml +` anywhere in the page, and the style you defined with of `Button` would apply to that button. If you want, you can still explicitly key the style with the same type value as for clarity in your markup, but that is optional. -Implicit keys for styles do not apply on a control if is `true`. (Also note that might be set as part of native behavior for the control class, rather than explicitly on an instance of the control.) Also, in order to support implicit keys for derived class scenarios, the control must override (all existing controls provided as part of WPF include this override). For more information about styles, themes, and control design, see [Guidelines for Designing Stylable Controls](../../../framework/wpf/controls/guidelines-for-designing-stylable-controls.md). +Implicit keys for styles don't apply on a control if is `true`. (Also note that might be set as part of native behavior for the control class, rather than explicitly on an instance of the control.) Also, to support implicit keys for derived class scenarios, the control must override (all existing controls provided as part of WPF include this override). For more information about styles, themes, and control design, see [Guidelines for Designing Stylable Controls](../../../framework/wpf/controls/guidelines-for-designing-stylable-controls.md). also has an implicit key. The implicit key for a is the property value. can also be specified as the name of the type rather than explicitly using [{x:Type...}](../../../xaml-services/xtype-markup-extension.md). For details, see [Data Templating Overview](../../../framework/wpf/data/data-templating-overview.md). ## See also +- [Resources in code](xaml-resources-and-code.md) +- [Merged resource dictionaries](xaml-resources-merged-dictionaries.md) +- [How to define and reference a WPF resource](xaml-resources-how-to-define-and-reference.md) +- [How to use system resources](xaml-resources-how-to-use-system.md) +- [How to use application resources](xaml-resources-how-to-use-application.md) +- [x:Type markup extension](../../../xaml-services/xtype-markup-extension.md) - - [Application resources](../../../framework/wpf/advanced/optimizing-performance-application-resources.md) -- [Resources and code](../../../framework/wpf/advanced/resources-and-code.md) - [Define and reference a resource](../../../framework/wpf/advanced/how-to-define-and-reference-a-resource.md) - [Application management overview](../../../framework/wpf/app-development/application-management-overview.md) -- [x:Type markup extension](../../../xaml-services/xtype-markup-extension.md) - [StaticResource markup extension](../../../framework/wpf/advanced/staticresource-markup-extension.md) - [DynamicResource markup extension](../../../framework/wpf/advanced/dynamicresource-markup-extension.md) diff --git a/dotnet-desktop-guide/net/wpf/toc.yml b/dotnet-desktop-guide/net/wpf/toc.yml index d6d7ee9..ab92669 100644 --- a/dotnet-desktop-guide/net/wpf/toc.yml +++ b/dotnet-desktop-guide/net/wpf/toc.yml @@ -7,53 +7,65 @@ items: href: overview/index.md - name: Create a WPF application href: get-started/create-app-visual-studio.md - # - name: Create a control library - # href: getting-started/how-to-create-control-library.md - name: Migration items: - name: Differences from .NET Framework href: migration/differences-from-net-framework.md - - name: Migrate from Framework to Core - href: migration/convert-project-from-net-framework.md - name: Fundamentals items: - - name: XAML - href: fundamentals/xaml.md - - name: Define resources - href: fundamentals/xaml-resources-define.md - - name: Styles and templates + - name: Windows items: - name: Overview - href: fundamentals/styles-templates-overview.md - - name: Create and apply a style - href: fundamentals/styles-templates-create-apply-style.md - - name: Create and apply a template - href: themes/how-to-create-apply-template.md - #- name: Accessibility overview - # href: fundamentals/accessibility.md - #- name: Localize your app - # href: fundamentals/localize-app.md - #- name: Draw shapes - # href: fundamentals/draw-shapes.md - #- name: Display a dialog popup - # href: fundamentals/display-dialog-popup.md - - name: XAML Language Reference - href: ../../xaml-services/ -- name: Work with data - items: - - name: Data binding overview - href: data/data-binding-overview.md - # - name: Add data binding to a control - # href: data/databind-control.md - # - name: Add validation to a control - # href: data/validate-control-input.md - # - name: Display data in a grid control - # href: data/use-datagrid-control.md -# - name: Package and distribute -# items: -# - name: Package your app with MSIX -# href: publishing/package-app-msix.md -# - name: Publish a library to NuGet -# href: publishing/create-nuget-package.md -# - name: Publish to the Microsoft Store -# href: publishing/publish-microsoft-store.md + href: windows/index.md + - name: Dialogs boxes + href: windows/dialog-boxes-overview.md + - name: Common tasks + items: + - name: Display a message box + href: windows/how-to-open-message-box.md + - name: Open a window + href: windows/how-to-open-window-dialog-box.md + - name: Close a window + href: windows/how-to-close-window-dialog-box.md + - name: Display a system dialog box + href: windows/how-to-open-common-system-dialog-box.md + - name: Get or set the main window + href: windows/how-to-get-set-main-application-window.md + - name: Controls + items: + - name: Styles and templates + items: + - name: Overview + href: controls/styles-templates-overview.md + - name: Common tasks + items: + - name: Create and apply a style + href: controls/how-to-create-apply-style.md + - name: Create and apply a template + href: controls/how-to-create-apply-template.md + - name: Data binding + items: + - name: Overview + href: data/index.md + - name: WPF resource system + items: + - name: Overview + href: systems/xaml-resources-overview.md + - name: Merged dictionaries + href: systems/xaml-resources-merged-dictionaries.md + - name: Resources in code + href: systems/xaml-resources-and-code.md + - name: Common tasks + items: + - name: Define and reference resources + href: systems/xaml-resources-how-to-define-and-reference.md + - name: Use application resources + href: systems/xaml-resources-how-to-use-application.md + - name: Use system resources + href: systems/xaml-resources-how-to-use-system.md + - name: XAML with WPF + items: + - name: Overview + href: xaml/index.md +- name: XAML Language Reference + href: ../../xaml-services/ diff --git a/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md b/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md new file mode 100644 index 0000000..b7634ef --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md @@ -0,0 +1,171 @@ +--- +title: Dialog Boxes Overview +description: Learn about the varieties of dialog boxes in Windows Foundation Presentation (WPF). With a dialog box, you gather and display information to a user. +ms.date: "03/12/2021" +helpviewer_keywords: + - "modeless dialog boxes [WPF]" + - "modal dialog boxes [WPF]" + - "dialog boxes [WPF]" + - "message boxes [WPF]" +--- + +# Dialog boxes overview (WPF .NET) + +Windows Presentation Foundation (WPF) provides ways for you to design your own dialog boxes. Dialog boxes are windows but with a specific intent and user experience. This article discusses how a dialog box works and what types of dialog boxes you can create and use. Dialog boxes are used to: + +- Display specific information to users. +- Gather information from users. +- Both display and gather information. +- Display an operating system prompt, such a print window. +- Select a file or folder. + +These types of windows are known as _dialog boxes_. A dialog box can be displayed in two ways: modal and modeless. + +Displaying a _modal_ dialog box to the user is a technique with which the application interrupts what it was doing until the user closes the dialog box. This generally comes in the form of a prompt or alert. Other windows in the application can't be interacted with until the dialog box is closed. Once the _modal_ dialog box is closed, the application continues. The most common dialog boxes are used to show an open file or save file prompt, displaying the printer dialog, or messaging the user with some status. + +A *modeless* dialog box doesn't prevent a user from activating other windows while it's open. For example, if a user wants to find occurrences of a particular word in a document, a main window will often open a dialog box to ask a user what word they're looking for. Since the application doesn't want to prevent the user from editing the document, the dialog box doesn't need to be modal. A modeless dialog box at least provides a **Close** button to close the dialog box. Other buttons may be provided to run specific functions, such as a **Find Next** button to find the next word in a word search. + +With WPF you can create several types of dialog boxes, such as message boxes, common dialog boxes, and custom dialog boxes. This article discusses each, and the [Dialog Box Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Windows/DialogBox) provides matching examples. + +## Message boxes + +A *message box* is a dialog box that can be used to display textual information and to allow users to make decisions with buttons. The following figure shows a message box that asks a question and provides the user with three buttons to answer the question. + +:::image type="content" source="media/dialog-boxes-overview/word-processor-dialog.png" alt-text="Word processor dialog box asking if you want to save the changes to the document before the application closes."::: + +To create a message box, you use the class. lets you configure the message box text, title, icon, and buttons. + +For more information, see [How to open a message box](how-to-open-message-box.md). + +## Common dialog boxes + +Windows implements different kinds of reusable dialog boxes that are common to all applications, including dialog boxes for selecting files and printing. + +Since these dialog boxes are provided by the operating system, they're shared among all the applications that run on the operating system. These dialog boxes provide a consistent user experience, and are known as *common dialog boxes*. As a user uses a common dialog box in one application, they don't need to learn how to use that dialog box in other applications. + +WPF encapsulates the open file, save file, and print common dialog boxes and exposes them as managed classes for you to use in standalone applications. + +:::image type="content" source="media/dialog-boxes-overview/open-file-dialog-box.png" alt-text="Open file dialog box called from WPF."::: + +To learn more about common dialog boxes, see the following articles: + +- [How to display a common dialog box](how-to-open-common-system-dialog-box.md) +- [Show the Open File dialog box](how-to-open-common-system-dialog-box.md#open-file-dialog-box) +- [Show the Save File dialog box](how-to-open-common-system-dialog-box.md#save-file-dialog-box) +- [Show the Print dialog box](how-to-open-common-system-dialog-box.md#print-dialog-box) + +## Custom dialog boxes + +While common dialog boxes are useful, and should be used when possible, they don't support the requirements of domain-specific dialog boxes. In these cases, you need to create your own dialog boxes. As we'll see, a dialog box is a window with special behaviors. implements those behaviors and you use the window to create custom modal and modeless dialog boxes. + +There are many design considerations to take into account when you create your own dialog box. Although both an application window and dialog box contain similarities, such as sharing the same base class, a dialog box is used for a specific purpose. Usually a dialog box is required when you need to prompt a user for some sort of information or response. Typically the application will pause while the dialog box (modal) is displayed, restricting access to the rest of the application. Once the dialog box is closed, the application continues. Confining interactions to the dialog box alone, though, isn't a requirement. + +When a WPF window is closed, it can't be reopened. Custom dialog boxes are WPF windows and the same rule applies. To learn how to close a window, see [How to close a window or dialog box](how-to-close-window-dialog-box.md). + +### Implementing a dialog box + +When designing a dialog box, follow these suggestions to create a good user experience: + +❌ DON'T clutter the dialog window. The dialog experience is for the user to enter some data, or to make a choice. + +✔️ DO provide an **OK** button to close the window. + +✔️ DO set the **OK** button's property to `true` to allow the user to press the ENTER key to accept and close the window. + +✔️ CONSIDER adding a **Cancel** button so that the user can close the window and indicate that they don't want to continue. + +✔️ DO set the **Cancel** button's property to `true` to allow the user to press the ESC key to close the window. + +✔️ DO set the title of the window to accurately describe what the dialog represents, or what the user should do with the dialog. + +✔️ DO set minimum width and height values for the window, preventing the user from resizing the window too small. + +✔️ CONSIDER disabling the ability to resize the window if is set to `false`. You can disable resizing by setting to + +The following code demonstrates this configuration. + +:::code language="xaml" source="snippets/dialog-boxes-overview/csharp/Margins.xaml" highlight="5-9,58-59"::: + +The above XAML creates a window that looks similar to the following image: + +:::image type="content" source="media/dialog-boxes-overview/example-dialog.png" alt-text="A dialog box window for WPF that shows left, top, right, bottom text boxes."::: + +## UI elements opening a dialog box + +The user experience for a dialog box also extends into the menu bar or the button of the window that opens it. When a menu item or button runs a function that requires user interaction through a dialog box before the function can continue, the control should use an ellipsis at the end of its header text: + +```xaml + + + + + +``` + +The following code is the code-behind for the XAML. + +```csharp +using System.Windows; + +namespace WindowsOverview +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Button was clicked."); + } + } +} +``` + +```vb +Public Class Window1 + + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + MessageBox.Show("Button was clicked.") + End Sub + +End Class +``` + +### Configuring a window for MSBuild + +How you implement your window determines how it's configured for MSBuild. For a window that is defined using both XAML markup and code-behind: + +- XAML markup files are configured as MSBuild `Page` items. +- Code-behind files are configured as MSBuild `Compile` items. + +.NET SDK projects automatically import the correct `Page` and `Compile` items for you and you don't need to do declare these. When the project is configured for WPF, the XAML markup files are automatically imported as `Page` items, and the corresponding code-behind file is imported as `Compile`. + +MSBuild projects won't automatically import the types and you must declare them yourself: + +```xml + + ... + + + ... + +``` + +For information about building WPF applications, see [Compile a WPF Application](../../../framework/wpf/app-development/building-a-wpf-application-wpf.md). + +## Window lifetime + +As with any class, a window has a lifetime that begins when it's first instantiated, after which it's opened, activated/deactivated, and eventually closed. + +### Opening a window + +To open a window, you first create an instance of it, which is demonstrated in the following example: + +:::code language="csharp" source="snippets/index_2/csharp/App.xaml.cs"::: +:::code language="vb" source="snippets/index_2/vb/Application.xaml.vb"::: + +In this example `Window1` is instantiated when the application starts, which occurs when the event is raised. For more information about the startup window, see [How to get or set the main application window](how-to-get-set-main-application-window.md). + +When a window is instantiated, a reference to it's automatically added to a [list of windows](xref:System.Windows.Application.Windows%2A) that is managed by the object. The first window to be instantiated is automatically set by as the [main application window](xref:System.Windows.Application.MainWindow%2A). + +The window is finally opened by calling the method as shown in the following image: + +:::image type="content" source="./media/index/window-with-button.png" alt-text="WPF Window with a single button inside."::: + +A window that is opened by calling is a _modeless_ window, and the application doesn't prevent users from interacting with other windows in the application. Opening a window with opens a window as _modal_ and restricts user interaction to the specific window. For more information, see [Dialog Boxes Overview](dialog-boxes-overview.md). + +When is called, a window does initialization work before it's shown to establish infrastructure that allows it to receive user input. When the window is initialized, the event is raised and the window is shown. + +For more information, see [How to open a window or dialog box](how-to-open-window-dialog-box.md). + +#### Startup window + +The previous example used the `Startup` event to run code that displayed the initial application window. As a shortcut, instead use to specify the path to a XAML file in your application. The application automatically creates and displays the window specified by that property. + +:::code language="xaml" source="snippets/index/csharp/App.xaml" highlight="5"::: + +#### Window ownership + +A window that is opened by using the method doesn't have an implicit relationship with the window that created it. Users can interact with either window independently of the other, which means that either window can do the following: + +- Cover the other (unless one of the windows has its property set to `true`). +- Be minimized, maximized, and restored without affecting the other. + +Some windows require a relationship with the window that opens them. For example, an Integrated Development Environment (IDE) application may open property windows and tool windows whose typical behavior is to cover the window that creates them. Furthermore, such windows should always close, minimize, maximize, and restore in concert with the window that created them. Such a relationship can be established by making one window *own* another, and is achieved by setting the property of the *owned window* with a reference to the *owner window*. This is shown in the following example. + +:::code language="csharp" source="snippets/index/csharp/ChildWindow1.xaml.cs" range="12-18"::: +:::code language="vb" source="snippets/index/vb/ChildWindow1.xaml.vb" range="2-7"::: + +After ownership is established: + +- The owned window can reference its owner window by inspecting the value of its property. +- The owner window can discover all the windows it owns by inspecting the value of its property. + +### Window activation + +When a window is first opened, it becomes the active window. The _active window_ is the window that is currently capturing user input, such as key strokes and mouse clicks. When a window becomes active, it raises the event. + +> [!NOTE] +> When a window is first opened, the and events are raised only after the event is raised. With this in mind, a window can effectively be considered opened when is raised. + +After a window becomes active, a user can activate another window in the same application, or activate another application. When that happens, the currently active window becomes deactivated and raises the event. Likewise, when the user selects a currently deactivated window, the window becomes active again and is raised. + +One common reason to handle and is to enable and disable functionality that can only run when a window is active. For example, some windows display interactive content that requires constant user input or attention, including games and video players. The following example is a simplified video player that demonstrates how to handle and to implement this behavior. + +:::code language="xaml" source="snippets/index/csharp/CustomMediaPlayerWindow.xaml"::: + +The following code is the code-behind for the XAML. + +:::code language="csharp" source="snippets/index/csharp/CustomMediaPlayerWindow.xaml.cs"::: +:::code language="vb" source="snippets/index/vb/CustomMediaPlayerWindow.xaml.vb"::: + +Other types of applications may still run code in the background when a window is deactivated. For example, a mail client may continue polling the mail server while the user is using other applications. Applications like these often provide different or extra behavior while the main window is deactivated. For a mail program, this may mean both adding the new mail item to the inbox and adding a notification icon to the system tray. A notification icon need only be displayed when the mail window isn't active, which is determined by inspecting the property. + +If a background task completes, a window may want to notify the user more urgently by calling method. If the user is interacting with another application activated when is called, the window's taskbar button flashes. However, if a user is interacting with the current application, calling will bring the window to the foreground. + +> [!NOTE] +> You can handle application-scope activation using the and events. + +#### Preventing window activation + +There are scenarios where windows shouldn't be activated when shown, such as conversation windows of a chat application or notification windows of an email application. + +If your application has a window that shouldn't be activated when shown, you can set its property to `false` before calling the method for the first time. As a consequence: + +- The window isn't activated. +- The window's event isn't raised. +- The currently activated window remains activated. + + The window will become activated, however, as soon as the user activates it by clicking either the client or non-client area. In this case: + +- The window is activated. +- The window's event is raised. +- The previously activated window is deactivated. +- The window's and events are then raised as expected in response to user actions. + +### Closing a window + +The life of a window starts coming to an end when a user closes it. Once a window is closed, it can't be reopened. A window can be closed by using elements in the non-client area, including the following: + +- The **Close** item of the **System** menu. +- Pressing ALT + F4. +- Pressing the **Close** button. +- Pressing ESC when a button has the property set to `true` on a modal window. + + You can provide more mechanisms to the client area to close a window, the more common of which include the following: + +- An **Exit** item in the **File** menu, typically for main application windows. +- A **Close** item in the **File** menu, typically on a secondary application window. +- A **Cancel** button, typically on a modal dialog box. +- A **Close** button, typically on a modeless dialog box. + +To close a window in response to one of these custom mechanisms, you need to call the method. The following example implements the ability to close a window by choosing **Exit** from a **File** menu. + +:::code language="xaml" source="snippets/index/csharp/ClosingWindow.xaml"::: + +The following code is the code-behind for the XAML. + +:::code language="csharp" source="snippets/index/csharp/ClosingWindow.xaml.cs"::: +:::code language="vb" source="snippets/index/vb/ClosingWindow.xaml.vb"::: + +> [!NOTE] +> An application can be configured to shut down automatically when either the main application window closes (see ) or the last window closes. For more information, see . + +While a window can be explicitly closed through mechanisms provided in the non-client and client areas, a window can also be implicitly closed as a result of behavior in other parts of the application or Windows, including the following: + +- A user logs off or shuts down Windows. +- A window's closes. +- The main application window is closed and is . +- is called. + +> [!IMPORTANT] +> A window can't be reopened after it's closed. + +#### Cancel window closure + +When a window closes, it raises two events: and . + + is raised before the window closes, and it provides a mechanism by which window closure can be prevented. One common reason to prevent window closure is if window content contains modified data. In this situation, the event can be handled to determine whether data is dirty and, if so, to ask the user whether to either continue closing the window without saving the data or to cancel window closure. The following example shows the key aspects of handling . + +:::code language="xaml" source="snippets/index/csharp/DataWindow.xaml"::: + +The following code is the code-behind for the XAML. + +:::code language="csharp" source="snippets/index/csharp/DataWindow.xaml.cs"::: +:::code language="vb" source="snippets/index/vb/DataWindow.xaml.vb"::: + +The event handler is passed a , which implements the property that you set to `true` to prevent a window from closing. + +If isn't handled, or it's handled but not canceled, the window will close. Just before a window actually closes, is raised. At this point, a window can't be prevented from closing. + +### Window lifetime events + +The following illustration shows the sequence of the principal events in the lifetime of a window: + +:::image type="content" source="./media/index/window-lifetime-events.png" alt-text="Diagram that shows events in a window's lifetime."::: + +The following illustration shows the sequence of the principal events in the lifetime of a window that is shown without activation ( is set to `false` before the window is shown): + +:::image type="content" source="./media/index/window-lifetime-no-activation.png" alt-text="Diagram that shows events in a window's lifetime without activation."::: + +## Window location + +While a window is open, it has a location in the x and y dimensions relative to the desktop. This location can be determined by inspecting the and properties, respectively. Set these properties to change the location of the window. + +You can also specify the initial location of a when it first appears by setting the property with one of the following enumeration values: + +- (default) +- +- + +If the startup location is specified as , and the and properties have not been set, will ask the operating system for a location to appear in. + +### Topmost windows and z-order + +Besides having an x and y location, a window also has a location in the z dimension, which determines its vertical position with respect to other windows. This is known as the window's z-order, and there are two types: **normal** z-order and **topmost** z-order. The location of a window in the *normal z-order* is determined by whether it's currently active or not. By default, a window is located in the normal z-order. The location of a window in the *topmost z-order* is also determined by whether it's currently active or not. Furthermore, windows in the topmost z-order are always located above windows in the normal z-order. A window is located in the topmost z-order by setting its property to `true`. + +Within each z-order type, the currently active window appears above all other windows in the same z-order. + +## Window size + +Besides having a desktop location, a window has a size that is determined by several properties, including the various width and height properties and . + +, , and are used to manage the range of widths that a window can have during its lifetime. + +```xaml + + +``` + +Window height is managed by , , and . + +```xaml + + +``` + +Because the various width values and height values each specify a range, it's possible for the width and height of a resizable window to be anywhere within the specified range for the respective dimension. To detect its current width and height, inspect and , respectively. + + If you'd like the width and height of your window to have a size that fits to the size of the window's content, you can use the property, which has the following values: + +- [SizeToContent.Manual](xref:System.Windows.SizeToContent.Manual)\ +No effect (default). +- [SizeToContent.Width](xref:System.Windows.SizeToContent.Width)\ +Fit to content width, which has the same effect as setting both and to the width of the content. +- [SizeToContent.Height](xref:System.Windows.SizeToContent.Height)\ +Fit to content height, which has the same effect as setting both and to the height of the content. +- [SizeToContent.WidthAndHeight](xref:System.Windows.SizeToContent.WidthAndHeight)\ +Fit to content width and height, which has the same effect as setting both and to the height of the content, and setting both and to the width of the content. + +The following example shows a window that automatically sizes to fit its content, both vertically and horizontally, when first shown. + +```xaml + + +``` + +The following example shows how to set the property in code to specify how a window resizes to fit its content . + +```csharp +// Manually alter window height and width +this.SizeToContent = SizeToContent.Manual; + +// Automatically resize width relative to content +this.SizeToContent = SizeToContent.Width; + +// Automatically resize height relative to content +this.SizeToContent = SizeToContent.Height; + +// Automatically resize height and width relative to content +this.SizeToContent = SizeToContent.WidthAndHeight; +``` + +```vb +' Manually alter window height and width +Me.SizeToContent = SizeToContent.Manual + +' Automatically resize width relative to content +Me.SizeToContent = SizeToContent.Width + +' Automatically resize height relative to content +Me.SizeToContent = SizeToContent.Height + +' Automatically resize height and width relative to content +Me.SizeToContent = SizeToContent.WidthAndHeight +``` + +## Order of precedence for sizing properties + +Essentially, the various sizes properties of a window combine to define the range of width and height for a resizable window. To ensure a valid range is maintained, evaluates the values of the size properties using the following orders of precedence. + +**For Height Properties:** + +01. +01. +01. / +01. + +**For Width Properties:** + +01. +01. +01. / +01. + +The order of precedence can also determine the size of a window when it's maximized, which is managed with the property. + +## Window state + +During the lifetime of a resizable window, it can have three states: normal, minimized, and maximized. A window with a _normal_ state is the default state of a window. A window with this state allows a user to move and resize it by using a resize grip or the border, if it's resizable. + +A window with a *minimized* state collapses to its task bar button if is set to `true`; otherwise, it collapses to the smallest possible size it can be and moves itself to the bottom-left corner of the desktop. Neither type of minimized window can be resized using a border or resize grip, although a minimized window that isn't shown in the task bar can be dragged around the desktop. + +A window with a *maximized* state expands to the maximum size it can be, which will only be as large as its , , and properties dictate. Like a minimized window, a maximized window can't be resized by using a resize grip or by dragging the border. + +> [!NOTE] +> The values of the , , , and properties of a window always represent the values for the normal state, even when the window is currently maximized or minimized. + + The state of a window can be configured by setting its property, which can have one of the following enumeration values: + +- (default) +- +- + +The following example shows how to create a window that is shown as maximized when it opens. + +```xaml + + +``` + +In general, you should set to configure the initial state of a window. Once a _resizable_ window is shown, users can press the minimize, maximize, and restore buttons on the window's title bar to change the window state. + +## Window appearance + +You change the appearance of the client area of a window by adding window-specific content to it, such as buttons, labels, and text boxes. To configure the non-client area, provides several properties, which include to set a window's icon and to set its title. + +You can also change the appearance and behavior of non-client area border by configuring a window's resize mode, window style, and whether it appears as a button in the desktop task bar. + +### Resize mode + +Depending on the property, you can control if, and how, users resize the window. The window style affects the following: + +- Allow or disallow resizing by dragging the window border with the mouse. +- Whether the **Minimize**, **Maximize**, and **Close** buttons appear on the non-client area. +- Whether the **Minimize**, **Maximize**, and **Close** buttons are enabled. + +You can configure how a window resizes by setting its property, which can be one of the following enumeration values: + +- +- +- (default) +- + +As with , the resize mode of a window is unlikely to change during its lifetime, which means that you'll most likely set it from XAML markup. + +```xaml + + +``` + +Note that you can detect whether a window is maximized, minimized, or restored by inspecting the property. + +### Window style + +The border that is exposed from the non-client area of a window is suitable for most applications. However, there are circumstances where different types of borders are needed, or no borders are needed at all, depending on the type of window. + +To control what type of border a window gets, you set its property with one of the following values of the enumeration: + +- +- (default) +- +- + +The effect of applying a window style is illustrated in the following image: + +:::image type="content" source="./media/index/window-styles.png" alt-text="Screenshot that shows how WindowStyle affects a window in WPF."::: + +Notice that the image above doesn't show any noticeable difference between `SingleBorderWindow` and `ThreeDBorderWindow`. Back in Windows XP, `ThreeDBorderWindow` did affect how the window was drawn, adding a 3D border to the client area. Starting with Windows 7, the differences between the two styles are minimal. + +You can set using either XAML markup or code. Because it's unlikely to change during the lifetime of a window, you'll most likely configure it using XAML markup. + +```xaml + + +``` + +#### Non-rectangular window style + +There are also situations where the border styles that allows you to have aren't sufficient. For example, you may want to create an application with a non-rectangular border, like Microsoft Windows Media Player uses. + +For example, consider the speech bubble window shown in the following image: + +:::image type="content" source="./media/index/window-transparent.png" alt-text="Screenshot of a WPF window that has a clipped area and custom shape."::: + +This type of window can be created by setting the property to , and by using special support that has for transparency. + +:::code language="xaml" source="snippets/index/csharp/ClippedWindow.xaml"::: + +This combination of values instructs the window to render transparent. In this state, the window's non-client area adornment buttons can't be used and you need to provide your own. + +### Task bar presence + +The default appearance of a window includes a taskbar button. Some types of windows don't have a task bar button, such as message boxes, [dialog boxes](dialog-boxes-overview.md), or windows with the property set to . You can control whether the task bar button for a window is shown by setting the property, which is `true` by default. + +```xaml + + +``` + +## Other types of windows + + is a window that is designed to host navigable content. + +Dialog boxes are windows that are often used to gather information from a user to complete a function. For example, when a user wants to open a file, the **Open File** dialog box is displayed by an application to get the file name from the user. For more information, see [Dialog Boxes Overview](dialog-boxes-overview.md). + +## See also + +- [Dialog boxes overview](dialog-boxes-overview.md) +- [How to open a window or dialog box](how-to-open-window-dialog-box.md) +- [How to open a common dialog box](how-to-open-common-system-dialog-box.md) +- [How to open a message box](how-to-open-message-box.md) +- [How to close a window or dialog box](how-to-close-window-dialog-box.md) +- +- +- +- diff --git a/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/example-dialog.png b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/example-dialog.png new file mode 100644 index 0000000..263da6a Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/example-dialog.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/open-file-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/open-file-dialog-box.png new file mode 100644 index 0000000..109b586 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/open-file-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor-menu.png b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor-menu.png new file mode 100644 index 0000000..36a4251 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor-menu.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor.png b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor.png new file mode 100644 index 0000000..f0eafe6 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/simple-text-editor.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/word-processor-dialog.png b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/word-processor-dialog.png new file mode 100644 index 0000000..b05c746 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/dialog-boxes-overview/word-processor-dialog.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/open-file-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/open-file-dialog-box.png new file mode 100644 index 0000000..109b586 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/open-file-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/print-data-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/print-data-dialog-box.png new file mode 100644 index 0000000..74d8ba4 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/print-data-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/save-file-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/save-file-dialog-box.png new file mode 100644 index 0000000..f86a700 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-common-system-dialog-box/save-file-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert-simple.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert-simple.png new file mode 100644 index 0000000..3ad541b Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert-simple.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert.png new file mode 100644 index 0000000..d2a8cb5 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/alert.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.pdn b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.pdn new file mode 100644 index 0000000..345eb88 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.pdn differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.png new file mode 100644 index 0000000..9e58eec Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/diagram.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/prompt.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/prompt.png new file mode 100644 index 0000000..f3dcf75 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/prompt.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/warning.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/warning.png new file mode 100644 index 0000000..d56dd32 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-message-box/warning.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/find-modeless-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/find-modeless-dialog-box.png new file mode 100644 index 0000000..79692ea Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/find-modeless-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/invalid-left-margin-dialog.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/invalid-left-margin-dialog.png new file mode 100644 index 0000000..8feed21 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/invalid-left-margin-dialog.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/margin-size-dialog-box.png b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/margin-size-dialog-box.png new file mode 100644 index 0000000..ec3c115 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/how-to-open-window-dialog-box/margin-size-dialog-box.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-events.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-events.png new file mode 100644 index 0000000..aa7995e Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-events.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-no-activation.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-no-activation.png new file mode 100644 index 0000000..bc42780 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-lifetime-no-activation.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.pdn b/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.pdn new file mode 100644 index 0000000..40c66a9 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.pdn differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.png new file mode 100644 index 0000000..952f361 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-parts.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-styles.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-styles.png new file mode 100644 index 0000000..2d90fa4 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-styles.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-transparent.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-transparent.png new file mode 100644 index 0000000..ee56d48 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-transparent.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/media/index/window-with-button.png b/dotnet-desktop-guide/net/wpf/windows/media/index/window-with-button.png new file mode 100644 index 0000000..b534c96 Binary files /dev/null and b/dotnet-desktop-guide/net/wpf/windows/media/index/window-with-button.png differ diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml new file mode 100644 index 0000000..3368f61 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml.cs new file mode 100644 index 0000000..cbd31c2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace Dialogs +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // Create the window + Window1 window = new Window1(); + + // Open the window + window.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Dialogs.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Dialogs.csproj new file mode 100644 index 0000000..49ad9b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Dialogs.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net5.0-windows + true + app.manifest + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/MarginValidationRule.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/MarginValidationRule.cs new file mode 100644 index 0000000..b26b9a9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/MarginValidationRule.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace Dialogs +{ + public class MarginValidationRule : ValidationRule + { + public double MinMargin { get; set; } + public double MaxMargin { get; set; } + + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + double margin; + + // Is a number? + if (!double.TryParse((string)value, out margin)) + { + return new ValidationResult(false, "Not a number."); + } + + // Is in range? + if ((margin < MinMargin) || (margin > MaxMargin)) + { + var msg = $"Margin must be between {MinMargin} and {MaxMargin}."; + return new ValidationResult(false, msg); + } + + // Number is valid + return new ValidationResult(true, null); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml new file mode 100644 index 0000000..b4c7ae6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml.cs new file mode 100644 index 0000000..3dd46f6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Margins.xaml.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Dialogs +{ + /// + /// Interaction logic for Margins.xaml + /// + public partial class Margins : Window + { + public Margins() + { + InitializeComponent(); + } + + private void okButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + + // + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + // First, cancel the window closure + e.Cancel = true; + + // Next, hide the window + Hide(); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Window1.xaml new file mode 100644 index 0000000..b817605 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/csharp/Window1.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Margins.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Margins.xaml.vb new file mode 100644 index 0000000..2b5f2e8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Margins.xaml.vb @@ -0,0 +1,15 @@ +Public Class Margins + Private Sub okButton_Click(sender As Object, e As RoutedEventArgs) + + End Sub + + ' + Private Sub Window_Closing(sender As Object, e As ComponentModel.CancelEventArgs) + 'First, cancel the window closure + e.Cancel = True + + 'Next, hide the window + Hide() + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Window1.xaml new file mode 100644 index 0000000..38aefa8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/dialog-boxes-overview/vb/Window1.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Margins.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Margins.xaml.cs new file mode 100644 index 0000000..4905623 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Margins.xaml.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace CloseWindows +{ + /// + /// Interaction logic for Margins.xaml + /// + public partial class Margins : Window + { + public Margins() + { + InitializeComponent(); + } + + private void okButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + + // + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + // Cancel the closure + e.Cancel = true; + + // Hide the window + Hide(); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Menus.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Menus.xaml new file mode 100644 index 0000000..eb44d3b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Menus.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Window1.xaml.cs new file mode 100644 index 0000000..a55a8ef --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/Window1.xaml.cs @@ -0,0 +1,36 @@ +using System.Windows; + +namespace CloseWindows +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void formatMarginsButton_Click(object sender, RoutedEventArgs e) + { + // + var window = new Margins(); + window.Owner = this; + window.ShowDialog(); + // + } + + private void showMenus_Click(object sender, RoutedEventArgs e) + { + var menu = new Menus(); + var result = menu.ShowDialog(); + menu.Show(); + } + + // + private void okButton_Click(object sender, RoutedEventArgs e) => + DialogResult = true; + + private void cancelButton_Click(object sender, RoutedEventArgs e) => + DialogResult = false; + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/app.manifest b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/app.manifest new file mode 100644 index 0000000..67d2cf9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/csharp/app.manifest @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml new file mode 100644 index 0000000..496faae --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml.vb new file mode 100644 index 0000000..5bde547 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Application.xaml.vb @@ -0,0 +1,11 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' Create the window + Dim window As New Window1 + + ' Open the window + window.Show() + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/CloseWindowsVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/CloseWindowsVB.vbproj new file mode 100644 index 0000000..de6c78f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/CloseWindowsVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + CloseWindows + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/MarginValidationRule.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/MarginValidationRule.vb new file mode 100644 index 0000000..c52d52d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/MarginValidationRule.vb @@ -0,0 +1,26 @@ +Imports System.Globalization + +Public Class MarginValidationRule + Inherits ValidationRule + + Public Property MinMargin As Double + Public Property MaxMargin As Double + + Public Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As ValidationResult + Dim margin As Double + + ' Is it a number? + If Not Double.TryParse(DirectCast(value, String), margin) Then + Return New ValidationResult(False, "Not a number") + End If + + ' Is it in range + If margin < MinMargin Or margin > MaxMargin Then + Return New ValidationResult(False, $"Margin must be between {MinMargin} and {MaxMargin}") + End If + + Return New ValidationResult(True, Nothing) + + End Function + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml new file mode 100644 index 0000000..92b6604 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml.vb new file mode 100644 index 0000000..838177e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Margins.xaml.vb @@ -0,0 +1,15 @@ +Public Class Margins + Private Sub okButton_Click(sender As Object, e As RoutedEventArgs) + + End Sub + + ' + Private Sub Window_Closing(sender As Object, e As ComponentModel.CancelEventArgs) + ' Cancel the closure + e.Cancel = True + + ' Hide the window + Hide() + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Menus.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Menus.xaml new file mode 100644 index 0000000..a655028 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Menus.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Window1.xaml.vb new file mode 100644 index 0000000..66fd029 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-close-window-dialog-box/vb/Window1.xaml.vb @@ -0,0 +1,79 @@ +Public Class Window1 + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + ' + Dim messageBoxText As String = "Do you want to save changes?" + Dim caption As String = "Word Processor" + Dim Button As MessageBoxButton = MessageBoxButton.YesNoCancel + Dim Icon As MessageBoxImage = MessageBoxImage.Warning + Dim result As MessageBoxResult + + ' + result = MessageBox.Show(messageBoxText, caption, Button, Icon) + ' + + Select Case result + Case MessageBoxResult.Cancel + ' User pressed Cancel + Case MessageBoxResult.Yes + ' User pressed Yes + Case MessageBoxResult.No + ' User pressed No + End Select + ' + End Sub + + Private Sub Save_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure save file dialog box + Dim dialog As New Microsoft.Win32.SaveFileDialog() + dialog.FileName = "Document" ' Default file name + dialog.DefaultExt = ".txt" ' Default file extension + dialog.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension + + ' Show save file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process save file dialog box results + If result = True Then + ' Save document + Dim filename As String = dialog.FileName + End If + ' + End Sub + + Private Sub Open_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure open file dialog box + Dim dialog As New Microsoft.Win32.OpenFileDialog() + dialog.FileName = "Document" ' Default file name + dialog.DefaultExt = ".txt" ' Default file extension + dialog.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension + + ' Show open file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process open file dialog box results + If result = True Then + ' Open document + Dim filename As String = dialog.FileName + End If + ' + End Sub + + Private Sub Print_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure printer dialog box + Dim dialog As New System.Windows.Controls.PrintDialog() + dialog.PageRangeSelection = System.Windows.Controls.PageRangeSelection.AllPages + dialog.UserPageRangeEnabled = True + + ' Show save file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process save file dialog box results + If result = True Then + ' Print document + End If + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml new file mode 100644 index 0000000..d0b82b3 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml @@ -0,0 +1,7 @@ + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml.cs new file mode 100644 index 0000000..7b37049 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/App.xaml.cs @@ -0,0 +1,22 @@ +using System.Windows; + +namespace MainApp +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // + Application.Current.MainWindow = new Window2(); + + Application.Current.MainWindow.Show(); + // + + // + var appWindow = new Window2(); + + appWindow.Show(); + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/MainApp.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/MainApp.csproj new file mode 100644 index 0000000..453da2b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/MainApp.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net5.0-windows + true + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml new file mode 100644 index 0000000..bbddec7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml @@ -0,0 +1,12 @@ + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml.cs new file mode 100644 index 0000000..7d99b81 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window1.xaml.cs @@ -0,0 +1,17 @@ +using System.Windows; + +namespace MainApp +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + // + private void Button_Click(object sender, RoutedEventArgs e) => + MessageBox.Show($"The main window's title is: {Application.Current.MainWindow.Title}"); + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml new file mode 100644 index 0000000..2ba87c0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml.cs new file mode 100644 index 0000000..d2cb5ff --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/csharp/Window2.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace MainApp +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml new file mode 100644 index 0000000..619a09a --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml.vb new file mode 100644 index 0000000..af8fe16 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Application.xaml.vb @@ -0,0 +1,17 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' + Application.Current.MainWindow = New Window2() + + Application.Current.MainWindow.Show() + ' + + ' + Dim appWindow As New Window2() + + appWindow.Show() + ' + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/MainAppVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/MainAppVB.vbproj new file mode 100644 index 0000000..0dc12ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/MainAppVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + WindowsOverview + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml new file mode 100644 index 0000000..aa7edff --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml @@ -0,0 +1,11 @@ + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml.vb new file mode 100644 index 0000000..8c53a42 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window1.xaml.vb @@ -0,0 +1,7 @@ +Public Class Window1 + ' + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + MessageBox.Show($"The main window's title is: {Application.Current.MainWindow.Title}") + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml new file mode 100644 index 0000000..b48dd53 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml.vb new file mode 100644 index 0000000..cffbfed --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window/vb/Window2.xaml.vb @@ -0,0 +1,3 @@ +Public Class Window2 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml new file mode 100644 index 0000000..01199c8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml.cs new file mode 100644 index 0000000..6184c0d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Windows; + +namespace MainApp +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/MainApp.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/MainApp.csproj new file mode 100644 index 0000000..453da2b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/MainApp.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net5.0-windows + true + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml new file mode 100644 index 0000000..bbddec7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml @@ -0,0 +1,12 @@ + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml.cs new file mode 100644 index 0000000..cd584fb --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window1.xaml.cs @@ -0,0 +1,17 @@ +using System.Windows; + +namespace MainApp +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml new file mode 100644 index 0000000..2ba87c0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml.cs new file mode 100644 index 0000000..d2cb5ff --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-get-set-main-application-window_2/csharp/Window2.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace MainApp +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml new file mode 100644 index 0000000..125ef1f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml.cs new file mode 100644 index 0000000..46035de --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // Create the window + Window1 window = new Window1(); + + // Open the window + window.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Dialogs.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Dialogs.csproj new file mode 100644 index 0000000..49ad9b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Dialogs.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net5.0-windows + true + app.manifest + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml new file mode 100644 index 0000000..7360012 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml.cs new file mode 100644 index 0000000..6f062b8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/Window1.xaml.cs @@ -0,0 +1,101 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + // + string messageBoxText = "Do you want to save changes?"; + string caption = "Word Processor"; + MessageBoxButton button = MessageBoxButton.YesNoCancel; + MessageBoxImage icon = MessageBoxImage.Warning; + MessageBoxResult result; + + // + result = MessageBox.Show(messageBoxText, caption, button, icon); + // + + switch (result) + { + case MessageBoxResult.Cancel: + // User pressed Cancel + break; + case MessageBoxResult.Yes: + // User pressed Yes + break; + case MessageBoxResult.No: + // User pressed No + break; + } + // + } + + private void Save_Click(object sender, RoutedEventArgs e) + { + // + // Configure save file dialog box + var dialog = new Microsoft.Win32.SaveFileDialog(); + dialog.FileName = "Document"; // Default file name + dialog.DefaultExt = ".txt"; // Default file extension + dialog.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension + + // Show save file dialog box + bool? result = dialog.ShowDialog(); + + // Process save file dialog box results + if (result == true) + { + // Save document + string filename = dialog.FileName; + } + // + } + + private void Open_Click(object sender, RoutedEventArgs e) + { + // + // Configure open file dialog box + var dialog = new Microsoft.Win32.OpenFileDialog(); + dialog.FileName = "Document"; // Default file name + dialog.DefaultExt = ".txt"; // Default file extension + dialog.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension + + // Show open file dialog box + bool? result = dialog.ShowDialog(); + + // Process open file dialog box results + if (result == true) + { + // Open document + string filename = dialog.FileName; + } + // + } + + private void Print_Click(object sender, RoutedEventArgs e) + { + // + // Configure printer dialog box + var dialog = new System.Windows.Controls.PrintDialog(); + dialog.PageRangeSelection = System.Windows.Controls.PageRangeSelection.AllPages; + dialog.UserPageRangeEnabled = true; + + // Show save file dialog box + bool? result = dialog.ShowDialog(); + + // Process save file dialog box results + if (result == true) + { + // Document was printed + } + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/app.manifest b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/app.manifest new file mode 100644 index 0000000..67d2cf9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/csharp/app.manifest @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml new file mode 100644 index 0000000..7d338d8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml.vb new file mode 100644 index 0000000..5bde547 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Application.xaml.vb @@ -0,0 +1,11 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' Create the window + Dim window As New Window1 + + ' Open the window + window.Show() + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/DialogsVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/DialogsVB.vbproj new file mode 100644 index 0000000..0dc12ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/DialogsVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + WindowsOverview + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml new file mode 100644 index 0000000..2a5e72c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml.vb new file mode 100644 index 0000000..e831b90 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-common-system-dialog-box/vb/Window1.xaml.vb @@ -0,0 +1,79 @@ +Public Class Window1 + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + ' + Dim messageBoxText As String = "Do you want to save changes?" + Dim caption As String = "Word Processor" + Dim Button As MessageBoxButton = MessageBoxButton.YesNoCancel + Dim Icon As MessageBoxImage = MessageBoxImage.Warning + Dim result As MessageBoxResult + + ' + result = MessageBox.Show(messageBoxText, caption, Button, Icon) + ' + + Select Case result + Case MessageBoxResult.Cancel + ' User pressed Cancel + Case MessageBoxResult.Yes + ' User pressed Yes + Case MessageBoxResult.No + ' User pressed No + End Select + ' + End Sub + + Private Sub Save_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure save file dialog box + Dim dialog As New Microsoft.Win32.SaveFileDialog() + dialog.FileName = "Document" ' Default file name + dialog.DefaultExt = ".txt" ' Default file extension + dialog.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension + + ' Show save file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process save file dialog box results + If result = True Then + ' Save document + Dim filename As String = dialog.FileName + End If + ' + End Sub + + Private Sub Open_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure open file dialog box + Dim dialog As New Microsoft.Win32.OpenFileDialog() + dialog.FileName = "Document" ' Default file name + dialog.DefaultExt = ".txt" ' Default file extension + dialog.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension + + ' Show open file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process open file dialog box results + If result = True Then + ' Open document + Dim filename As String = dialog.FileName + End If + ' + End Sub + + Private Sub Print_Click(sender As Object, e As RoutedEventArgs) + ' + ' Configure printer dialog box + Dim dialog As New System.Windows.Controls.PrintDialog() + dialog.PageRangeSelection = System.Windows.Controls.PageRangeSelection.AllPages + dialog.UserPageRangeEnabled = True + + ' Show save file dialog box + Dim result As Boolean? = dialog.ShowDialog() + + ' Process save file dialog box results + If result = True Then + ' Document was printed + End If + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml new file mode 100644 index 0000000..125ef1f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml.cs new file mode 100644 index 0000000..46035de --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // Create the window + Window1 window = new Window1(); + + // Open the window + window.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Dialogs.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Dialogs.csproj new file mode 100644 index 0000000..49ad9b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Dialogs.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net5.0-windows + true + app.manifest + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml new file mode 100644 index 0000000..d84d329 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml.cs new file mode 100644 index 0000000..fc4b39e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/Window1.xaml.cs @@ -0,0 +1,75 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + // + string messageBoxText = "Do you want to save changes?"; + string caption = "Word Processor"; + MessageBoxButton button = MessageBoxButton.YesNoCancel; + MessageBoxImage icon = MessageBoxImage.Warning; + MessageBoxResult result; + + // + result = MessageBox.Show(messageBoxText, caption, button, icon, MessageBoxResult.Yes); + // + + switch (result) + { + case MessageBoxResult.Cancel: + // User pressed Cancel + break; + case MessageBoxResult.Yes: + // User pressed Yes + break; + case MessageBoxResult.No: + // User pressed No + break; + } + // + } + + private void Button2_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Message to display to the user", "Window caption", MessageBoxButton.OK, MessageBoxImage.Question, MessageBoxResult.OK, MessageBoxOptions.RightAlign); + } + + private void Alert_Click(object sender, RoutedEventArgs e) + { + // + MessageBox.Show("Unable to save file, try again."); + // + // + MessageBox.Show("Unable to save file, try again.", "Save error", MessageBoxButton.OK, MessageBoxImage.Error); + // + } + + private void Warning_Click(object sender, RoutedEventArgs e) + { + // + MessageBox.Show("If you close the next window without saving, your changes will be lost.", "Configuration", MessageBoxButton.OK, MessageBoxImage.Warning); + // + } + + private void Prompt_Click(object sender, RoutedEventArgs e) + { + // + if (MessageBox.Show("If the file save fails, do you want to automatically try again?", + "Save file", + MessageBoxButton.YesNo, + MessageBoxImage.Question) == MessageBoxResult.Yes) + { + // Do something here + } + // + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/app.manifest b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/app.manifest new file mode 100644 index 0000000..67d2cf9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/csharp/app.manifest @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml new file mode 100644 index 0000000..7d338d8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml.vb new file mode 100644 index 0000000..5bde547 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Application.xaml.vb @@ -0,0 +1,11 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' Create the window + Dim window As New Window1 + + ' Open the window + window.Show() + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/DialogsVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/DialogsVB.vbproj new file mode 100644 index 0000000..0dc12ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/DialogsVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + WindowsOverview + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml new file mode 100644 index 0000000..d85aa80 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml.vb new file mode 100644 index 0000000..85527ec --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-message-box/vb/Window1.xaml.vb @@ -0,0 +1,56 @@ +Public Class Window1 + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + ' + Dim messageBoxText As String = "Do you want to save changes?" + Dim caption As String = "Word Processor" + Dim Button As MessageBoxButton = MessageBoxButton.YesNoCancel + Dim Icon As MessageBoxImage = MessageBoxImage.Warning + Dim result As MessageBoxResult + + ' + result = MessageBox.Show(messageBoxText, caption, Button, Icon, MessageBoxResult.Yes) + ' + + Select Case result + Case MessageBoxResult.Cancel + ' User pressed Cancel + Case MessageBoxResult.Yes + ' User pressed Yes + Case MessageBoxResult.No + ' User pressed No + End Select + ' + End Sub + + Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) + MessageBox.Show("Message to display to the user", "Window caption", MessageBoxButton.OK, MessageBoxImage.Question, MessageBoxResult.OK, MessageBoxOptions.RightAlign) + End Sub + + Private Sub Alert_Click(sender As Object, e As RoutedEventArgs) + ' + MessageBox.Show("Unable to save file, try again.") + ' + ' + MessageBox.Show("Unable to save file, try again.", "Save error", MessageBoxButton.OK, MessageBoxImage.Error) + ' + End Sub + + Private Sub Warning_Click(sender As Object, e As RoutedEventArgs) + ' + MessageBox.Show("If you close the next window without saving, your changes will be lost.", "Configuration", MessageBoxButton.OK, MessageBoxImage.Warning) + ' + End Sub + + Private Sub Prompt_Click(sender As Object, e As RoutedEventArgs) + ' + If MessageBox.Show("If the file save fails, do you want to automatically try again?", + "Save file", + MessageBoxButton.YesNo, + MessageBoxImage.Question) = MessageBoxResult.Yes Then + + ' Do something here + + End If + ' + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml new file mode 100644 index 0000000..d6c65e8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml.cs new file mode 100644 index 0000000..4f11688 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace DisplayWindows +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // Create the window + Window1 window = new Window1(); + + // Open the window + window.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/DisplayWindows.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/DisplayWindows.csproj new file mode 100644 index 0000000..49ad9b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/DisplayWindows.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net5.0-windows + true + app.manifest + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/MarginValidationRule.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/MarginValidationRule.cs new file mode 100644 index 0000000..a94bfc7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/MarginValidationRule.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace DisplayWindows +{ + public class MarginValidationRule : ValidationRule + { + public double MinMargin { get; set; } + public double MaxMargin { get; set; } + + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + double margin; + + // Is a number? + if (!double.TryParse((string)value, out margin)) + { + return new ValidationResult(false, "Not a number."); + } + + // Is in range? + if ((margin < MinMargin) || (margin > MaxMargin)) + { + var msg = $"Margin must be between {MinMargin} and {MaxMargin}."; + return new ValidationResult(false, msg); + } + + // Number is valid + return new ValidationResult(true, null); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml new file mode 100644 index 0000000..20a5db7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml.cs new file mode 100644 index 0000000..04288b7 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Margins.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace DisplayWindows +{ + /// + /// Interaction logic for Margins.xaml + /// + public partial class Margins : Window + { + public Margins() + { + InitializeComponent(); + } + + private void okButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml new file mode 100644 index 0000000..15733e2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. This is a text editor. + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml.cs new file mode 100644 index 0000000..89a2003 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Menus.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace DisplayWindows +{ + /// + /// Interaction logic for Menus.xaml + /// + public partial class Menus : Window + { + public Menus() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml new file mode 100644 index 0000000..f1b2a36 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml.cs new file mode 100644 index 0000000..28bf862 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/Window1.xaml.cs @@ -0,0 +1,40 @@ +using System.Windows; + +namespace DisplayWindows +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void formatMarginsButton_Click(object sender, RoutedEventArgs e) + { + // + var window = new Margins(); + + window.Owner = this; + window.ShowDialog(); + // + } + + private void showMenus_Click(object sender, RoutedEventArgs e) + { + // + var window = new Margins(); + + window.Owner = this; + window.Show(); + // + } + + // + private void okButton_Click(object sender, RoutedEventArgs e) => + DialogResult = true; + + private void cancelButton_Click(object sender, RoutedEventArgs e) => + DialogResult = false; + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/app.manifest b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/app.manifest new file mode 100644 index 0000000..67d2cf9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/csharp/app.manifest @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml new file mode 100644 index 0000000..75743db --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml.vb new file mode 100644 index 0000000..5bde547 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Application.xaml.vb @@ -0,0 +1,11 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' Create the window + Dim window As New Window1 + + ' Open the window + window.Show() + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/DisplayWindowsVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/DisplayWindowsVB.vbproj new file mode 100644 index 0000000..bd80052 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/DisplayWindowsVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + DisplayWindows + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/MarginValidationRule.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/MarginValidationRule.vb new file mode 100644 index 0000000..c52d52d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/MarginValidationRule.vb @@ -0,0 +1,26 @@ +Imports System.Globalization + +Public Class MarginValidationRule + Inherits ValidationRule + + Public Property MinMargin As Double + Public Property MaxMargin As Double + + Public Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As ValidationResult + Dim margin As Double + + ' Is it a number? + If Not Double.TryParse(DirectCast(value, String), margin) Then + Return New ValidationResult(False, "Not a number") + End If + + ' Is it in range + If margin < MinMargin Or margin > MaxMargin Then + Return New ValidationResult(False, $"Margin must be between {MinMargin} and {MaxMargin}") + End If + + Return New ValidationResult(True, Nothing) + + End Function + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml new file mode 100644 index 0000000..22acbaf --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml.vb new file mode 100644 index 0000000..c43ca79 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Margins.xaml.vb @@ -0,0 +1,5 @@ +Public Class Margins + Private Sub okButton_Click(sender As Object, e As RoutedEventArgs) + + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml new file mode 100644 index 0000000..059d997 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml.vb new file mode 100644 index 0000000..5436c0f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/how-to-open-window-dialog-box/vb/Window1.xaml.vb @@ -0,0 +1,23 @@ +Public Class Window1 + Private Sub formatMarginsButton_Click(sender As Object, e As RoutedEventArgs) + ' + Dim myWindow As New Margins() + + myWindow.Owner = Me + myWindow.ShowDialog() + ' + End Sub + + Private Sub showMenus_Click(sender As Object, e As RoutedEventArgs) + ' + Dim myWindow As New Margins() + + myWindow.Owner = Me + myWindow.Show() + ' + End Sub + + Private Sub okButton_Click(sender As Object, e As RoutedEventArgs) + + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml new file mode 100644 index 0000000..a61a9c1 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml.cs new file mode 100644 index 0000000..83a617a --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/App.xaml.cs @@ -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 WindowsOverview +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml new file mode 100644 index 0000000..ca798d5 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml.cs new file mode 100644 index 0000000..17c153f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ChildWindow1.xaml.cs @@ -0,0 +1,20 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class ChildWindow1 : Window + { + public ChildWindow1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + // Create a window and make the current window its owner + var ownedWindow = new ChildWindow1(); + ownedWindow.Owner = this; + ownedWindow.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ClippedWindow.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ClippedWindow.xaml new file mode 100644 index 0000000..130d77d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/ClippedWindow.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Final.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Final.xaml.cs new file mode 100644 index 0000000..aa7be1f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Final.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for Final.xaml + /// + public partial class Final : Window + { + public Final() + { + InitializeComponent(); + } + + // + private void ButtonAddName_Click(object sender, RoutedEventArgs e) + { + if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) + lstNames.Items.Add(txtName.Text); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml new file mode 100644 index 0000000..aa5b6cd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml.cs new file mode 100644 index 0000000..a0f7b06 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Start.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml new file mode 100644 index 0000000..7f1cd6c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml.cs new file mode 100644 index 0000000..77fdd6e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/Window1.xaml.cs @@ -0,0 +1,17 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Button was clicked."); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml new file mode 100644 index 0000000..afd841f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml.cs new file mode 100644 index 0000000..e853839 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorder3d.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for WindowBorder3d.xaml + /// + public partial class WindowBorder3d : Window + { + public WindowBorder3d() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml new file mode 100644 index 0000000..dbab36e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml @@ -0,0 +1,13 @@ + + + WindowStyle = None + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml.cs new file mode 100644 index 0000000..629e7c1 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderNone.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for WindowBorderNone.xaml + /// + public partial class WindowBorderNone : Window + { + public WindowBorderNone() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml new file mode 100644 index 0000000..19edbfc --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml.cs new file mode 100644 index 0000000..819bb96 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderSingle.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for WindowBorderSingle.xaml + /// + public partial class WindowBorderSingle : Window + { + public WindowBorderSingle() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml new file mode 100644 index 0000000..1e3eac8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml.cs new file mode 100644 index 0000000..acd5cc6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowBorderTool.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WindowsOverview +{ + /// + /// Interaction logic for WindowBorderTool.xaml + /// + public partial class WindowBorderTool : Window + { + public WindowBorderTool() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowsOverview.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowsOverview.csproj new file mode 100644 index 0000000..49ad9b0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/WindowsOverview.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net5.0-windows + true + app.manifest + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/app.manifest b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/app.manifest new file mode 100644 index 0000000..67d2cf9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/csharp/app.manifest @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml new file mode 100644 index 0000000..a59ebec --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml.vb new file mode 100644 index 0000000..084cbe9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml new file mode 100644 index 0000000..eb51c9d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml.vb new file mode 100644 index 0000000..769f553 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ChildWindow1.xaml.vb @@ -0,0 +1,8 @@ +Public Class ChildWindow1 + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + ' Create a window and make the current window its owner + Dim ownedWindow As New ChildWindow1 + ownedWindow.Owner = Me + ownedWindow.Show() + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml new file mode 100644 index 0000000..192bbec --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml.vb new file mode 100644 index 0000000..8560ead --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/ClosingWindow.xaml.vb @@ -0,0 +1,6 @@ +Public Class ClosingWindow + Private Sub fileExitMenuItem_Click(sender As Object, e As RoutedEventArgs) + ' Close the current window + Me.Close() + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml new file mode 100644 index 0000000..1cb5b5f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml @@ -0,0 +1,11 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml.vb new file mode 100644 index 0000000..f66a074 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/CustomMediaPlayerWindow.xaml.vb @@ -0,0 +1,11 @@ +Public Class CustomMediaPlayerWindow + Private Sub Window_Activated(sender As Object, e As EventArgs) + ' Continue playing media if window Is activated + mediaElement.Play() + End Sub + + Private Sub Window_Deactivated(sender As Object, e As EventArgs) + ' Pause playing if media is being played and window is deactivated + mediaElement.Pause() + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml new file mode 100644 index 0000000..336ab0f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml.vb new file mode 100644 index 0000000..142cdb3 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/DataWindow.xaml.vb @@ -0,0 +1,24 @@ +Public Class DataWindow + + Private _isDataDirty As Boolean + + Private Sub documentTextBox_TextChanged(sender As Object, e As TextChangedEventArgs) + _isDataDirty = True + End Sub + + Private Sub Window_Closing(sender As Object, e As ComponentModel.CancelEventArgs) + + ' If data is dirty, prompt user and ask for a response + If _isDataDirty Then + Dim result = MessageBox.Show("Document has changed. Close without saving?", + "Question", + MessageBoxButton.YesNo) + + ' User doesn't want to close, cancel closure + If result = MessageBoxResult.No Then + e.Cancel = True + End If + End If + + End Sub +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml new file mode 100644 index 0000000..b111b6b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml.vb new file mode 100644 index 0000000..77f9c9e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/Final.xaml.vb @@ -0,0 +1,9 @@ +Public Class Final + ' + Private Sub ButtonAddName_Click(sender As Object, e As RoutedEventArgs) + If Not String.IsNullOrWhiteSpace(txtName.Text) And Not lstNames.Items.Contains(txtName.Text) Then + lstNames.Items.Add(txtName.Text) + End If + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/WindowsOverviewVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/WindowsOverviewVB.vbproj new file mode 100644 index 0000000..0dc12ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index/vb/WindowsOverviewVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + WindowsOverview + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml new file mode 100644 index 0000000..125ef1f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml.cs new file mode 100644 index 0000000..46035de --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class App : Application + { + private void Application_Startup(object sender, StartupEventArgs e) + { + // Create the window + Window1 window = new Window1(); + + // Open the window + window.Show(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml new file mode 100644 index 0000000..33b2bae --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml @@ -0,0 +1,12 @@ + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml.cs new file mode 100644 index 0000000..77fdd6e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/Window1.xaml.cs @@ -0,0 +1,17 @@ +using System.Windows; + +namespace WindowsOverview +{ + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + MessageBox.Show("Button was clicked."); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/WindowsOverview.csproj b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/WindowsOverview.csproj new file mode 100644 index 0000000..453da2b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/csharp/WindowsOverview.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net5.0-windows + true + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml new file mode 100644 index 0000000..7d338d8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml.vb new file mode 100644 index 0000000..5bde547 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Application.xaml.vb @@ -0,0 +1,11 @@ +Class Application + + Private Sub Application_Startup(sender As Object, e As StartupEventArgs) + ' Create the window + Dim window As New Window1 + + ' Open the window + window.Show() + End Sub + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Class1.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Class1.vb new file mode 100644 index 0000000..875798b --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Class1.vb @@ -0,0 +1,3 @@ +Public Class Class1 + +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml new file mode 100644 index 0000000..86bc7c6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml.vb b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml.vb new file mode 100644 index 0000000..8b7b212 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/Window1.xaml.vb @@ -0,0 +1,9 @@ +Public Class Window1 + ' + Private Sub ButtonAddName_Click(sender As Object, e As RoutedEventArgs) + If Not String.IsNullOrWhiteSpace(txtName.Text) And Not lstNames.Items.Contains(txtName.Text) Then + lstNames.Items.Add(txtName.Text) + End If + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/WindowsOverviewVB.vbproj b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/WindowsOverviewVB.vbproj new file mode 100644 index 0000000..0dc12ce --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/windows/snippets/index_2/vb/WindowsOverviewVB.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + WindowsOverview + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md b/dotnet-desktop-guide/net/wpf/xaml/index.md similarity index 63% rename from dotnet-desktop-guide/net/wpf/fundamentals/xaml.md rename to dotnet-desktop-guide/net/wpf/xaml/index.md index 4ecbde2..e3f3544 100644 --- a/dotnet-desktop-guide/net/wpf/fundamentals/xaml.md +++ b/dotnet-desktop-guide/net/wpf/xaml/index.md @@ -2,7 +2,7 @@ title: XAML overview description: Learn how the XAML language is structured and implemented by Windows Presentation Foundation (WPF) for .NET. author: adegeo -ms.date: 12/03/2020 +ms.date: 04/12/2021 ms.author: adegeo ms.topic: overview dev_langs: @@ -36,13 +36,13 @@ XAML is a declarative markup language. As applied to the .NET Core programming m When represented as text, XAML files are XML files that generally have the `.xaml` extension. The files can be encoded by any XML encoding, but encoding as UTF-8 is typical. -The following example shows how you might create a button as part of a UI. This example is intended to give you a flavor of how XAML represents common UI programming metaphors (it is not a complete sample). +The following example shows how you might create a button as part of a UI. This example is intended to give you a flavor of how XAML represents common UI programming metaphors (it's not a complete sample). -[!code-xaml[XAMLOvwSupport#DirtSimple](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#dirtsimple)] +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="simple"::: ## XAML syntax in brief -The following sections explain the basic forms of XAML syntax, and give a short markup example. These sections are not intended to provide complete information about each syntax form, such as how these are represented in the backing type system. For more information about the specifics of XAML syntax, see [XAML Syntax In Detail](../../../framework/wpf/advanced/xaml-syntax-in-detail.md). +The following sections explain the basic forms of XAML syntax, and give a short markup example. These sections aren't intended to provide complete information about each syntax form, such as how these are represented in the backing type system. For more information about the specifics of XAML syntax, see [XAML Syntax In Detail](../../../framework/wpf/advanced/xaml-syntax-in-detail.md). Much of the material in the next few sections will be elementary to you if you have previous familiarity with the XML language. This is a consequence of one of the basic design principles of XAML. The XAML language defines concepts of its own, but these concepts work within the XML language and markup form. @@ -50,9 +50,9 @@ Much of the material in the next few sections will be elementary to you if you h An object element typically declares an instance of a type. That type is defined in the assemblies referenced by the technology that uses XAML as a language. -Object element syntax always starts with an opening angle bracket (`<`). This is followed by the name of the type where you want to create an instance. (The name can include a prefix, a concept that will be explained later.) After this, you can optionally declare attributes on the object element. To complete the object element tag, end with a closing angle bracket (`>`). You can instead use a self-closing form that does not have any content, by completing the tag with a forward slash and closing angle bracket in succession (`/>`). For example, look at the previously shown markup snippet again. +Object element syntax always starts with an opening angle bracket (`<`). This is followed by the name of the type where you want to create an instance. (The name can include a prefix, a concept that will be explained later.) After this, you can optionally declare attributes on the object element. To complete the object element tag, end with a closing angle bracket (`>`). You can instead use a self-closing form that doesn't have any content, by completing the tag with a forward slash and closing angle bracket in succession (`/>`). For example, look at the previously shown markup snippet again. -[!code-xaml[XAMLOvwSupport#DirtSimple](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#dirtsimple)] +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="Simple"::: This specifies two object elements: `` (with content, and a closing tag later), and ``. +- The class must declare a content property, and that content property must be of a type assignable to a string (the type could be ). For instance, any uses as its content property and it's type , and this supports the following usage on a such as a : ``. - The type must declare a type converter, in which case the text content is used as initialization text for that type converter. For example, `Blue` converts the content value of `Blue` into a brush. This case is less common in practice. @@ -132,81 +114,66 @@ A small number of XAML elements can directly process text as their content. To e Consider this example. -```xaml - - - - -``` +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="ContentCollection1"::: Here, each is a child element of . This is a streamlined and intuitive markup that omits two tags for two different reasons. - **Omitted StackPanel.Children property element:** derives from . defines as its XAML content property. -- **Omitted UIElementCollection object element:** The property takes the type , which implements . The collection's element tag can be omitted, based on the XAML rules for processing collections such as . (In this case, actually cannot be instantiated because it does not expose a parameterless constructor, and that is why the object element is shown commented out). +- **Omitted UIElementCollection object element:** The property takes the type , which implements . The collection's element tag can be omitted, based on the XAML rules for processing collections such as . (In this case, actually can't be instantiated because it doesn't expose a parameterless constructor, and that is why the object element is shown commented out). -```xaml - - - - - - - - -``` +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="ContentCollection2"::: ### Attribute syntax (events) Attribute syntax can also be used for members that are events rather than properties. In this case, the attribute's name is the name of the event. In the WPF implementation of events for XAML, the attribute's value is the name of a handler that implements that event's delegate. For example, the following markup assigns a handler for the event to a created in markup: -[!code-xaml[XAMLOvwSupport#ButtonWithCodeBehind](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml#buttonwithcodebehind)] +```xaml + +``` -There is more to events and XAML in WPF than just this example of the attribute syntax. For example, you might wonder what the `ClickHandler` referenced here represents and how it is defined. This will be explained in the upcoming [Events and XAML code-behind](#events-and-xaml-code-behind) section of this article. +There's more to events and XAML in WPF than just this example of the attribute syntax. For example, you might wonder what the `ClickHandler` referenced here represents and how it's defined. This will be explained in the upcoming [Events and XAML code-behind](#events-and-xaml-code-behind) section of this article. ## Case and white space in XAML -In general, XAML is case-sensitive. For purposes of resolving backing types, WPF XAML is case-sensitive by the same rules that the CLR is case-sensitive. Object elements, property elements, and attribute names must all be specified by using the sensitive casing when compared by name to the underlying type in the assembly, or to a member of a type. XAML language keywords and primitives are also case-sensitive. Values are not always case-sensitive. Case sensitivity for values will depend on the type converter behavior associated with the property that takes the value, or the property value type. For example, properties that take the type can take either `true` or `True` as equivalent values, but only because the native WPF XAML parser type conversion for string to already permits these as equivalents. +In general, XAML is case-sensitive. For purposes of resolving backing types, WPF XAML is case-sensitive by the same rules that the CLR is case-sensitive. Object elements, property elements, and attribute names must all be specified by using the sensitive casing when compared by name to the underlying type in the assembly, or to a member of a type. XAML language keywords and primitives are also case-sensitive. Values aren't always case-sensitive. Case sensitivity for values will depend on the type converter behavior associated with the property that takes the value, or the property value type. For example, properties that take the type can take either `true` or `True` as equivalent values, but only because the native WPF XAML parser type conversion for string to already permits these as equivalents. -WPF XAML processors and serializers will ignore or drop all nonsignificant white space, and will normalize any significant white space. This is consistent with the default white-space behavior recommendations of the XAML specification. This behavior is only of consequence when you specify strings within XAML content properties. In simplest terms, XAML converts space, linefeed, and tab characters into spaces, and then preserves one space if found at either end of a contiguous string. The full explanation of XAML white-space handling is not covered in this article. For more information, see [White space processing in XAML](../../../xaml-services/white-space-processing.md). +WPF XAML processors and serializers will ignore or drop all nonsignificant white space, and will normalize any significant white space. This is consistent with the default white-space behavior recommendations of the XAML specification. This behavior is only of consequence when you specify strings within XAML content properties. In simplest terms, XAML converts space, linefeed, and tab characters into spaces, and then preserves one space if found at either end of a contiguous string. The full explanation of XAML white-space handling isn't covered in this article. For more information, see [White space processing in XAML](../../../xaml-services/white-space-processing.md). ## Markup extensions Markup extensions are a XAML language concept. When used to provide the value of an attribute syntax, curly braces (`{` and `}`) indicate a markup extension usage. This usage directs the XAML processing to escape from the general treatment of attribute values as either a literal string or a string-convertible value. -The most common markup extensions used in WPF app programming are [`Binding`](../../../framework/wpf/advanced/binding-markup-extension.md), used for data binding expressions, and the resource references [`StaticResource`](../../../framework/wpf/advanced/staticresource-markup-extension.md) and [`DynamicResource`](../../../framework/wpf/advanced/dynamicresource-markup-extension.md). By using markup extensions, you can use attribute syntax to provide values for properties even if that property does not support an attribute syntax in general. Markup extensions often use intermediate expression types to enable features such as deferring values or referencing other objects that are only present at run-time. +The most common markup extensions used in WPF app programming are [`Binding`](../../../framework/wpf/advanced/binding-markup-extension.md), used for data binding expressions, and the resource references [`StaticResource`](../../../framework/wpf/advanced/staticresource-markup-extension.md) and [`DynamicResource`](../../../framework/wpf/advanced/dynamicresource-markup-extension.md). By using markup extensions, you can use attribute syntax to provide values for properties even if that property doesn't support an attribute syntax in general. Markup extensions often use intermediate expression types to enable features such as deferring values or referencing other objects that are only present at run-time. For example, the following markup sets the value of the property using attribute syntax. The property takes an instance of the class, which by default could not be instantiated by an attribute syntax string. But in this case, the attribute references a particular markup extension, `StaticResource`. When that markup extension is processed, it returns a reference to a style that was previously instantiated as a keyed resource in a resource dictionary. -[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources)] -[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources2](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources2)] -[!code-xaml[FEResourceSH_snip#XAMLOvwShortResources3](~/samples/snippets/csharp/VS_Snippets_Wpf/FEResourceSH_snip/CS/page1.xaml#xamlovwshortresources3)] +:::code language="xaml" source="./snippets/index/csharp/Window1.xaml" highlight="7-10,12" ::: For a reference listing of all markup extensions for XAML implemented specifically in WPF, see [WPF XAML Extensions](../../../framework/wpf/advanced/wpf-xaml-extensions.md). For a reference listing of the markup extensions that are defined by System.Xaml and are more widely available for .NET Core XAML implementations, see [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md). For more information about markup extension concepts, see [Markup Extensions and WPF XAML](../../../framework/wpf/advanced/markup-extensions-and-wpf-xaml.md). ## Type converters -In the [XAML Syntax in Brief](#xaml-syntax-in-brief) section, it was stated that the attribute value must be able to be set by a string. The basic, native handling of how strings are converted into other object types or primitive values is based on the type itself, in addition to native processing for certain types such as or . But many WPF types or members of those types extend the basic string attribute processing behavior in such a way that instances of more complex object types can be specified as strings and attributes. +In the [XAML Syntax in Brief](#xaml-syntax-in-brief) section, it was stated that the attribute value must be able to be set by a string. The basic, native handling of how strings are converted into other object types or primitive values is based on the type itself, along with native processing for certain types such as or . But many WPF types or members of those types extend the basic string attribute processing behavior in such a way that instances of more complex object types can be specified as strings and attributes. The structure is an example of a type that has a type conversion enabled for XAML usages. indicates measurements within a nested rectangle and is used as the value for properties such as . By placing a type converter on , all properties that use a are easier to specify in XAML because they can be specified as attributes. The following example uses a type conversion and attribute syntax to provide a value for a : -[!code-xaml[XAMLOvwSupport#MarginTCE](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#margintce)] +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="TypeConverter1" ::: The previous attribute syntax example is equivalent to the following more verbose syntax example, where the is instead set through property element syntax containing a object element. The four key properties of are set as attributes on the new instance: -[!code-xaml[XAMLOvwSupport#MarginVerbose](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#marginverbose)] +:::code language="xaml" source="./snippets/index/csharp/MainWindow.xaml" id="TypeConverter2" ::: > [!NOTE] -> There are also a limited number of objects where the type conversion is the only public way to set a property to that type without involving a subclass, because the type itself does not have a parameterless constructor. An example is . +> There are also a limited number of objects where the type conversion is the only public way to set a property to that type without involving a subclass, because the type itself doesn't have a parameterless constructor. An example is . For more information on type conversion, see [TypeConverters and XAML](../../../framework/wpf/advanced/typeconverters-and-xaml.md). -## XAML root elements and XAML namespaces +## Root elements and namespaces -A XAML file must have only one root element, in order to be both a well-formed XML file and a valid XAML file. For typical WPF scenarios, you use a root element that has a prominent meaning in the WPF app model (for example, or for a page, for an external dictionary, or for the app definition). The following example shows the root element of a typical XAML file for a WPF page, with the root element of . +A XAML file must have only one root element, to be both a well-formed XML file and a valid XAML file. For typical WPF scenarios, you use a root element that has a prominent meaning in the WPF app model (for example, or for a page, for an external dictionary, or for the app definition). The following example shows the root element of a typical XAML file for a WPF page, with the root element of . -[!code-xaml[XAMLOvwSupport#RootOnly](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#rootonly)] -[!code-xaml[XAMLOvwSupport#RootOnly2](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page2.xaml#rootonly2)] +:::code language="xaml" source="./snippets/index/csharp/Page1.xaml" ::: The root element also contains the attributes `xmlns` and `xmlns:x`. These attributes indicate to a XAML processor which XAML namespaces contain the type definitions for backing types that the markup will reference as elements. The `xmlns` attribute specifically indicates the default XAML namespace. Within the default XAML namespace, object elements in the markup can be specified without a prefix. For most WPF app scenarios, and for almost all of the examples given in the WPF sections of the SDK, the default XAML namespace is mapped to the WPF namespace `http://schemas.microsoft.com/winfx/2006/xaml/presentation`. The `xmlns:x` attribute indicates an additional XAML namespace, which maps the XAML language namespace `http://schemas.microsoft.com/winfx/2006/xaml`. @@ -214,7 +181,7 @@ This usage of `xmlns` to define a scope for usage and mapping of a namescope is The `xmlns` attributes are only strictly necessary on the root element of each XAML file. `xmlns` definitions will apply to all descendant elements of the root element (this behavior is again consistent with the XML 1.0 specification for `xmlns`.) `xmlns` attributes are also permitted on other elements underneath the root, and would apply to any descendant elements of the defining element. However, frequent definition or redefinition of XAML namespaces can result in a XAML markup style that is difficult to read. -The WPF implementation of its XAML processor includes an infrastructure that has awareness of the WPF core assemblies. The WPF core assemblies are known to contain the types that support the WPF mappings to the default XAML namespace. This is enabled through configuration that is part of your project build file and the WPF build and project systems. Therefore, declaring the default XAML namespace as the default `xmlns` is all that is necessary in order to reference XAML elements that come from WPF assemblies. +The WPF implementation of its XAML processor includes an infrastructure that has awareness of the WPF core assemblies. The WPF core assemblies are known to contain the types that support the WPF mappings to the default XAML namespace. This is enabled through configuration that is part of your project build file and the WPF build and project systems. Therefore, declaring the default XAML namespace as the default `xmlns` is all that is necessary to reference XAML elements that come from WPF assemblies. ### The x: prefix @@ -224,15 +191,15 @@ In the previous root element example, the prefix `x:` was used to map the XAML n - [x:Class](../../../xaml-services/xclass-directive.md): Specifies the CLR namespace and class name for the class that provides code-behind for a XAML page. You must have such a class to support code-behind per the WPF programming model, and therefore you almost always see `x:` mapped, even if there are no resources. -- [x:Name](../../../xaml-services/xname-directive.md): Specifies a run-time object name for the instance that exists in run-time code after an object element is processed. In general, you will frequently use a WPF-defined equivalent property for [x:Name](../../../xaml-services/xname-directive.md). Such properties map specifically to a CLR backing property and are thus more convenient for app programming, where you frequently use run-time code to find the named elements from initialized XAML. The most common such property is . You might still use [x:Name](../../../xaml-services/xname-directive.md) when the equivalent WPF framework-level property is not supported in a particular type. This occurs in certain animation scenarios. +- [x:Name](../../../xaml-services/xname-directive.md): Specifies a run-time object name for the instance that exists in run-time code after an object element is processed. In general, you will frequently use a WPF-defined equivalent property for [x:Name](../../../xaml-services/xname-directive.md). Such properties map specifically to a CLR backing property and are thus more convenient for app programming, where you frequently use run-time code to find the named elements from initialized XAML. The most common such property is . You might still use [x:Name](../../../xaml-services/xname-directive.md) when the equivalent WPF framework-level property isn't supported in a particular type. This occurs in certain animation scenarios. -- [x:Static](../../../xaml-services/xstatic-markup-extension.md): Enables a reference that returns a static value that is not otherwise a XAML-compatible property. +- [x:Static](../../../xaml-services/xstatic-markup-extension.md): Enables a reference that returns a static value that isn't otherwise a XAML-compatible property. - [x:Type](../../../xaml-services/xtype-markup-extension.md): Constructs a reference based on a type name. This is used to specify attributes that take , such as , although frequently the property has native string-to- conversion in such a way that the [x:Type](../../../xaml-services/xtype-markup-extension.md) markup extension usage is optional. -There are additional programming constructs in the `x:` prefix/XAML namespace, which are not as common. For details, see [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md). +There are additional programming constructs in the `x:` prefix/XAML namespace, which aren't as common. For details, see [XAML Namespace (x:) Language Features](../../../xaml-services/namespace-language-features.md). -## Custom prefixes and custom types in XAML +## Custom prefixes and custom types For your own custom assemblies, or for assemblies outside the WPF core of **PresentationCore**, **PresentationFramework** and **WindowsBase**, you can specify the assembly as part of a custom `xmlns` mapping. You can then reference types from that assembly in your XAML, so long as that type is correctly implemented to support the XAML usages you are attempting. @@ -261,70 +228,75 @@ Most WPF apps consist of both XAML markup and code-behind. Within a project, the In the examples so far, you have seen several buttons, but none of these buttons had any logical behavior associated with them yet. The primary application-level mechanism for adding a behavior for an object element is to use an existing event of the element class, and to write a specific handler for that event that is invoked when that event is raised at run-time. The event name and the name of the handler to use are specified in the markup, whereas the code that implements your handler is defined in the code-behind. -[!code-xaml[XAMLOvwSupport#ButtonWithCodeBehind](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml#buttonwithcodebehind)] +:::code language="xaml" source="./snippets/index/csharp/Window2.xaml" ::: -[!code-csharp[XAMLOvwSupport#ButtonWithCodeBehindHandler](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page3.xaml.cs#buttonwithcodebehindhandler)] -[!code-vb[XAMLOvwSupport#ButtonWithCodeBehindHandler](~/samples/snippets/visualbasic/VS_Snippets_Wpf/XAMLOvwSupport/VisualBasic/Page1.xaml.vb#buttonwithcodebehindhandler)] +:::code language="csharp" source="./snippets/index/csharp/Window2.xaml.cs" id="ButtonClickHandler" ::: +:::code language="vb" source="./snippets/index/vb/Window2.xaml.vb" id="ButtonClickHandler" ::: Notice that the code-behind file uses the CLR namespace `ExampleNamespace` and declares `ExamplePage` as a partial class within that namespace. This parallels the `x:Class` attribute value of `ExampleNamespace`.`ExamplePage` that was provided in the markup root. The WPF markup compiler will create a partial class for any compiled XAML file, by deriving a class from the root element type. When you provide code-behind that also defines the same partial class, the resulting code is combined within the same namespace and class of the compiled app. For more information about requirements for code-behind programming in WPF, see [Code-behind, Event Handler, and Partial Class Requirements in WPF](../../../framework/wpf/advanced/code-behind-and-xaml-in-wpf.md#code-behind-event-handler-and-partial-class-requirements-in-wpf). -If you do not want to create a separate code-behind file, you can also inline your code in a XAML file. However, inline code is a less versatile technique that has substantial limitations. For more information, see [Code-Behind and XAML in WPF](../../../framework/wpf/advanced/code-behind-and-xaml-in-wpf.md). +If you don't want to create a separate code-behind file, you can also inline your code in a XAML file. However, inline code is a less versatile technique that has substantial limitations. For more information, see [Code-Behind and XAML in WPF](../../../framework/wpf/advanced/code-behind-and-xaml-in-wpf.md). ### Routed events -A particular event feature that is fundamental to WPF is a routed event. Routed events enable an element to handle an event that was raised by a different element, as long as the elements are connected through a tree relationship. When specifying event handling with a XAML attribute, the routed event can be listened for and handled on any element, including elements that do not list that particular event in the class members table. This is accomplished by qualifying the event name attribute with the owning class name. For instance, the parent `StackPanel` in the ongoing `StackPanel` / `Button` example could register a handler for the child element button's event by specifying the attribute `Button.Click` on the `StackPanel` object element, with your handler name as the attribute value. For more information, see [Routed Events Overview](../../../framework/wpf/advanced/routed-events-overview.md). +A particular event feature that is fundamental to WPF is a routed event. Routed events enable an element to handle an event that was raised by a different element, as long as the elements are connected through a tree relationship. When specifying event handling with a XAML attribute, the routed event can be listened for and handled on any element, including elements that don't list that particular event in the class members table. This is accomplished by qualifying the event name attribute with the owning class name. For instance, the parent `StackPanel` in the ongoing `StackPanel` / `Button` example could register a handler for the child element button's event by specifying the attribute `Button.Click` on the `StackPanel` object element, with your handler name as the attribute value. For more information, see [Routed Events Overview](../../../framework/wpf/advanced/routed-events-overview.md). -## XAML named elements +## Named elements -By default, the object instance that is created in an object graph by processing a XAML object element does not possess a unique identifier or object reference. In contrast, if you call a constructor in code, you almost always use the constructor result to set a variable to the constructed instance, so that you can reference the instance later in your code. In order to provide standardized access to objects that were created through a markup definition, XAML defines the [x:Name attribute](../../../xaml-services/xname-directive.md). You can set the value of the `x:Name` attribute on any object element. In your code-behind, the identifier you choose is equivalent to an instance variable that refers to the constructed instance. In all respects, named elements function as if they were object instances (the name references that instance), and your code-behind can reference the named elements to handle run-time interactions within the app. This connection between instances and variables is accomplished by the WPF XAML markup compiler, and more specifically involve features and patterns such as that will not be discussed in detail in this article. +By default, the object instance that is created in an object graph by processing a XAML object element doesn't have a unique identifier or object reference. In contrast, if you call a constructor in code, you almost always use the constructor result to set a variable to the constructed instance, so that you can reference the instance later in your code. To provide standardized access to objects that were created through a markup definition, XAML defines the [x:Name attribute](../../../xaml-services/xname-directive.md). You can set the value of the `x:Name` attribute on any object element. In your code-behind, the identifier you choose is equivalent to an instance variable that refers to the constructed instance. In all respects, named elements function as if they were object instances (the name references that instance), and your code-behind can reference the named elements to handle run-time interactions within the app. This connection between instances and variables is accomplished by the WPF XAML markup compiler, and more specifically involve features and patterns such as that won't be discussed in detail in this article. -WPF framework-level XAML elements inherit a property, which is equivalent to the XAML defined `x:Name` attribute. Certain other classes also provide property-level equivalents for `x:Name`, which is also generally defined as a `Name` property. Generally speaking, if you cannot find a `Name` property in the members table for your chosen element/type, use `x:Name` instead. The `x:Name` values will provide an identifier to a XAML element that can be used at run-time, either by specific subsystems or by utility methods such as . +WPF framework-level XAML elements inherit a property, which is equivalent to the XAML defined `x:Name` attribute. Certain other classes also provide property-level equivalents for `x:Name`, which is also usually defined as a `Name` property. Generally speaking, if you can't find a `Name` property in the members table for your chosen element/type, use `x:Name` instead. The `x:Name` values will provide an identifier to a XAML element that can be used at run-time, either by specific subsystems or by utility methods such as . The following example sets on a element. Then, a handler on a within that references the through its instance reference `buttonContainer` as set by . -[!code-xaml[XAMLOvwSupport#NamedE](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#namede)] -[!code-xaml[XAMLOvwSupport#NamedE2](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml#namede2)] +:::code language="xaml" source="./snippets/index/csharp/Window3.xaml" id="RemoveControl" ::: -[!code-csharp[XAMLOvwSupport#NameCode](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page7.xaml.cs#namecode)] -[!code-vb[XAMLOvwSupport#NameCode](~/samples/snippets/visualbasic/VS_Snippets_Wpf/XAMLOvwSupport/VisualBasic/Page1.xaml.vb#namecode)] +:::code language="csharp" source="./snippets/index/csharp/Window3.xaml.cs" id="RemoveControl" ::: +:::code language="vb" source="./snippets/index/vb/Window3.xaml.vb" id="RemoveControl" ::: -Just like a variable, the XAML name for an instance is governed by a concept of scope, so that names can be enforced to be unique within a certain scope that is predictable. The primary markup that defines a page denotes one unique XAML namescope, with the XAML namescope boundary being the root element of that page. However, other markup sources can interact with a page at run-time, such as styles or templates within styles, and such markup sources often have their own XAML namescopes that do not necessarily connect with the XAML namescope of the page. For more information on `x:Name` and XAML namescopes, see , [x:Name Directive](../../../xaml-services/xname-directive.md), or [WPF XAML Namescopes](../../../framework/wpf/advanced/wpf-xaml-namescopes.md). +Just like a variable, the XAML name for an instance is governed by a concept of scope, so that names can be enforced to be unique within a certain scope that is predictable. The primary markup that defines a page denotes one unique XAML namescope, with the XAML namescope boundary being the root element of that page. However, other markup sources can interact with a page at run-time, such as styles or templates within styles, and such markup sources often have their own XAML namescopes that don't necessarily connect with the XAML namescope of the page. For more information on `x:Name` and XAML namescopes, see , [x:Name Directive](../../../xaml-services/xname-directive.md), or [WPF XAML Namescopes](../../../framework/wpf/advanced/wpf-xaml-namescopes.md). ## Attached properties and attached events -XAML specifies a language feature that enables certain properties or events to be specified on any element, regardless of whether the property or event exists in the type's definitions for the element it is being set on. The properties version of this feature is called an attached property, the events version is called an attached event. Conceptually, you can think of attached properties and attached events as global members that can be set on any XAML element/object instance. However, that element/class or a larger infrastructure must support a backing property store for the attached values. +XAML specifies a language feature that enables certain properties or events to be specified on any element, even if the property or event doesn't exists in the type's definitions for the element it's being set on. The properties version of this feature is called an attached property, the events version is called an attached event. Conceptually, you can think of attached properties and attached events as global members that can be set on any XAML element/object instance. However, that element/class or a larger infrastructure must support a backing property store for the attached values. Attached properties in XAML are typically used through attribute syntax. In attribute syntax, you specify an attached property in the form `ownerType.propertyName`. -Superficially, this resembles a property element usage, but in this case the `ownerType` you specify is always a different type than the object element where the attached property is being set. `ownerType` is the type that provides the accessor methods that are required by a XAML processor in order to get or set the attached property value. +Superficially, this resembles a property element usage, but in this case the `ownerType` you specify is always a different type than the object element where the attached property is being set. `ownerType` is the type that provides the accessor methods that are required by a XAML processor to get or set the attached property value. The most common scenario for attached properties is to enable child elements to report a property value to their parent element. -The following example illustrates the attached property. The class defines the accessors for and therefore owns the attached property. The class also includes logic that iterates its child elements and specifically checks each element for a set value of . If a value is found, that value is used during layout to position the child elements. Use of the attached property and this positioning capability is in fact the motivating scenario for the class. +The following example illustrates the attached property. The class defines the accessors for and owns the attached property. The class also includes logic that iterates its child elements and specifically checks each element for a set value of . If a value is found, that value is used during layout to position the child elements. Use of the attached property and this positioning capability is in fact the motivating scenario for the class. -[!code-xaml[XAMLOvwSupport#DockAP](~/samples/snippets/csharp/VS_Snippets_Wpf/XAMLOvwSupport/CSharp/page8.xaml#dockap)] +:::code language="xaml" source="./snippets/index/csharp/Window3.xaml" id="DockPanel" ::: In WPF, most or all the attached properties are also implemented as dependency properties. For more information, see [Attached Properties Overview](../../../framework/wpf/advanced/attached-properties-overview.md). Attached events use a similar `ownerType.eventName` form of attribute syntax. Just like the non-attached events, the attribute value for an attached event in XAML specifies the name of the handler method that is invoked when the event is handled on the element. Attached event usages in WPF XAML are less common. For more information, see [Attached Events Overview](../../../framework/wpf/advanced/attached-events-overview.md). -## Base types and XAML +## Base types -Underlying WPF XAML and its XAML namespace is a collection of types that correspond to CLR objects in addition to markup elements for XAML. However, not all classes can be mapped to elements. Abstract classes, such as , and certain non-abstract base classes, are used for inheritance in the CLR objects model. Base classes, including abstract ones, are still important to XAML development because each of the concrete XAML elements inherits members from some base class in its hierarchy. Often these members include properties that can be set as attributes on the element, or events that can be handled. is the concrete base UI class of WPF at the WPF framework level. When designing UI, you will use various shape, panel, decorator, or control classes, which all derive from . A related base class, , supports document-oriented elements that work well for a flow layout presentation, using APIs that deliberately mirror the APIs in . The combination of attributes at the element level and a CLR object model provides you with a set of common properties that are settable on most concrete XAML elements, regardless of the specific XAML element and its underlying type. +Underlying WPF XAML and its XAML namespace is a collection of types that correspond to CLR objects and markup elements for XAML. However, not all classes can be mapped to elements. Abstract classes, such as , and certain non-abstract base classes, are used for inheritance in the CLR objects model. Base classes, including abstract ones, are still important to XAML development because each of the concrete XAML elements inherits members from some base class in its hierarchy. Often these members include properties that can be set as attributes on the element, or events that can be handled. is the concrete base UI class of WPF at the WPF framework level. When designing UI, you will use various shape, panel, decorator, or control classes, which all derive from . A related base class, , supports document-oriented elements that work well for a flow layout presentation, using APIs that deliberately mirror the APIs in . The combination of attributes at the element level and a CLR object model provides you with a set of common properties that are settable on most concrete XAML elements, regardless of the specific XAML element and its underlying type. -## XAML security +## Security -XAML is a markup language that directly represents object instantiation and execution. Therefore, elements created in XAML have the same ability to interact with system resources (network access, file system IO, for example) as the equivalent generated code does. XAML loaded in to a fully trusted app has the same access to the system resources as the hosting app does. +XAML is a markup language that directly represents object instantiation and execution. That's why elements created in XAML have the same ability to interact with system resources (network access, file system IO, for example) as your app code does. XAML also has the same access to the system resources as the hosting app does. ### Code Access Security (CAS) in WPF Unlike .NET Framework, WPF for .NET doesn't support CAS. For more information, see [Code Access Security differences](../migration/differences-from-net-framework.md#code-access-security). -## Loading XAML from code +## Load XAML from code -XAML can be used to define all of the UI, but it is sometimes also appropriate to define just a piece of the UI in XAML. This capability could be used to enable partial customization, local storage of information, using XAML to provide a business object, or a variety of possible scenarios. The key to these scenarios is the class and its method. The input is a XAML file, and the output is an object that represents all of the run-time tree of objects that was created from that markup. You then can insert the object to be a property of another object that already exists in the app. So long as the property is an appropriate property in the content model that has eventual display capabilities and that will notify the execution engine that new content has been added into the app, you can modify a running app's contents easily by loading in XAML. +XAML can be used to define all of the UI, but it's sometimes also appropriate to define just a piece of the UI in XAML. This capability could be used to: + +- Enable partial customization. +- Local storage of UI information. +- Model a business object. + +The key to these scenarios is the class and its method. The input is a XAML file, and the output is an object that represents all of the run-time tree of objects that was created from that markup. You then can insert the object to be a property of another object that already exists in the app. As long as the property is in the content model and has display capabilities that will notify the execution engine that new content has been added into the app, you can modify a running app's contents easily by dynamically loading in XAML. ## See also diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml new file mode 100644 index 0000000..0779afd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml.cs new file mode 100644 index 0000000..bd6d382 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/App.xaml.cs @@ -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 index +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/AssemblyInfo.cs @@ -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) +)] diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml new file mode 100644 index 0000000..e1c6f63 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000..f3299a4 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/MainWindow.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace index +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml new file mode 100644 index 0000000..6886989 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml @@ -0,0 +1,6 @@ + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml.cs new file mode 100644 index 0000000..3a0ccb2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Page1.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace index +{ + /// + /// Interaction logic for Page1.xaml + /// + public partial class Page1 : Page + { + public Page1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml new file mode 100644 index 0000000..7b876d5 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml.cs new file mode 100644 index 0000000..840df2e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window1.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace index +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml new file mode 100644 index 0000000..5bfb019 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml.cs new file mode 100644 index 0000000..057cf29 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window2.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace index +{ + /// + /// Interaction logic for Window2.xaml + /// + public partial class Window2 : Window + { + public Window2() + { + InitializeComponent(); + } + + // + private void Button_Click(object sender, RoutedEventArgs e) + { + var buttonControl = (Button)e.Source; + buttonControl.Foreground = Brushes.Red; + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml new file mode 100644 index 0000000..724c913 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml.cs b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml.cs new file mode 100644 index 0000000..337ae3f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/Window3.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace index +{ + /// + /// Interaction logic for Window3.xaml + /// + public partial class Window3 : Window + { + public Window3() + { + InitializeComponent(); + } + + // + private void RemoveThis_Click(object sender, RoutedEventArgs e) + { + var element = (FrameworkElement)e.Source; + + if (buttonContainer.Children.Contains(element)) + buttonContainer.Children.Remove(element); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/index.csproj b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/index.csproj new file mode 100644 index 0000000..407932c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/csharp/index.csproj @@ -0,0 +1,9 @@ + + + + WinExe + net5.0-windows + true + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml new file mode 100644 index 0000000..a376807 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml.vb new file mode 100644 index 0000000..f3e8ffd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/AssemblyInfo.vb @@ -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) + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml new file mode 100644 index 0000000..27dc113 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml.vb new file mode 100644 index 0000000..603c598 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/MainWindow.xaml.vb @@ -0,0 +1,3 @@ +Class MainWindow + +End Class diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml new file mode 100644 index 0000000..41275a2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml.vb b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml.vb new file mode 100644 index 0000000..e97faa2 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window2.xaml.vb @@ -0,0 +1,8 @@ +Public Class Window2 + ' + Private Sub Button_Click(sender As Object, e As RoutedEventArgs) + Dim buttonControl = DirectCast(e.Source, Button) + buttonControl.Foreground = Brushes.Red + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml new file mode 100644 index 0000000..97615cc --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml.vb b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml.vb new file mode 100644 index 0000000..e8ddfc4 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/Window3.xaml.vb @@ -0,0 +1,11 @@ +Public Class Window3 + ' + Private Sub RemoveThis_Click(sender As Object, e As RoutedEventArgs) + Dim element = DirectCast(e.Source, FrameworkElement) + + If buttonContainer.Children.Contains(element) Then + buttonContainer.Children.Remove(element) + End If + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/index.vbproj b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/index.vbproj new file mode 100644 index 0000000..8ef0fb3 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/xaml/snippets/index/vb/index.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + index + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/xaml-services/index.md b/dotnet-desktop-guide/xaml-services/index.md index 58905c6..9d1f13f 100644 --- a/dotnet-desktop-guide/xaml-services/index.md +++ b/dotnet-desktop-guide/xaml-services/index.md @@ -1,5 +1,6 @@ --- title: "XAML Services" +description: "Describes the capabilities of a .NET XAML Services. Services include readers and writers, schema classes and schema support factories, attributing of classes, XAML language support, and other XAML language features." ms.date: "03/30/2017" helpviewer_keywords: - "XAML [XAML Services], System.Xaml concepts" @@ -29,7 +30,7 @@ Conceptual documentation for .NET XAML Services assumes that you have previous e - Using the `Lookup` or `Invoker` techniques to influence the XAML type system and how type backings are evaluated. -If you are looking for introductory material on XAML as a language, you might try [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md). That topic discusses XAML for an audience that is new both to Windows Presentation Foundation (WPF) and also to using XAML markup and XAML language features. Another useful document is the introductory material in the [XAML language specification](/previous-versions/msp-n-p/ff650760(v=pandp.10)). +If you are looking for introductory material on XAML as a language, you might try [XAML overview (WPF .NET)](../net/wpf/xaml/index.md). That topic discusses XAML for an audience that is new both to Windows Presentation Foundation (WPF) and also to using XAML markup and XAML language features. Another useful document is the introductory material in the [XAML language specification](/previous-versions/msp-n-p/ff650760(v=pandp.10)). ## .NET XAML Services and `System.Xaml` in the .NET Architecture diff --git a/dotnet-desktop-guide/xaml-services/type-converters-overview.md b/dotnet-desktop-guide/xaml-services/type-converters-overview.md index 672a07b..cf7da12 100644 --- a/dotnet-desktop-guide/xaml-services/type-converters-overview.md +++ b/dotnet-desktop-guide/xaml-services/type-converters-overview.md @@ -1,5 +1,6 @@ --- title: "Type Converters for XAML Overview" +description: "Type converters provide logic for an object writer that converts a string value in XAML markup into particular objects in an object graph." ms.date: "03/30/2017" helpviewer_keywords: - "XAML [XAML Services], type converters" @@ -115,4 +116,4 @@ If you are working with a XAML node stream, the action or end result of a type c - - [Type Converters and Markup Extensions for XAML](type-converters-and-markup-extensions.md) -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) diff --git a/dotnet-desktop-guide/xaml-services/white-space-processing.md b/dotnet-desktop-guide/xaml-services/white-space-processing.md index 4534166..567493f 100644 --- a/dotnet-desktop-guide/xaml-services/white-space-processing.md +++ b/dotnet-desktop-guide/xaml-services/white-space-processing.md @@ -1,5 +1,6 @@ --- title: "White-space processing in XAML" +description: "This article describes the XAML language rules regarding how white space is handled." ms.date: "03/30/2017" helpviewer_keywords: - "East Asian characters [XAML Services]" @@ -72,6 +73,6 @@ Also, certain inline elements that connote a line break in a flow document model ## See also -- [XAML overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) - [XML character entities and XAML](xml-character-entities.md) - [xml:space handling in XAML](xml-space-handling.md) diff --git a/dotnet-desktop-guide/xaml-services/xaml-2009-language-features.md b/dotnet-desktop-guide/xaml-services/xaml-2009-language-features.md index 04cf266..e4ff6ea 100644 --- a/dotnet-desktop-guide/xaml-services/xaml-2009-language-features.md +++ b/dotnet-desktop-guide/xaml-services/xaml-2009-language-features.md @@ -1,5 +1,6 @@ --- title: "XAML 2009 Language Features" +description: "Describes the language features specific to the XAML 2009 specification." ms.date: "03/30/2017" helpviewer_keywords: - "XAML 2009 [XAML Services]" @@ -31,4 +32,4 @@ For attributes that are backed by events, XAML 2006 presumes that markup compila ## See also -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) diff --git a/dotnet-desktop-guide/xaml-services/xamlname-grammar.md b/dotnet-desktop-guide/xaml-services/xamlname-grammar.md index d8a6524..26e6ff4 100644 --- a/dotnet-desktop-guide/xaml-services/xamlname-grammar.md +++ b/dotnet-desktop-guide/xaml-services/xamlname-grammar.md @@ -1,5 +1,6 @@ --- title: "XamlName Grammar" +description: "Describes what the XAML language specification related to XamlName Grammer." ms.date: "03/30/2017" helpviewer_keywords: - "DottedXamlName grammar [XAML Services]" @@ -42,7 +43,7 @@ Which assumes the following general category values as defined in the Unicode Ch | Nd | Number, Decimal | | Nl | Number, Letter | -XAML defines a second grammar, DottedXamlName, that is used for property and event qualified references, and also for attached members. For more information, see and [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md). +XAML defines a second grammar, DottedXamlName, that is used for property and event qualified references, and also for attached members. For more information, see and [XAML overview (WPF .NET)](../net/wpf/xaml/index.md). String values that are of type DottedXamlName must conform to the following grammar: diff --git a/dotnet-desktop-guide/xaml-services/xarguments-directive.md b/dotnet-desktop-guide/xaml-services/xarguments-directive.md index 42781c6..c597704 100644 --- a/dotnet-desktop-guide/xaml-services/xarguments-directive.md +++ b/dotnet-desktop-guide/xaml-services/xarguments-directive.md @@ -1,5 +1,6 @@ --- title: "x:Arguments Directive" +description: "The x:Arguments directive packages construction arguments for non-parameterless constructor object elements in XAML." ms.date: "03/30/2017" helpviewer_keywords: - "x:Arguments directive [XAML Services]" @@ -33,7 +34,7 @@ Packages construction arguments for a non-parameterless constructor object eleme ## XAML Values -||| +| Value | Description | |-|-| |`oneOrMoreObjectElements`|One or more object elements that specify arguments to be passed to the backing non-parameterless constructor or factory method.

Typical usage is to use initialization text within the object elements to specify the actual argument values. See Examples section.

The order of the elements is significant. The XAML types in order must match the types and type order of the backing constructor or factory method overload.| |`methodName`|The name of the factory method that should process any `x:Arguments` arguments.| @@ -107,4 +108,4 @@ switch (name) { ## See also - [Defining Custom Types for Use with .NET XAML Services](define-custom-types.md) -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) diff --git a/dotnet-desktop-guide/xaml-services/xcode-intrinsic-xaml-type.md b/dotnet-desktop-guide/xaml-services/xcode-intrinsic-xaml-type.md index 3ba624d..a63867a 100644 --- a/dotnet-desktop-guide/xaml-services/xcode-intrinsic-xaml-type.md +++ b/dotnet-desktop-guide/xaml-services/xcode-intrinsic-xaml-type.md @@ -1,5 +1,6 @@ --- title: "x:Code Intrinsic XAML Type" +description: "Describes how the x:Code XML type allows code to be compiled by the XAML processor." ms.date: "03/30/2017" f1_keywords: - "Code" @@ -48,4 +49,4 @@ Code declared within `x:Code` for WPF has several notable limitations: - [x:Class Directive](xclass-directive.md) - [Code-Behind and XAML in WPF](../framework/wpf/advanced/code-behind-and-xaml-in-wpf.md) -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) diff --git a/dotnet-desktop-guide/xaml-services/xkey-directive.md b/dotnet-desktop-guide/xaml-services/xkey-directive.md index 8c4d726..5902935 100644 --- a/dotnet-desktop-guide/xaml-services/xkey-directive.md +++ b/dotnet-desktop-guide/xaml-services/xkey-directive.md @@ -1,6 +1,7 @@ --- title: "x:Key Directive" ms.date: "03/30/2017" +description: "The x:Key directive identifies elements that are created and referenced in a XAML-defined dictionary." f1_keywords: - "xKey" - "Key" @@ -37,14 +38,14 @@ Uniquely identifies elements that are created and referenced in a XAML-defined d ## XAML Values -||| +| Value | Description | |-|-| |`stringKeyValue`|A text string to use as a key. The text string must conform to the [XamlName Grammar](xamlname-grammar.md).| |`markupExtensionUsage`|Within the markup extension delimiters {}, a markup extension usage that provides an object to use as a key. See Remarks.| ## Remarks - `x:Key` supports the XAML resource dictionary concept. XAML as a language doesn't define a resource dictionary implementation, that is left to specific UI frameworks. To learn more about how XAML resource dictionaries are implemented in WPF, see [XAML Resources](../net/wpf/fundamentals/xaml-resources-define.md). + `x:Key` supports the XAML resource dictionary concept. XAML as a language doesn't define a resource dictionary implementation, that is left to specific UI frameworks. To learn more about how XAML resource dictionaries are implemented in WPF, see [Overview of XAML resources (WPF .NET)](../net/wpf/systems/xaml-resources-overview.md). In XAML 2006 and WPF, `x:Key` must be provided as an attribute. You can still use nonstring keys, but this requires a markup extension usage in order to provide the nonstring value in attribute form. If you are using XAML 2009, `x:Key` can be specified as an element, to explicitly support dictionaries keyed by object types other than strings without requiring a markup extension intermediate. See the "XAML 2009" section in this topic. The remainder of the Remarks section applies specifically to the XAML 2006 implementation. @@ -60,7 +61,7 @@ Uniquely identifies elements that are created and referenced in a XAML-defined d - Some WPF types declare an implicit key for dictionary usage. For example, a with a , or a with a , can be in a and use the implicit key. -- WPF supports a merged resource dictionary concept. Keys can be shared between the merged dictionaries, and the shared key behavior can be accessed using . For more information, see [Merged Resource Dictionaries](../framework/wpf/advanced/merged-resource-dictionaries.md). +- WPF supports a merged resource dictionary concept. Keys can be shared between the merged dictionaries, and the shared key behavior can be accessed using . For more information, see [Merged resource dictionaries](../net/wpf/systems/xaml-resources-merged-dictionaries.md). In the overall WPF XAML implementation and application model, key uniqueness is not checked by the XAML markup compiler. Instead, missing or nonunique `x:Key` values cause load-time XAML parser errors. However, Visual Studio handling of dictionaries for WPF can often note such errors in the design phase. @@ -72,7 +73,7 @@ Uniquely identifies elements that are created and referenced in a XAML-defined d As stated previously, the value of a key can be supplied through a markup extension and can be other than a string value. An example WPF scenario is that the value of `x:Key` may be a [ComponentResourceKey](../framework/wpf/advanced/componentresourcekey-markup-extension.md). Certain controls expose a style key of that type for a custom style resource that influences part of the appearance and behavior of that control without totally replacing the style. An example of such a key is . - The WPF merged dictionary feature introduces additional considerations for key uniqueness and key lookup behavior. For more information, see [Merged Resource Dictionaries](../framework/wpf/advanced/merged-resource-dictionaries.md). + The WPF merged dictionary feature introduces additional considerations for key uniqueness and key lookup behavior. For more information, see [Merged resource dictionaries](../net/wpf/systems/xaml-resources-merged-dictionaries.md). ## XAML 2009 @@ -95,7 +96,7 @@ keyObject ### XAML Values -||| +| Value | Description | |-|-| |`keyObject`|Object element for the object that is used as the key for a given `object` in a specialized dictionary.| @@ -111,6 +112,6 @@ keyObject ## See also -- [XAML Resources](../net/wpf/fundamentals/xaml-resources-define.md) -- [Resources and Code](../framework/wpf/advanced/resources-and-code.md) +- [Overview of XAML resources (WPF .NET)](../net/wpf/systems/xaml-resources-overview.md) +- [Resources in code (WPF .NET)](../net/wpf/systems/xaml-resources-and-code.md) - [StaticResource Markup Extension](../framework/wpf/advanced/staticresource-markup-extension.md) diff --git a/dotnet-desktop-guide/xaml-services/xml-character-entities.md b/dotnet-desktop-guide/xaml-services/xml-character-entities.md index bae618c..da09213 100644 --- a/dotnet-desktop-guide/xaml-services/xml-character-entities.md +++ b/dotnet-desktop-guide/xaml-services/xml-character-entities.md @@ -1,5 +1,6 @@ --- title: "XML Character Entities and XAML" +description: "Describes how special characters are handled in XAML and general considerations for other XML concepts in XAML." ms.date: "03/30/2017" f1_keywords: - "&" @@ -59,7 +60,7 @@ XAML handles XML processing instructions according to XML specifications, which ## See also -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) - [Markup Extensions and WPF XAML](../framework/wpf/advanced/markup-extensions-and-wpf-xaml.md) - [XamlName Grammar](xamlname-grammar.md) - [White-space processing in XAML](white-space-processing.md) diff --git a/dotnet-desktop-guide/xaml-services/xml-space-handling.md b/dotnet-desktop-guide/xaml-services/xml-space-handling.md index 72eb904..27502c7 100644 --- a/dotnet-desktop-guide/xaml-services/xml-space-handling.md +++ b/dotnet-desktop-guide/xaml-services/xml-space-handling.md @@ -1,5 +1,6 @@ --- title: "xml:space Handling in XAML" +description: "Describes the xml:space attribute and how it affects white-space processing behavior within an object element." ms.date: "03/30/2017" helpviewer_keywords: - "XAML [XAML Services], xml:space attribute" @@ -39,4 +40,4 @@ For a complete discussion of white-space processing in XAML, see [White-space pr ## See also - [White-space processing in XAML](white-space-processing.md) -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) diff --git a/dotnet-desktop-guide/xaml-services/xnull-markup-extension.md b/dotnet-desktop-guide/xaml-services/xnull-markup-extension.md index 3e2056e..e7bf321 100644 --- a/dotnet-desktop-guide/xaml-services/xnull-markup-extension.md +++ b/dotnet-desktop-guide/xaml-services/xnull-markup-extension.md @@ -1,5 +1,6 @@ --- title: "x:Null Markup Extension" +description: "Describes how the x:Null markup extension is handled by XAML." ms.date: "03/30/2017" f1_keywords: - "NullExtension" @@ -44,5 +45,5 @@ Note that `null` is not necessarily the initial unset value for a reference-type ## See also - -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) - [Markup Extensions and WPF XAML](../framework/wpf/advanced/markup-extensions-and-wpf-xaml.md) diff --git a/dotnet-desktop-guide/xaml-services/xshared-attribute.md b/dotnet-desktop-guide/xaml-services/xshared-attribute.md index 1d7da66..481e4f2 100644 --- a/dotnet-desktop-guide/xaml-services/xshared-attribute.md +++ b/dotnet-desktop-guide/xaml-services/xshared-attribute.md @@ -1,5 +1,6 @@ --- title: "x:Shared Attribute" +description: "Describes the x:Shared attribute and how it modifies the WPF resource-retrieval behavior." ms.date: "03/30/2017" helpviewer_keywords: - "XAML [XAML Services], x:Shared attribute" @@ -29,7 +30,7 @@ In WPF, the default `x:Shared` condition for resources is `true`. This condition Modifying an object that is returned through a resource API, such as , or modifying an object directly within a , changes the original resource. If references to that resource were dynamic resource references, the consumers of that resource get the changed resource. -If references to the resource were static resource references, changes to the resource after [!INCLUDE[TLA2#tla_xaml](../includes/tla2sharptla-xaml-md.md)] processing time are irrelevant. For more information about static versus dynamic resource references, see [XAML Resources](../net/wpf/fundamentals/xaml-resources-define.md). +If references to the resource were static resource references, changes to the resource after [!INCLUDE[TLA2#tla_xaml](../includes/tla2sharptla-xaml-md.md)] processing time are irrelevant. For more information about static versus dynamic resource references, see [Overview of XAML resources (WPF .NET)](../net/wpf/systems/xaml-resources-overview.md). Explicitly specifying `x:Shared="true"` is rarely done, because that is already the default. There is no direct code equivalent for `x:Shared` in the WPF object model; it can only be specified in a XAML usage and must be processed either by the default WPF behavior or in an intermediate XAML node stream on the load path if processed using .NET XAML Services and its XAML readers. @@ -48,5 +49,5 @@ In WPF, `x:Shared` is only valid under the following conditions: ## See also - -- [XAML Resources](../net/wpf/fundamentals/xaml-resources-define.md) +- [Overview of XAML resources (WPF .NET)](../net/wpf/systems/xaml-resources-overview.md) - [Base Elements](../framework/wpf/advanced/base-elements.md) diff --git a/dotnet-desktop-guide/xaml-services/xtype-markup-extension.md b/dotnet-desktop-guide/xaml-services/xtype-markup-extension.md index 1c645a4..79f6df3 100644 --- a/dotnet-desktop-guide/xaml-services/xtype-markup-extension.md +++ b/dotnet-desktop-guide/xaml-services/xtype-markup-extension.md @@ -1,5 +1,6 @@ --- title: "x:Type Markup Extension" +description: "Describes how the x:Type markup extension is used in XAML. The x:Type markup extension specifies a CLR object." ms.date: "03/30/2017" f1_keywords: - "x:TypeExtension" @@ -33,7 +34,7 @@ Supplies the CLR object that is the underlying type for a spe ## XAML Values -||| +| Value | Description | |-|-| |`prefix`|Optional. A prefix that maps a non-default XAML namespace. Specifying a prefix is frequently not necessary. See Remarks.| |`typeNameValue`|Required. A type name resolvable to the current default XAML namespace; or the specified mapped prefix if `prefix` is supplied.| @@ -81,6 +82,6 @@ In WPF, you can use XAML 2009 features but only for loose XAML (XAML that is not ## See also - -- [Styling and Templating](../net/wpf/fundamentals/styles-templates-overview.md) -- [XAML Overview (WPF)](../net/wpf/fundamentals/xaml.md) +- [Styles and templates (WPF .NET)](../net/wpf/controls/styles-templates-overview.md) +- [XAML overview (WPF .NET)](../net/wpf/xaml/index.md) - [Markup Extensions and WPF XAML](../framework/wpf/advanced/markup-extensions-and-wpf-xaml.md)