This function allows you to get a control by name and type in a given parent control VisualTree. Keep in mind that recursively searching a tree downwards could be a lengthy process. Note that if the argument name is undefined, the function returns the first found child element that matches the submitted type T. In … Continue reading “C# – How to find a control by name or type in the VisualTree”
This recursive function allows you to get all controls of a given generic type that are children of a given element in the VisualTree.
One thing that happened to me often was the items of an ItemsControl derivative (like a ListBox or ListView) not fill the full width of the list when was defined a DataTemplate for the ItemTemplate of the list. For example, the Xaml code below: … produces this: It should be noted that despite <Grid HorizontalAlignment=”Stretch”>, … Continue reading “C# – How to make items of ListView fill the entire list width”
Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. To provide explicit control, implement the Dispose method provided by the IDisposable interface. The consumer of … Continue reading “C# – Implementing Finalize and Dispose to clean up resources”
A good book with advices and tips for writing better code. Free download FoundationsOfProgramming.pdf Copyright © Karl Seguin About the Author Karl Seguin is a developer at Epocal Corporation, a former Microsoft MVP, a member of the influential CodeBetter.com community and an editor for DotNetSlackers.
Many people questioned themselves about which of the two forms is the best to (re) throw an exception? Is it better to do this : or this: The way to preserve the stack trace is through the use of the throw; This is valid as well throw ex; is basically like throwing an exception from … Continue reading “C# – Throwing Exceptions best practices”
in (Generic Modifier) For generic type parameters, the in keyword specifies that the type parameter is contravariant. You can use the in keyword in generic interfaces and delegates. Contravariance enables you to use a less derived type than that specified by the generic parameter. An interface that has a contravariant type parameter allows its methods … Continue reading “C # – Understanding ‘in’ and ‘out’ (Generic Modifier)”