Questions tagged [wpf]

Windows Presentation Foundation, or WPF, is a subsystem for rendering user interfaces in Windows-based applications.

Windows Presentation Foundation (WPF, previously known as “Avalon”) is part of the Microsoft .NET Framework used to create rich client user experiences for Windows applications. It is also considered as the successor to

It features a diverse set of controls, layout options, 2D and 3D graphics, media and text handling and enables data binding and style-driven templates.

It uses a combination of XAML, an XML-based markup language, and any of the Common Language Runtime languages to define user interface elements. A fundamental aspect of WPF is to separate the user interface definition from the business logic, which enables developers and designers to work concurrently on a single project much more easily. It enables the users to build a loosely coupled application with the use of data bindings effectively. WPF also moves UI rendering off to the video hardware through the use of . Doing so allows computers to utilize their GPU, which frees the CPU to handle more of the logic-oriented tasks.

WPF runtime libraries are included in all versions of Windows, since Windows Vista and Windows Server 2008.

To learn more, visit the WPF portal on MSDN. See also the Wikipedia entry on WPF.

WPF employs XAML, an XML-based language, to define and link various UI elements. WPF applications can also be deployed as standalone desktop programs, or hosted as an embedded object in a website. WPF aims to unify a number of common user interface elements, such as 2D/3D rendering, fixed and adaptive documents, typography, vector graphics, runtime animation, and pre-rendered media. These elements can then be linked and manipulated based on various events, user interactions, and data bindings.

Microsoft has released six major WPF versions:

  • WPF 4.6 (July 2015)
  • WPF 4.5 (August 2012)
  • WPF 4 (April 2010)
  • WPF 3.5SP1 (Aug 2008)
  • WPF 3.5 (Nov 2007)
  • WPF 3.0 (Nov 2006)

In future, the WPF runtime libraries will be provided by Microsoft as packages known as "App Local" in order for updates to be released independently of .NET Framework releases.

Breaking Changes

On December, 2018 WPF, WinForms and WinUI frameworks became another part of open source community, as announced by Microsoft. WinForms and WinUI are already open, and WPF is starting with System.XAML, and more changes will be announced during the 2019.

Resources

Visual Studio Extensions for WPF Controls

Chat Room

168897 questions
290
votes
4 answers

Page vs Window in WPF?

What is the difference between a Page and a Window in WPF when you are adding a new file in the Solution Explorer?
HelloWorld1
  • 13,688
  • 28
  • 82
  • 145
283
votes
7 answers

Globally catch exceptions in a WPF application?

We have a WPF application where parts of it may throw exceptions at runtime. I'd like to globally catch any unhandled exceptions and log them, but otherwise continue program execution as if nothing happened (kinda like VB's On Error Resume Next). Is…
Joey
  • 344,408
  • 85
  • 689
  • 683
278
votes
15 answers

Databinding an enum property to a ComboBox in WPF

As an example take the following code: public enum ExampleEnum { FooBar, BarFoo } public class ExampleClass : INotifyPropertyChanged { private ExampleEnum example; public ExampleEnum ExampleProperty { get { return example; } { /* set…
Maximilian
  • 4,728
  • 5
  • 29
  • 28
271
votes
6 answers

Simple (I think) Horizontal Line in WPF?

Creating a relatively simple data entry form, and just want to separate certain sections with a horizontal line (not unlike an HR tag in HTML) that stretches the full length of the form. I have tried this:
Phil Sandler
  • 27,544
  • 21
  • 86
  • 147
270
votes
7 answers

ResourceDictionary in a separate assembly

I have resource dictionary files (MenuTemplate.xaml, ButtonTemplate.xaml, etc) that I want to use in multiple separate applications. I could add them to the applications' assemblies, but it's better if I compile these resources in one single…
Gus Cavalcanti
  • 10,527
  • 23
  • 71
  • 104
266
votes
25 answers

How should the ViewModel close the form?

I'm trying to learn WPF and the MVVM problem, but have hit a snag. This question is similar but not quite the same as this one (handling-dialogs-in-wpf-with-mvvm)... I have a "Login" form written using the MVVM pattern. This form has a ViewModel…
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
265
votes
17 answers

Text vertical alignment in WPF TextBlock

How do I assign vertical center alignment to the text inside a TextBlock? I found TextAlignment property but it is for horizontal text alignment. How do I do it for vertical text alignment?
Ant
  • 3,369
  • 5
  • 25
  • 23
262
votes
35 answers

How to automatically select all text on focus in WPF TextBox?

If I call SelectAll from a GotFocus event handler, it doesn't work with the mouse - the selection disappears as soon as mouse is released. EDIT: People are liking Donnelle's answer, I'll try to explain why I did not like it as much as the accepted…
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
261
votes
21 answers

Data binding to SelectedItem in a WPF Treeview

How can I retrieve the item that is selected in a WPF-treeview? I want to do this in XAML, because I want to bind it. You might think that it is SelectedItem but apparently that does not exist is readonly and therefore unusable. This is what I want…
Natrium
  • 30,772
  • 17
  • 59
  • 73
260
votes
5 answers

Difference between ObservableCollection and BindingList

I want to know the difference between ObservableCollection and BindingList because I've used both to notify for any add/delete change in Source, but I actually do not know when to prefer one over the other. Why would I choose one of the following…
Azhar
  • 20,500
  • 38
  • 146
  • 211
260
votes
20 answers

Any way to make a WPF textblock selectable?

How to allow TextBlock's text to be selectable? I tried to get it to work by displaying the text using a read-only TextBox styled to look like a textblock but this will not work in my case because a TextBox does not have inlines. In other words, how…
Alan Le
  • 8,683
  • 7
  • 36
  • 31
257
votes
4 answers

How to bind multiple values to a single WPF TextBlock?

I'm currently using the TextBlock below to bind the value of a property named Name: Now, I want to bind another property named ID to the same TextBlock. Is it possible to bind two or more values to the same…
Spen D
  • 4,225
  • 9
  • 39
  • 47
254
votes
3 answers

What is The difference between ListBox and ListView

What is the difference between WPF's ListBox and ListView? I can not find any significant difference in their properties. Is there different typical use?
Rasto
  • 17,204
  • 47
  • 154
  • 245
251
votes
4 answers

Properties order in Margin

If I have such string in XAML: Storyboard.TargetProperty="Margin" From="1,2,3,4" To="0,0,0,0" What is Top Bottom Right and Left? 1- right 2- top 3- left 4 - bottom Is that right?
Papa John
  • 3,764
  • 3
  • 26
  • 23
251
votes
24 answers

Handling Dialogs in WPF with MVVM

In the MVVM pattern for WPF, handling dialogs is one of the more complex operations. As your view model does not know anything about the view, dialog communication can be interesting. I can expose an ICommand that when the view invokes it, a…
Ray Booysen
  • 28,894
  • 13
  • 84
  • 111