| WPF-Question-Answers-51-60 | WPF-Question-Answers-91-100 | |
WPF (Windows Presentation Foundation) Question Answers - 81 to 90 |
In WPF, routed events are a powerful extension of the standard .NET event model. They allow events to travel through the visual tree, giving multiple elements a chance to respond—even if they aren’t the direct source of the event.
The thread that creates a WPF UI element owns the elements and other threads can not interact with the UI elements directly, this is known as thread affinity.
We can use the Thumb control for simple dragging of objects on a Canvas. Set the Template of the Thumb control to contain the actual element to be dragged and then handle the thumb’s DragDelta event.
Thumb provides DragStarted, DragCompleted and DragDelta events to manage drag operations associated with the mouse pointer. When the user presses the left mouse button, the Thumb control receives logical focus and mouse capture, and the DragStarted event is raised. While the Thumbcontrol has focus and mouse capture, the DragDelta event can be raised multiple times without limit. When the user releases the left mouse button, the Thumb control loses mouse capture and the DragCompleted event is raised.
UIElement—The base class for all 2D visual objects with support for routed events, command binding, layout, and focus.
UIElement3D—The base class for all 3D visual objects with support for routed events, command binding, and focus.
Virtualization is a technique in WPF to improves the rendering performance of UI elements. With the Virtualization technique the layout system ensures that only the visible items of a container are rendered on the screen. For example, a list control may have thousands of items but virtualization will reduce the rendering to the visible items only say 5 or 10 items.
VirtualizingPanel is the abstract base class of VirtualizingStackPanel. If you plan on supporting UI virtualization, then you should derive from VirtualizingPanel.
VirtualizingStackPanel?
The VirtualizingStackPanel is a layout control in WPF which is used to implement virtualization. By default, the IsVirtualizing property is set to true. When IsVirtualizing is set to false, a VirtualizingStackPanel behaves the same as an ordinary StackPanel. The VirtualizingStackPanel calculates the number of visible items and works with the ItemContainerGenerator from an ItemsControl to create UI elements only for visible items.
Example: <
VirtualizingStackPanel Width="300" Height="200" />
VirtualizingStackPanel? When to use this?
VirtualizingStackPanel Is layout control similar to StackPanel which arranges and virtualizes content on a single line that is oriented either horizontally or vertically.
When working with a large Children collection, consider using a VirtualizingStackPanel instead of a regular StackPanel.
By virtualizing the child collection, the VirtualizingStackPanel only keeps objects in memory that are currently within the parent's ViewPort. As a result, performance is substantially improved in most scenarios.
Visual—The base class for all objects that have their own 2D visual representation.
| WPF-Question-Answers-51-60 | WPF-Question-Answers-91-100 | |