Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Windows Presentation Foundation

From Wikipedia, the free encyclopedia
Open source UI framework
Windows Presentation Foundation (WPF)
Original authorMicrosoft
Developer.NET Foundation
Initial releaseNovember 21, 2006; 19 years ago (2006-11-21)
Stable release
v8.0.5 / May 14, 2024; 21 months ago (2024-05-14)[1]
Written inC#,C++,C
Operating systemMicrosoft Windows
Platform.NET Framework,.NET
TypeSoftware framework
LicenseMIT License
Websitelearn.microsoft.com/en-us/dotnet/desktop/wpf/
Repository

Windows Presentation Foundation (WPF) is afree and open-sourceuser interface framework forWindows-based desktop applications. WPF applications are based in.NET, and are primarily developed usingC# andXAML.[2]

Originally developed byMicrosoft, WPF was initially released as part of.NET Framework 3.0 in 2006. In 2018, Microsoft released WPF asopen source under theMIT License.[3] WPF's design and its layout language XAML have been adopted by multiple other UI frameworks, such asUWP,.NET MAUI, andAvalonia.

Overview

[edit]

WPF employsXAML, anXML-based language, to define and link various interface elements, and uses C# to define program behavior.[4] WPF applications are deployed as standalone desktop programs.

WPF supports a number of commonuser interface elements, such as 2D/3D rendering, fixed and adaptivedocuments,typography,vector graphics, runtimeanimation, and pre-rendered media. These elements can then be linked and manipulated based on various events, user interactions, anddata bindings.[5]

WPF was developed under the codename "Avalon", as part of the WinFX programming model forWindows "Longhorn". In August 2004, Microsoft announced that components of WinFX would bebackported toWindows XP andWindows Server 2003.[6] It would later be released as part of .NET Framework 3.0, a free download for these operating systems.[7] WPFruntime libraries are included with all versions ofMicrosoft Windows sinceWindows Vista andWindows Server 2008.[8][9]

At the Microsoft Connect event on December 4, 2018,Microsoft announced releasing WPF as open source project onGitHub. It is released under theMIT License. Windows Presentation Foundation has become available for projects targeting the.NET software framework, however, the system is not cross-platform and is still available only on Windows.[3][10]

Code examples

[edit]

In WPF, screens and other UI elements are defined using a pair of files: aXAML file and an associatedC# file with the extension.xaml.cs, often referred to as a "code-behind". The XAML file declaratively defines the layout, contents and other properties of the UI element, while the C# file allows exposure of code entry points for interactivity.[4]

A basic example of an interactiveHello, World! program could be created like so:

MainWindow.xaml:

<Windowx:Class="WpfExample.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow"Height="200"Width="300"><StackPanelOrientation="Vertical"><TextBlockText="What is your name?"/><TextBoxx:Name="NameInputTextBox"/><Buttonx:Name="SubmitButton"Click="SubmitButton_Click"><TextBlockText="Submit"/></Button><TextBlockx:Name="ResultTextBlock"/></StackPanel></Window>

MainWindow.xaml.cs:

usingSystem.Windows;namespaceWpfExample{publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}privatevoidSubmitButton_Click(objectsender,RoutedEventArgse){stringname=this.NameInputTextBox.Text;this.ResultTextBlock.Text=$"Hello {name}!";}}}

In the above example, a UI element calledMainWindow is declared as asubclass of the built-inWindow class. The XAML file defines the layout, which in this example is a vertical collection of controls - a textblock outlining instructions to the user, a textbox for the user to type their name, a button to submit, and a results text block. When the button is clicked, the methodSubmitButton_Click is called, which is defined in the.xaml.cs file. This function updates the final textblock to contain a message greeting the user, addressing them by their submitted name.

Features

[edit]

Media and graphics

[edit]

WPF supports most modern media types, including vector and raster images, audio, video, and can support both 2D and 3D rendering.[11] It also supports implementing graphical effects on visual elements, such asHLSLpixel shaders and built-in effects such asblurs anddrop shadows.[12][13]

WPF mainly relies on vector graphics, which allows most controls and elements to be scaled without loss in quality orpixelization.[14][15]

Data binding

[edit]

WPF employsdata binding, a technique of propagating changes between user interface elements and theobject model of the program.[16] For instance, a textblock defined in XAML could bind its contents to astring property stored on a C# object in the following way:

<TextBlockText="{Binding Username}"/>
publicclassExampleViewModel{publicstringUsername{get;set;}}

This would make the textblock display the value of theUsername property.

The direction data binding happens is configurable - it can be defined to go UI-to-source (eg. text entered into atextbox being propagated to a bound string property in code), or source-to-UI (eg. a visual clock being updated to display the current time stored in code), or bi-directional.[16]

Data binding doesn't have any restrictions on types, and it is possible to bindstructs,classes, orcollections. Converters can be used to transpose the values and types being used during binding - for example, binding a textbox to aDateTime property, but using a converter to display the time as a formattedlocalised date string.[16]

Most properties on built-in controls can be databound, and custom-made controls can create bindable properties by defining Dependency Properties.[16][17]

MVVM, the architectural pattern encouraged by Microsoft for WPF developers, relies heavily on data binding.[18]

Styles and templates

[edit]

Using templates and styles, developers can define the visuals and structure of UI elements.

A style is a combination of property settings that can be applied to a UI element with a single property attribute. For example, a "blueradio button" style could be created and then be reused on any number of radio button controls throughout the program. Styles can alter collections of properties of controls, but are not intended for significant structural changes.

Templates are a mechanism for defining alternative UI for portions of a WPF application. There are several template types available in WPF for different scenarios, but they all have the general purpose of defining the contents, layout and structure of a UI element.[19]

Animations

[edit]

In WPF, many visual properties can be animated. This is exposed through dependency properties, which is the same underlying system that data binding relies on. WPF animations are time-based, as opposed to frame-based.[20]

Animation classes are based on the .NET type of property to be animated. For instance, changing the color of an element is done with the ColorAnimation class and animating the width of an element (which is typed as adouble) is done with the DoubleAnimation class.[20]

Animations can be grouped into Storyboards, which are the primary way to start, stop, pause and otherwise manipulate animations.[20]

Documents and text

[edit]

WPF natively supports paginated documents. It provides theDocumentViewer class, which is for reading fixed layout documents. TheFlowDocumentReader class offers different view modes such as per-page or scrollable and alsoreflows text if the viewing area is resized. It supports both theXML Paper Specification andOpen Packaging Conventions.[21]

WPF includes a number of text rendering features, includingOpenType,TrueType, and OpenType CFF (Compact Font Format) fonts. This means that WPF can support a wide number of text features, includingligatures,old-style numerals,swash variants,fraction,superscript andsubscript,small caps,ruby characters,glyph substitution, multiplebaselines, andkerning.[22]

WPF handles texts inUnicode, and handles texts independent of global settings, such as system locale. In addition, fallback mechanisms are provided to allow writing direction (horizontal versus vertical) handled independent of font name; building international fonts from composite fonts, using a group of single-language fonts; composite fonts embedding. Font linking and font fallback information is stored in a portable XML file, using composite font technology.[23] The XML file has extension.CompositeFont.

The WPF text engine also supports built-inspell checking. It also supports such features as automatic line spacing, enhanced international text, language-guided line breaking,hyphenation, and justification, bitmap effects, transforms, and text effects such as shadows, blur, glow, rotation etc. Animated text is also supported; this refers to animated glyphs, as well as real-time changes in position, size, color, and opacity of the text.

WPF text rendering takes advantage of advances inClearType technology, such as sub-pixel positioning, natural advance widths, Y-direction anti-aliasing,hardware-accelerated text rendering, as well as aggressive caching of pre-rendered text in video memory.[24] ClearType cannot be turned off in older WPF 3.x applications.[25]

Interoperability

[edit]

Windows Forms features are possible through the use of theElementHost andWindowsFormsHost classes.

To enable the use of WinForms, the developer executes this from their WPF C# code:[26]

usingSystem.Windows.Forms.Integration;WindowsFormsHost.EnableWindowsFormsInterop();

WPF programs, via theP/Invoke feature of theCLR, can access native functionality such calling functions from Windowslibraries. This allows the ability to communicate and operate other parts of the operating system, includingunmanaged libraries.[27]

Alternative input and accessibility

[edit]

WPF supportsWindows Ink forpen-based input,[28] and multi-touch input onWindows 7 and above.[29] It also supportsMicrosoft UI Automation to allow developers to create accessible interfaces, and to expose the UI to automated test frameworks.[30]

XAML

[edit]
Main article:Extensible Application Markup Language

Following the success ofmarkup languages for web development, WPF introduced eXtensible Application Markup Language (XAML;/ˈzæməl/), which is based onXML. XAML is designed as a more efficient method of developing application user interfaces.[31] XAML is adeclarative language, meaning the developer (or designer) describes the behavior and integration of components without the use ofprocedural programming. Although it is rare that an entire application will be built completely in XAML, the introduction of XAML allows application designers to more effectively contribute to the application development cycle. UsingXAML to develop user interfaces also allows for separation of model and view, which is considered a good architectural principle.[32] In XAML, elements and attributes map to classes and properties in the underlying APIs.

As in web development, both layouts and specific themes are well suited to markup, butXAML is not required for either. Indeed, all elements of WPF may be coded in a.NET language (C#,VB.NET). The XAML code can ultimately be compiled into a managed assembly in the same way all .NET languages are.

Deployment

[edit]

WPF applications are Windows-only standalone desktopexecutables.

Historically, WPF supported compiling toXBAP, a file format intended to be shown inweb browsers via aNPAPI plugin, but NPAPI and XBAP support was phased out of support by browsers, and XBAP compilation is now no longer included for WPF for .NET.[33][34]

Usage and influence

[edit]

WPF is used to developVisual Studio, Microsoft's flagshipIDE, and was used for developing MicrosoftExpression Blend.[35]

An example of an app made with UWP, a XAML-based framework influenced by WPF

WPF and its layout language, XAML, have influenced multiple other UI frameworks.Silverlight (codenamed WPF/E - WPF Everywhere), released in 2007, is adeprecated cross-browserbrowser plugin. Silverlight had a WPF-based implementation, including using XAML for layouting, that supported video, vector graphics, and animations.[36] Using add-ons, it was supported onMozilla Firefox,Internet Explorer 6 and above,Google Chrome 42 and below andApple Safari. Microsoft encouraged developers to stop using Silverlight in 2015,[37] and support was officially ended in 2021.[38]

After becoming open source in 2018, WPF inspired the development ofAvalonia, an open-source .NET cross-platform XAML-based UI framework, distributed under theMIT License.[39] While WPF only is intended for Windows, Avalonia also supports builds for web (viaWebAssembly),MacOS,Android,iOS, andLinux. Avalonia's name references WPF's in-development codename ("Avalon"), and markets itself as "a spiritual successor to WPF".[40] Avalonia is currently used in tools made byUnity,GitHub andJetBrains.[41]

OpenSilver is framework designed to migrate WPF solutions to web usingWebAssembly. OpenSilver 3.1, released in December 2024, included a XAML designer for use inVisual Studio Code.[42]

XAML, which was first designed for WPF, has been adopted for other similar Microsoft-developed UI libraries, such asUWP,[43] designed forWindows 10,Windows 11,Xbox One andXbox Series S/X applications, and.NET MAUI (formerlyXamarin.Forms), designed for creating cross-platform nativeAndroid andiOS apps.[44]

Development

[edit]

Developers of WPF applications typically useMicrosoft Visual Studio. Visual Studio contains a combination XAML editor and WPF visual designer, beginning with Visual Studio 2008.[45] Prior to Visual Studio 2008, theWPF designer add-in, codenamed Cider, was the original release of aWYSIWYG editor for creating WPF windows, pages, and user controls. It was available for Visual Studio 2005 as aVisual Studio 2005 extensions for .NET Framework 3.0CTP for the initial release of WPF.[46]

Visual Studio is not strictly required to develop WPF projects, as solutions can be built in the command line usingMSBuild.[47]

Microsoft Blend is a designer-oriented tool that provides an artboard for the creation of WPF applications with 2D and 3D graphics, text and forms content. It generatesXAML that may be exported into other tools and shares solution (sln files) and project formats (csproj, vbproj) with Microsoft Visual Studio.Microsoft Expression Design is a bitmap and 2D-vector graphics tool for exporting toXAML.

References

[edit]
  1. ^"v8.0.5".github.com. 2023-05-14. Retrieved2023-05-30.
  2. ^"What is Windows Presentation Foundation - WPF .NET".learn.microsoft.com. 2023-06-02. Retrieved2024-05-15.
  3. ^abMartin, Jeff (4 December 2018)."Microsoft Open Sources WPF, WinForms, and WinUI".InfoQ. Retrieved2018-12-06.
  4. ^abdotnet-bot."XAML Overview (WPF)".msdn.microsoft.com. Retrieved31 March 2018.
  5. ^Sells, Chris; Griffiths, Ian (2007).Programming WPF: Building Windows UI with Windows Presentation Foundation. "O'Reilly Media, Inc.".ISBN 9780596554798.
  6. ^Thurrott, Paul (2005-04-29)."Paul Thurrott's SuperSite for Windows: The Road to Windows Longhorn 2005".www.winsupersite.com. Archived fromthe original on 2005-05-07. Retrieved2025-10-11.
  7. ^Somasegar, S. (2006-06-09)."Somasegar's WebLog : .NET Framework 3.0".blogs.msdn.com. Archived fromthe original on 2007-06-11. Retrieved2025-10-11.
  8. ^kexugit (2007-03-14)."Mailbag: What version of the .NET Framework is included in what version of the OS?".learn.microsoft.com. Retrieved2024-05-25.
  9. ^gewarren (2024-04-24).".NET Framework & Windows OS versions - .NET Framework".learn.microsoft.com. Retrieved2024-05-25.
  10. ^Hanselman, Scott (4 December 2018)."Announcing WPF, WinForms, and WinUI are going Open Source". Retrieved2018-12-06.
  11. ^Graphics and Multimedia. Msdn.Microsoft.com. Retrieved on 2013-08-29.
  12. ^dotnet-bot."Effect Class (System.Windows.Media.Effects)".learn.microsoft.com. Retrieved2024-05-22.
  13. ^4. How WPF and Silverlight Use Shaders - HLSL and Pixel Shaders for XAML Developers [Book].ISBN 978-1-4493-2499-5. Retrieved2024-05-28.{{cite book}}:|website= ignored (help)
  14. ^"Introducing Windows Presentation Foundation".msdn.microsoft.com. 11 May 2010. Retrieved31 March 2018.
  15. ^"What's New in WPF 3.5? Here's Fifteen Cool Features..." Retrieved2007-10-14.
  16. ^abcdadegeo (2023-09-02)."Data binding overview - WPF .NET".learn.microsoft.com. Retrieved2024-05-22.
  17. ^adegeo (2022-06-28)."Dependency properties overview - WPF .NET".learn.microsoft.com. Retrieved2024-05-22.
  18. ^kexugit (2016-12-08)."Patterns - WPF Apps With The Model-View-ViewModel Design Pattern".learn.microsoft.com. Retrieved2024-05-25.
  19. ^adegeo (2023-03-03)."Styles and templates - WPF .NET".learn.microsoft.com. Retrieved2024-05-22.
  20. ^abcadegeo (2022-03-17)."Animation Overview - WPF .NET Framework".learn.microsoft.com. Retrieved2024-05-22.
  21. ^adegeo (2023-02-06)."Documents Overview - WPF .NET Framework".learn.microsoft.com. Retrieved2024-05-22.
  22. ^adegeo (2022-08-18)."OpenType Font Features - WPF .NET Framework".learn.microsoft.com. Retrieved2024-05-22.
  23. ^"Typography in Windows Presentation Foundation".msdn.microsoft.com. 3 November 2006. Retrieved31 March 2018.
  24. ^dotnet-bot."ClearType Overview".msdn.microsoft.com. Retrieved31 March 2018.
  25. ^"Disable Antialiasing".social.msdn.microsoft.com. Retrieved31 March 2018.
  26. ^dotnet-bot."WindowsFormsHost.EnableWindowsFormsInterop Method (System.Windows.Forms.Integration)".learn.microsoft.com. Retrieved2024-05-22.
  27. ^jkoritzinsky (2024-05-10)."Platform Invoke (P/Invoke) - .NET".learn.microsoft.com. Retrieved2024-05-25.
  28. ^adegeo (2022-08-18)."Digital ink - Windows Forms and COM vs. WPF".learn.microsoft.com. Retrieved2024-05-22.
  29. ^kexugit (2015-08-12)."MSDN Magazine: UI Frontiers - Multi-Touch Manipulation Events in WPF".learn.microsoft.com. Retrieved2024-05-22.
  30. ^Xansky."UI Automation Overview".msdn.microsoft.com. Retrieved31 March 2018.
  31. ^MacDonald, Matthew (2010).Pro WPF in VB 2010: Windows Presentation Foundation in .NET 4. Apress.ISBN 9781430272403.
  32. ^Larman, Craig.Applying UML and Patterns: An introduction to Object-Oriented Analysis and Design and the Unified Process(PDF) (2nd ed.). p. 472.
  33. ^adegeo."FAQ about XBAP supportability".learn.microsoft.com. Retrieved2024-05-15.
  34. ^kexugit (2011-03-09)."IE9 - XBAPs Disabled in the Internet Zone".learn.microsoft.com. Retrieved2024-05-15.
  35. ^Blog, Visual Studio (2010-02-16)."WPF in Visual Studio 2010 - Part 1 : Introduction".Visual Studio Blog. Retrieved2024-05-22.
  36. ^kexugit (2019-10-01)."Silverlight: Start Building A Deeper Experience Across The Web".learn.microsoft.com. Retrieved2024-12-27.
  37. ^Blog, Microsoft Edge; Smith, Jerry (2015-07-02)."Moving to HTML5 Premium Media".Microsoft Edge Blog. Retrieved2024-05-23.
  38. ^GitHub-Name."Silverlight 5 - Microsoft Lifecycle".learn.microsoft.com. Retrieved2024-05-23.
  39. ^"Cross-platform Windows Presentation Framework, anyone? The short answer: yes. Unpacking Avalonia".Archived from the original on 2024-09-27. Retrieved2024-12-27.
  40. ^"Avalonia UI - Cross-Platform UI Framework for .NET".Avalonia UI. Retrieved2024-05-16.
  41. ^"Avalonia UI - Showcase".avaloniaui.net. Retrieved2024-05-23.
  42. ^"OpenSilver 3.1 Unveils Drag-and-Drop XAML Designer for VS Code". Visual Studio Magazine. 10 December 2024. Retrieved16 December 2024.
  43. ^jwmsft (2022-10-20)."XAML platform - UWP applications".learn.microsoft.com. Retrieved2024-05-23.
  44. ^davidbritch (2023-07-25)."XAML - .NET MAUI".learn.microsoft.com. Retrieved2024-05-23.
  45. ^Staff, CodeGuru (2009-04-06)."A Tour of WPF in Visual Studio 2008".CodeGuru. Retrieved2024-05-23.
  46. ^"Download details: Microsoft Visual Studio Code Name "Orcas" Community Technology Preview - WinFX™ Development Tools".Microsoft. 2006-04-15. Archived fromthe original on 2006-04-15. Retrieved2024-05-23.
  47. ^adegeo (2022-08-18)."Compile an app - WPF .NET Framework".learn.microsoft.com. Retrieved2024-05-23.

Bibliography

[edit]

External links

[edit]
Implementations
Architecture
Components
Tools
Decompilers
Obfuscators
IDEs
Organizations
Graphics and UI
Audio
Multimedia
Web
Data access
Networking
Communication
Administration and
management
Component model
Libraries
Device drivers
Security
.NET
Software factories
IPC
Accessibility
Text and multilingual
support
Overview
Software
Applications
Video games
Programming
languages
Frameworks,
development tools
Operating systems
Other
Licenses
Forges
Related
Low-level platform-specific
OnAmigaOS
OnClassic Mac OS,macOS
OnWindows
OnUnix
OnBeOS,Haiku
OnAndroid
CLI
Low Level Cross-platform
CLI
C
Java
High-level, platform-specific
OnAmigaOS
OnClassic Mac OS,macOS
Object Pascal
Objective-C,Swift
C++
CLI
OnWindows
CLI
C++
Object Pascal
OnUnix andX11
High-level, cross-platform
C
C++
Objective-C
CLI
Adobe Flash
Go
Haskell
Java
JavaScript
Common Lisp
Lua
Pascal
Object Pascal
Perl
PHP
Python
Ruby
Tcl
XML
shell
Dart
Authority control databases: NationalEdit this at Wikidata
Retrieved from "https://en.wikipedia.org/w/index.php?title=Windows_Presentation_Foundation&oldid=1332608905"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp