wpf interview questions
Top wpf frequently asked interview questions
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 mythical thing called a mutex, rarely can I find someone that bothers to stop and explain what one of these are.
The code needs to also inform the already-running instance that the user tried to start a second one, and maybe also pass any command-line arguments if any existed.
Source: (StackOverflow)
How can I get a Color from a Hexadecimal color code or say, Hash code (e.g. #FFDFD991
)?
I am reading a file and getting Hexadecimal color code, I need to create the corresponding System.Windows.Media.Color
instance for the Hexadecimal color code. Is there any inbuilt method in framework to do this?
Source: (StackOverflow)
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 search/sort/filter based on user input. The data binding demo (http://msdn.microsoft.com/en-us/library/ms771319.aspx) uses a ListBox with a CollectionViewSource.
Does anyone have pros/cons for which control to use and when?
Source: (StackOverflow)
The title says it all. 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 performance or memory implications to using them the wrong way?
EDIT Responses so far suggest that using x:Name
all the time works fine, but I still want to know what the difference is. Microsoft put these two attributes into the very first release of WPF, so there must be some sensible explanation.
Source: (StackOverflow)
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 scroll bar property in the Properties pane, but could not find one.
How can I make vertical scroll bar created automatically for my TextBlock
once its contents exceed its height?
Clarification: I would rather do it from the designer and not by directly writing to the XAML.
Source: (StackOverflow)
I come from a mostly web and a little bit Windows Forms background. For a new project, we will be using WPF. The WPF application will need 10 - 20 small icons and images for illustrative purposes. I am thinking about storing these in the assembly as embedded resources. Is that the right way to go ?
How do I specify in XAML that an Image control should load the image from an embedded resource ?
Source: (StackOverflow)
I am developing an application with the MVVM model, but I have reached a point where I need to choose which framework to use.
Among the possible options are:
- MVVM Toolkit
- MVVM Foundation
- WPF Application Framework (WAF)
- Light MVVM
- Caliburn
- Cinch
- Prism
In your experience, which is better?
Source: (StackOverflow)
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 apps, but then it seems to have something to do with HTML, CSS, DOM, and JavaScript.
Can someone explain what it is in a few paragraphs, in terms that a .NET UI programmer can understand? (I am missing something “key” that is necessary to understand it)
We all know that WPF and Silverlight and Winforms, etc will keep working under windows 8 (and windows 10) on at least on Intel system, so please don't tell me that...
Source: (StackOverflow)
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
<ItemsControl ItemTemplate="{DynamicResource MyItemTemplate}" />
Most of the times (always?), only one works and the other will throw exception during runtime. But I'd like to know why:
- What is the main difference. Like memory or performance implications
- Are there rules in WPF like "brushes are always static" and "templates are always dynamic" etc.?
I assume the choice between Static vs Dynamic isn't as arbitrary as it seems... but I fail to see the pattern.
Source: (StackOverflow)
I've got an enum like this:
public enum MyLovelyEnum
{
FirstSelection,
TheOtherSelection,
YetAnotherOne
};
I got a property in my DataContext:
public MyLovelyEnum VeryLovelyEnum { get; set; }
And I got three RadioButtons in my WPF client.
<RadioButton Margin="3">First Selection</RadioButton>
<RadioButton Margin="3">The Other Selection</RadioButton>
<RadioButton Margin="3">Yet Another one</RadioButton>
Now how do I bind the RadioButtons to the property for proper two-way-binding?
Source: (StackOverflow)
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 assembly and have my applications reference it, right?
After the resource assembly is built, how can I reference it in the App.xaml of my applications? Currently I use ResourceDictionary.MergedDictionaries to merge the individual dictionary files. If I have them in an assembly, how can I reference them in xaml?
Source: (StackOverflow)
I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this?
Source: (StackOverflow)
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) to be selected - it stays open if I simply click OK without choosing one. I could "hack up" the functionality by letting the user pick a file and then strip the path to figure out which directory it belongs to but that's unintuitive at best. Has anyone seen this done before?
Source: (StackOverflow)
What should every WPF developer know?
Entry Level
- Strong .NET 2.0 Background & willing to learn!
- Explain dependency properties?
- What's a style?
- What's a template?
- Binding
- Differences between base classes: Visual, UIElement, FrameworkElement, Control
- Visual vs Logical tree?
- Property Change Notification (INotifyPropertyChange and ObservableCollection)
- ResourceDictionary - Added by a7an
- UserControls - Added by a7an
- difference between bubble and tunnel routing strategies - added by Carlo
- Why did Microsoft introduce yet another markup language?
- XAML
Mid-level
- Routed Events & Commands
- Converters - Added by Artur Carvalho
- Explain WPF's 2-pass layout engine?
- How to implement a panel?
- Interoperability (WPF/WinForms)
- Blend/Cider - Added by a7an
- Animations and Storyboarding
- ClickOnce Deployment
- Skinning/Themeing
- Custom Controls
- How can worker threads update the UI?
- DataTemplate vs HierarchicalDataTemplate
- ItemsControl vs ItemsPresenter vs ContentControl vs ContentPresenter
- Different types of Triggers
Senior
- Example of attached behavior?
- What is PRISM,CAL & CAG?
- How can worker threads update the UI?
- WPF 3D - Added by a7an
- Differences between Silverlight 2 and WPF
- MVVM/MVP - Added by a7an
- WPF Performance tuning
- Pixel Shaders
- Purpose of Freezables
Any other "trick" questions to ask?
Do you expect your WPF developer to know blend?
Source: (StackOverflow)