To implement custom logic for choosing a style, you should create a System.Windows.Controls.StyleSelector descendant, and override the System.Windows.Controls.StyleSelector.SelectStyle method. This method's return value will be applied to a document container.