Posts

Showing posts from 2016

How UI Layout Works

Image
Few days ago, I was stuck with a GUI issue where WPF controls were not getting rendered in memory. Everything was arranged properly in a Visual Tree of parent control but still somehow child was not able to draw with custom size. So, to solve this issue I took  help of a book called WPF Control Development by Kevin Hoffman. I thought I should share how this layout process works under the hood. So there it is: ___________________________________________________________________________ The layout system in WPF is a conversation between the layout container and its children. This conversation takes place in two stages that are often referred to as passes. This two-pass approach starts at the root of the visual tree and recursively traverses the tree until all containers have been given the chance to perform the layout process with their children. In the first pass of the conversation, the parent asks its children how much space they need to display themselves. The parent infor

Increase Performance of your UI using Virtualization

Image
Recently I found an interesting article written by  Eric Stollnitz on increasing UI performance when Lists and collections are involved in your UI. Worth a read. Please follow this link:  UI Virtualization  

Single Textblock with multiple Font settings

Image
Today, I faced a requirement where I had to show some text and a down-arrow in default Ribbon control. Now, since this ribbon can have only one child, I had to come up with smart solution without much of code-behind. Application Menu After surfing, I got to know about this Inline feature of Textblock. TextBlock.Inlines property states:  An  InlineCollection  containing the  Inline  elements that comprise the contents of the  TextBlock . I added: You can also go with code-behind solution like this:

Binding Previous Item's data in ItemsControl

For a data-bound ItemsControl, each item in the source collection is the DataContext for the generated UI container.  By default, the binding expressions used in the ItemTemplate  are evaluated with respect to this DataContext.  This is useful if all of the information that  the template needs is contained in this context. This is actually the case in the vast  majority of data binding expressions.  However, there might be times when you also want  to take a peek at the previous item to do some work.  For example, say you are plotting a  sales chart and you want to show the percentage change in market share over five years. Here the change can be calculated within the ItemTemplate and shown in red for a decrease and in green for an increase. In this case, it is necessary to have information about the previous item in the data-bound list.  This is where the exact scenario that the  RelativeSource class was designed for with its PreviousData property.  RelativeSource.PreviousDa