How do I apply custom sorting to the order of the items in a bound listbox?

To specify custom sorting using a custom implementation of an IComparer, you will have to use a CollectionViewSource, get it’s default view and set it’s CustomSort property as follows: Sample ListBox bound to a CollectionViewSource: <Window x:Class='WindowsApplication1.Window1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:scm='clr-namespace:System.ComponentModel;assembly=windowsbase' > <Window.Resources> <XmlDataProvider x:Key='list' > <x:XData> <Items xmlns=''> <Item> <Name>David</Name> <Age>20</Age> </Item> <Item> <Name>Marcus</Name> <Age>25</Age> </Item> <Item> <Name>George</Name> <Age>25</Age> </Item> <Item> <Name><![CDATA[Peter&#M]]></Name> <Age>25</Age> </Item> </Items> </x:XData> </XmlDataProvider> <CollectionViewSource Source='{Binding Source={StaticResource list}, XPath=Items/Item/Name}' x:Key='data'/> </Window.Resources> <ListBox Name='lb1' DisplayMemberPath='Name' ItemsSource='{Binding Source={StaticResource data}}'/> </Window> Then in code-behind specify the custom comparer as follows: public partial class Window1 : Window { public Window1() { InitializeComponent(); this.lb1.Loaded += delegate { CollectionViewSource cvs = this.TryFindResource('data') as CollectionViewSource; if (cvs != null) { ListCollectionView view = cvs.View as ListCollectionView; if (view != null) { view.CustomSort = new XmlComparer(); } } }; } public class XmlComparer : IComparer { public Int32 Compare(Object x, Object y) { XmlElement a = x as XmlElement; XmlElement b = y as XmlElement; if (a != null && b != null) { return String.Compare(a.InnerText, b.InnerText); } return -1; } } }

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;