*
Previous WPF-Question-Answers-11-20 WPF-Question-Answers-31-40 Next

WPF (Windows Presentation Foundation) Question Answers - (21–30)

WPF Interview Questions (21 - 30)

21. How do I make my data-bound TextBox update the source value as I type?

By default, TextBox.Text has an UpdateSourceTrigger value of LostFocus. This means the source does not get updated until the TextBox loses focus. To update the source as you type, set the UpdateSourceTrigger property to PropertyChanged:

  <TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" />
  

Note: For most properties, UpdateSourceTrigger defaults to PropertyChanged, but for TextBox.Text it defaults to LostFocus.

22. How does layout work? Or What is 2-pass System of layout controls?

The layout system completes two passes for each child: a measure pass and an arrange pass.

  1. Measure pass – determines the desired size of each element.
  2. Arrange pass – explicitly sizes and positions each element.

Layout is recursive, leading to elements being sized, positioned, and drawn onscreen.

23. How many windows are there in WPF?

Two: Window and NavigationWindow. NavigationWindow derives from Window and adds navigation capability:

  • Navigate(Uri)
  • Navigate(Uri, Object)

24. Illustrate the difference between DataContext and ItemsSource property in WPF.

  • DataContext expects an object, ItemsSource expects IEnumerable.
  • DataContext is defined by FrameworkElement, ItemsSource by ItemsControl.
  • DataContext holds common data for binding; ItemsSource is used to generate templates.
  • DataContext can be inherited by child elements, ItemsSource is specific to the control.

25. Is x:Static the same as a data binding?

No. x:Static is a markup extension that retrieves values from static members on classes, unlike data binding which binds to dynamic data sources.

26. Syntax how to bind a dataset to grid in WPF?

Example in XAML:

  <DataGrid ItemsSource="{Binding Customers}" SelectionMode="Extended" SelectionUnit="Cell" />
  

In C# code:

  MyGrid.ItemsSource = ds.Tables["Table"].AsEnumerable();
  MyGrid.ItemsSource = ds.Tables["Table"].DefaultView;
  MyGrid.ItemsSource = new DataView(ds.Tables["Table"]);
  

27. What are resources in WPF?

Resources are reusable WPF objects (like styles, brushes, images). They can be declared in:

  • App.xaml (global scope)
  • Window scope
  • Resources property of any FrameworkElement
  • Separate XAML resource files

Types: StaticResource, DynamicResource.

28. What are Styles in WPF?

Styles allow sharing of properties, resources, and event handlers across controls. They are declared in Resources and obey the same scoping rules. Styles can inherit from other styles (via BasedOn).

29. What are templates in WPF?

WPF provides two main templates:

  • DataTemplate: Defines how data is presented.
  • ControlTemplate: Defines the appearance of a control.

30. What are the different kinds of controls in WPF?

  • Core Controls: Button, RadioButton, ComboBox, CheckBox, Expander, Slider, TreeView, TextBox, Label, etc.
  • Window Frame Adornment Controls: Menu, ToolBar, StatusBar, ToolTip, ProgressBar.
  • Media Controls: SoundPlayer, MediaPlayer, MediaElement.
  • Layout Controls: Grid, StackPanel, Canvas, etc.
  • Advanced Controls: DocumentViewer, FlowDocumentReader, PasswordBox, PrintDialog, etc.
Back to Index
Previous WPF-Question-Answers-11-20 WPF-Question-Answers-31-40 Next
*
*