Dec 30, 2008

How to expand items in a TreeView – Part III

49ExpandTreeViewPart3

This is the third of a three-part series about expanding TreeViewItems. In the first post I explained how to use an implicit Style to expand all TreeViewItems at load time. In the second post I showed how you can drive expansion and selection of items using an intermediate data source. In this post, I will explain how you can expand and select TreeViewItems using the dispatcher. Expanding all TreeViewItems by setting the IsExpanded property on the items directly is not as simple as doing a tree walk and…

read more
Nov 13, 2008

How to expand items in a TreeView – Part II

48ExpandTreeViewPart2

For those of you in Europe, I will be giving a talk at the Oredev conference in Malmo, Sweden, on Thursday the 20th of November. I hope I’ll get to meet some of you there. In my last post, I showed how you can expand all items in a TreeView at load time. In WPF, this can be done by simply adding an implicit style to the resources, and in Silverlight we need a little help from ImplicitStyleManager to achieve the same behavior. However, applications typically allow more…

read more
Oct 29, 2008

How to expand items in a TreeView – Part I

47ExpandTreeViewPart1

Exciting! Yesterday, the new Silverlight Toolkit (the team I now work for) was made available in CodePlex. This was announced by Scott Guthrie in his PDC keynote and by my manager Shawn Burke in his blog. We created the Silverlight Toolkit to provide developers with a set of reusable components that maximize productivity and help take Silverlight to the next level. The toolkit is available under the Microsoft Public License, so we provide the full source code (as well as tests and samples), and encourage you to reuse…

read more
Feb 22, 2008

How to drag and drop items between data bound ItemsControls

46DragDropListBox

In this blog post, I will explain how I implemented a sample that allows you to drag and drop items between data bound ItemsControls. Imagine you have two or more data bound (or not data bound) ItemsControls in the same Window. You may want to drag an item from an ItemsControl and drop it on another one. Or maybe you want to drag and drop it in a different position within the same ItemsControl. The code in this blog post allows you to do those operations. Use this…

read more
Jan 28, 2008

How to debug WPF bindings

45DebuggingDataBinding

Data Binding can be tricky to debug. In this post, I will share the techniques I use to debug WPF bindings, including the new debugging improvements we implemented in the latest 3.5 release. I will discuss the following four techniques: Scanning Visual Studio’s Output window for errors. Using Trace Sources for maximum control. Using the new property introduced in WPF 3.5 - PresentationTraceSources.TraceLevel. Adding a breakpoint to a Converter. The DataContext of this app is set to a new instance of Star, which is a class that contains…

read more
Jan 13, 2008

How to implement the Master-Detail pattern when binding to XLinq and XML

44XLinqXMLMasterDetail

I have explained in previous posts how to implement: A two-level Master-Detail scenario using objects as data source here. A three level Master-Detail scenario using objects as data source here A three level Master-Detail scenario using ADO.NET here. The two-level version of this scenario with ADO.NET should be obvious based on the samples above. In this post, I will explain how to implement a two and three level Master-Detail when binding to XLinq and XML. Two level Master-Detail with XML Here is the XML data source I used…

read more
Jan 01, 2008

How to bind WPF elements to XLinq

43BindToXLinq

One of the main features that we shipped in .NET 3.5 is the ability to bind to XLinq directly from XAML. In this post, I will first cover the basics of this new feature, and then discuss the seven queries I added to the sample project. Please keep in mind that this blog post does not attempt to provide an introduction to XLinq. For those of you that need a quick introduction to the topic, I found this site to be a good resource. Basics of binding to…

read more
Nov 26, 2007

Using WPF instead of PowerPoint for presentations

42WPFPresenter

If you’ve attended one of my presentations before, you’ve noticed that I never use PowerPoint - instead, I have my slides coded in WPF. I’ve decided to write my own presentation code because I want my slides to be interactive - instead of showing a concept in PowerPoint and switching to VS to demo it, I can demo it directly within the presentation. Several people have asked me for my presentation code in the past, so I’ve decided to share it here in my blog. Use this project…

read more
Sep 22, 2007

How to improve TreeView’s performance – Part III

41TreeViewPerformancePart3

Update: This post is out of date. With .NET 3.5 SP1, TreeView now provides opt-in UI virtualization. You can see this feature working by setting VirtualizingStackPanel.IsVirtualizing=”True” on the TreeView itself. TreeView also supports container recycling, which you can control by setting the VirtualizingStackPanel.VirtualizationMode property. In part I of my discussions on TreeView performance, I presented the three main limitations in the current implementation of TreeView that may lead to slower performance: UI elements stay in memory even when collapsed. There is no UI virtualization. There is no data…

read more
Sep 10, 2007

How to improve TreeView’s performance – Part II

40TreeViewPerformancePart2

In my previous post, I discussed some of the performance limitations of TreeView. In particular, I mentioned the three facts about our current implementation that may lead to performance issues, depending on your scenario: UI elements stay in memory even when collapsed. There is no UI virtualization. There is no data virtualization. Today I will talk about a trick that avoids the first problem and partially fixes the third. In my previous post, I always kept the data for all levels of the TreeView in memory. In this…

read more
Aug 31, 2007

How to improve TreeView’s performance – Part I

39TreeViewPerformancePart1

Update: This post is partially out of date. With .NET 3.5 SP1, TreeView now provides opt-in UI virtualization. You can see this feature working by setting VirtualizingStackPanel.IsVirtualizing=”True” on the TreeView itself. TreeView also supports container recycling, which you can control by setting the VirtualizingStackPanel.VirtualizationMode property. With .NET 3.5 SP1, there is still no support for data virtualization, so the data virtualization portions of this blog post series still apply. This is the first of three blog posts where I will discuss TreeView performance. This post will cover the…

read more
May 09, 2007

How to update an explicit binding within a template

38UpdateExplicit

Mix07 in Vegas was awesome! I always get pumped up when I meet new customers that are using WPF and loving it! It gives me fuel to come back to rainy Seattle with a smile and extra energized to do my absolute best for WPF! In today’s sample, I have a ListBox with editable data. When I change the data of one of the items, I want that to be reflected in the source, as usual. However, this time I set my Binding’s UpdateSourceTrigger to Explicit, which means…

read more