At first, binding to the TreeView's SelectedItem property sounds like a simple task, but if you give it a go you will soon realise it's not so straight forward. That's because the WPF TreeView's SelectedItem property is read-only so we can't set the binding in XAML like normal.
Welcome to my blog! I'll be posting any bits and pieces I come across that I think might be interesting or useful for any one else. Hopefully it will be of use to others out there.
Thursday, 18 April 2013
Thursday, 11 April 2013
WPF - Different Data Templates for Different Child Types in a TreeView
The TreeView control in WPF allows us to display hierarchical data and allows us to customise the appearance of this by setting the ItemTemplate property using a HierarchicalDataTemplate, giving us expandable nodes within our tree. However, we can only set the ItemTemplate property once with one data template. Imagine the scenario where you want to display a directory structure. A directory can contain files or other directories which in turn can also contain files or other directories and so on. You might want to use a different data template for files than for directories but as stated earlier you can only set the ItemTemplate property once, so how can we achieve this?
Tuesday, 2 April 2013
CallerMemberName .NET 4.0
After writing my recent post about a basic ViewModelBase implementation, the discussion about the CallerMemberNameAttribute got me thinking... how hard would it be to write my own implementation of this attribute?
Monday, 1 April 2013
MVVM - ViewModelBase
If you are developing a WPF application then you really need to be using the MVVM(Model-View-ViewModel) design pattern. I'm sure the vast majority of prospective employers searching for a WPF developer well expect some familiarity with MVVM. I'm not going to spend hours explaining this design pattern as many people have already done that rather well such as here and here.
Saturday, 30 March 2013
WPF - Find Parent by Type
Building on from my earlier post here I thought I'd show how we can use VisualTreeHelper to go the other way up the tree and find a parent of a specified type.
Thursday, 28 March 2013
WPF - Find Child by Type
WPF provides the VisualTreeHelper class which exposes a few static methods that help us to navigate the visual tree more easily. However, the existing methods don't provide any specific methods for searching the visual tree for a particular element type.