How come I don’t see a MouseHover event in WPF for it’s elements?

WPF doesn’t provide a MouseHover event and instead provides a much more flexible and high-level Tooltip support. To simulate MouseHover, you will first set the tooltip for the element in question to some dummy text and then listen to the TooltipOpening event where you would mark it as ‘Handled’ as follows: [XAML] <Canvas ToolTipOpening=’Canvas_ToolTipOpening’ ToolTipService.ToolTip=’Testing’> </Canvas> [C#] private void Canvas_ToolTipOpening(object sender, ToolTipEventArgs e) { e.Handled = true; // More code goes here: }

How do I load a FlowDocument XAML content from outside the application directory?

Let us say you have your application running in a folder called C:\MyApp. Then if you want to load a FlowDocumentContent.xaml from a folder called C:\Contentthen this is easily done by first defining a FlowDocumentReader in your app like so: [XAML] <FlowDocumentReader Name=’myFlowDocument’ ViewingMode=’Scroll’ IsTwoPageViewEnabled=’False’ IsPageViewEnabled=’False’> </FlowDocumentReader> And load the xaml file as follows: [C#] FileStream xamlFile = new FileStream(filePath, FileMode.Open, FileAccess.Read); // This will work, only if the top-level element in the document is FlowDocument FlowDocument content = XamlReader.Load(xamlFile) as FlowDocument; this.myFlowDocument.Document = content; xamlFile.Close(); But if you have references to sub-folders in your document. For example, if you are referring to images under this folder C:\Content\Images, then those images wouldn’t be found by the parser because the parser is executing with the application directory context whereas the document contents are in a different directory. To make this work, you can force a context on the parser as follows: [C#] ParserContext context = new ParserContext(); context.BaseUri = new Uri(filePath, UriKind.Absolute); FlowDocument content = XamlReader.Load(xamlFile, context) as FlowDocument;

Why is the ListBox displaying the type name of the objects in the list instead of the value of a property in the object

By default when you bind the ListBox’s ItemsSource to a collection of objects of a custom type, the ListBox would simply call the object’s ToString() method to determine what to display for each item. The ToString method would normally simply display the type name of the object. If you instead want a value of a property of the object to be displayed in the listbox, you should set the DisplayMemberPath property of the ListBox to that property name as follows: <ListBox ItemsSource='{StaticResource myCollection}’ DisplayMemberPath=’FirstName’ />

I have a custom type called Group which has 2 collections Products and Services and I want both these collections to appear as siblings when the Groups collection is bound to a tree, how do I do that?

Let us say you want have a hierarchical list like this: – Group | |— Products | |— Product1 | |— Product2 |— Service | |— Service1 | |— Service2 And the underlying Group type defined like this: public class Group { public string Name{…} public ProductCollection Products{…} public ServiceCollection Services{…} } Then you will have trouble binding this to a TreeView to get the above indicated effect. To achieve the above effect, you should first implement a dummy ‘Children’ collection that is a combination of the Products and Services collection as follows: public class Group { public string Name{…} public ProductCollection Products{…} public ServiceCollection Services{…} public IList Children{/*Combine Products and Services and return the list here. This could be just a read-only list.*/} } Then create a HierarchicalDataTemplate for the Group object as follows: [XAML] <HierarchicalDataTemplate DataType='{x:Type src:Group}’ ItemsSource='{Binding Path=Children}’> <TextBlock Text='{Binding Path=Name}’/> </HierarchicalDataTemplate> This will render both the Products and Services list as siblings at the same level. You should also declare HierarchicalDataTemplates for the Product and Service types you might have defined. You would of course, bind the tree to a collection of Group items.