Questions tagged [wpf]
Windows Presentation Foundation, or WPF, is a subsystem for rendering user interfaces in Windows-based applications.
169,637
questions
974
votes
111
answers
1.2m
views
Metadata file '.dll' could not be found
I am working on a WPF, C# 3.0 project, and I get this error:
Error 1 Metadata file
'WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug
\BusinessLogicLayer.dll' could not be found C:\-=...
742
votes
39
answers
260k
views
What is the correct way to create a single-instance WPF application?
Using C# and WPF under .NET (rather than Windows Forms or console), what is the correct way to create an application that can only be run as a single instance?
I know it has something to do with some ...
708
votes
20
answers
681k
views
How do I get the color from a hexadecimal color code using .NET?
How can I get a color from a hexadecimal color code (e.g. #FFDFD991)?
I am reading a file and am getting a hexadecimal color code. I need to create the corresponding System.Windows.Media.Color ...
669
votes
14
answers
523k
views
How do I use WPF bindings with RelativeSource?
How do I use RelativeSource with WPF bindings and what are the different use-cases?
663
votes
15
answers
157k
views
In WPF, what are the differences between the x:Name and Name attributes?
Sometimes it seems that the Name and x:Name attributes are interchangeable.
So, what are the definitive differences between them, and when is it preferable to use one over the other?
Are there any ...
569
votes
19
answers
466k
views
How do I exit a WPF application programmatically?
How is one supposed to exit an application such as when the user clicks on the Exit menu item from the File menu?
I have tried:
this.Dispose();
this.Exit();
Application.ShutDown();
Application.Exit();
...
531
votes
8
answers
217k
views
What's the difference between StaticResource and DynamicResource in WPF?
When using resources such as brushes, templates and styles in WPF, they can be specified either as StaticResources
<Rectangle Fill="{StaticResource MyBrush}" />
or as a DynamicResource
<...
509
votes
54
answers
395k
views
The name 'InitializeComponent' does not exist in the current context
If I create a new project in Visual Studio 2010 SP1 and select "WPF Application" and tries to build the generated application, I get the error
The name 'InitializeComponent' does not exist in the ...
475
votes
11
answers
169k
views
How to bind RadioButtons to an enum?
I've got an enum like this:
public enum MyLovelyEnum
{
FirstSelection,
TheOtherSelection,
YetAnotherOne
};
I got a property in my DataContext:
public MyLovelyEnum VeryLovelyEnum { get; ...
456
votes
11
answers
517k
views
Storing WPF Image Resources
For a WPF application which will need 10 - 20 small icons and images for illustrative purposes, is storing these in the assembly as embedded resources the right way to go?
If so, how do I specify in ...
447
votes
16
answers
274k
views
How to bind inverse boolean properties in WPF?
What I have is an object that has an IsReadOnly property. If this property is true, I would like to set the IsEnabled property on a Button, ( for example ), to false.
I would like to believe that I ...
438
votes
15
answers
384k
views
The calling thread cannot access this object because a different thread owns it
My code is as below
public CountryStandards()
{
InitializeComponent();
try
{
FillPageControls();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "...
418
votes
33
answers
609k
views
How do I get a TextBox to only accept numeric input in WPF?
I'm looking to accept digits and the decimal point, but no sign.
I've looked at samples using the NumericUpDown control for Windows Forms, and this sample of a NumericUpDown custom control from ...
414
votes
5
answers
289k
views
Difference between SelectedItem, SelectedValue and SelectedValuePath
What is the difference betweeen the following:
SelectedItem
SelectedValue
SelectedValuePath
All these dependency properties are defined in Selector class. I often confuse SelectedItem with ...
410
votes
5
answers
351k
views
Multiline for WPF TextBox
I am developing an app for sending some feedback.
Basically I'm trying to make a TextBox for comments, but I'm used to the WinForms MultiLine=true. I've set MinLines to 3, which is getting there, but ...
410
votes
4
answers
433k
views
How to get StackPanel's children to fill maximum space downward?
I simply want flowing text on the left, and a help box on the right.
The help box should extend all the way to the bottom.
If you take out the outer StackPanel below it works great.
But for reasons ...
403
votes
9
answers
365k
views
Is there a MessageBox equivalent in WPF?
Is there a standard message box in WPF, like WinForms' System.Windows.Forms.MessageBox.Show(), or should I use the WinForms message box?
402
votes
10
answers
315k
views
Automatic vertical scroll bar in WPF TextBlock?
I have a TextBlock in WPF. I write many lines to it, far exceeding its vertical height. I expected a vertical scroll bar to appear automatically when that happens, but it didn't. I tried to look for a ...
378
votes
9
answers
186k
views
WPF global exception handler [duplicate]
Sometimes, under not reproducible circumstances, my WPF application crashes without any message. The application simply close instantly.
Where is the best place to implement the global Try/Catch ...
378
votes
14
answers
81k
views
INotifyPropertyChanged vs. DependencyProperty in ViewModel
When implementing the ViewModel in a Model-View-ViewModel architecture WPF application there seem to be two major choices how to make it databindable. I have seen implementations that use ...
365
votes
19
answers
641k
views
Setting WPF image source in code
I'm trying to set a WPF image's source in code. The image is embedded as a resource in the project. By looking at examples I've come up with the below code. For some reason it doesn't work - the image ...
360
votes
5
answers
45k
views
How does Windows 8 Runtime (WinRT / Windows Store apps / Windows 10 Universal App) compare to Silverlight and WPF? [closed]
I am trying to get my head round the new Windows 8 Runtime that is used to create Metro style apps. I know you can use it with XAML and it is based on .NET so C# and VB.NET can be used to write the ...
356
votes
5
answers
335k
views
How to get controls in WPF to fill available space?
Some WPF controls (like the Button) seem to happily consume all the available space in its' container if you don't specify the height it is to have.
And some, like the ones I need to use right now, ...
329
votes
1
answer
123k
views
ListBox vs. ListView - how to choose for data binding
I'm considering either a ListBox or a ListView for a WPF application. It seems either supports data binding and item templates. My application has a simple list of items that I intend to be able to ...
327
votes
4
answers
162k
views
Difference between Visibility.Collapsed and Visibility.Hidden
What are differences between Visibility.Collapsed and Visibility.Hidden in WPF?
326
votes
19
answers
426k
views
Open directory dialog
I want the user to select a directory where a file that I will then generate will be saved. I know that in WPF I should use the OpenFileDialog from Win32, but unfortunately the dialog requires file(s) ...
324
votes
35
answers
310k
views
Watermark / hint / placeholder text in TextBox?
How can I put some text into a TextBox which will be removed automatically when the user types something in it?
300
votes
22
answers
403k
views
How can I find WPF controls by name or type?
I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this?
298
votes
12
answers
281k
views
How can I wrap text in a label using WPF?
I have a TextBox and a Label. After clicking a button, I execute the following code:
label1.Content = textbox1.Text;
My question is, how do I enable text wrapping of the label? There may be too ...
298
votes
32
answers
259k
views
How to bind to a PasswordBox in MVVM
I have come across a problem with binding to a PasswordBox. It seems it's a security risk but I am using the MVVM pattern so I wish to bypass this. I found some interesting code here (has anyone used ...
293
votes
4
answers
188k
views
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?
283
votes
7
answers
138k
views
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 ...
281
votes
15
answers
210k
views
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 ...
274
votes
6
answers
174k
views
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 ...
272
votes
7
answers
156k
views
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 ...
269
votes
17
answers
290k
views
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?
268
votes
25
answers
117k
views
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 ...
266
votes
35
answers
180k
views
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 ...
264
votes
21
answers
202k
views
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 ...
263
votes
20
answers
147k
views
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 ...
261
votes
5
answers
78k
views
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 ...
260
votes
4
answers
254k
views
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:
<TextBlock Text="{Binding Name}" />
Now, I want to bind another property named ID to the same TextBlock.
Is ...
256
votes
3
answers
209k
views
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?
252
votes
5
answers
91k
views
ItemsControl with horizontal orientation
Do you know any controls inherited from the ItemsControl that have horizontal orientation of items?
251
votes
4
answers
169k
views
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?
251
votes
24
answers
132k
views
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 ...
250
votes
21
answers
229k
views
How do I get an animated gif to work in WPF?
What control type should I use - Image, MediaElement, etc.?
248
votes
17
answers
223k
views
Find all controls in WPF Window by type
I'm looking for a way to find all controls on Window by their type,
for example: find all TextBoxes, find all controls implementing specific interface etc.
243
votes
20
answers
219k
views
Bring a window to the front in WPF
How can I bring my WPF application to the front of the desktop? So far I've tried:
SwitchToThisWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle, true);
SetWindowPos(new ...
243
votes
22
answers
418k
views
MVVM: Tutorial from start to finish?
I'm a C#/Windows Forms programmer with more than 5 years experience. I've been investigating WPF using the MVVM (Model-View-ViewModel) design pattern. I have searched the Internet for tutorials. I ...