none
How to determine if we're in an XBAP or normal WPF app? RRS feed

  • Question

  • I've created a project containing some custom WPF controls to be used by other apps.  However, there are a few things that need to work differently in an XBAP, like using a popup instead of dialog, etc. 
    So I'm trying to determine in code at runtime if we're in an XBAP or not.   I didn't find any direct way to do it, so this was my strategy. 

     
                DependencyObject root = this.Parent; 
                while ((root as FrameworkElement).Parent != null) 
                { 
                    root = (root as FrameworkElement).Parent; 
                } 
                DependencyObject gridRoot = MainGrid.Parent; 

    And then I'd check to see if gridRoot was a Page or a Popup, if it is, its an XBAP. 
    But being pretty new to WPF, I'm not 100% sure if this will work in all cases?  Will it?
    Thanks.
    • Edited by kruston Friday, July 4, 2008 2:58 PM meant Page, not Window
    Friday, July 4, 2008 2:45 PM

Answers

All replies