Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(D:\InetPub\vhosts\iasync-5360.package\karthiknadig.com\wwwroot/wp-content/plugins/http://karthiknadig.com/wp-content/plugins/lightbox-plus/languages/lightboxplus-en_US.mo) is not within the allowed path(s): (D:/InetPub/vhosts/iasync-5360.package\;C:\Windows\Temp\) in D:\InetPub\vhosts\iasync-5360.package\karthiknadig.com\wwwroot\wp-includes\l10n.php on line 556
Windows Store App: Is my app on the left or right? | Normal

Windows Store App: Is my app on the left or right?

Karthik Nadig

While writing code, I wondered if there was a simple way to detect where on the display my app would be rendered. If I could detect the location, I could write an app to automatically adjust the layout for easy access and usage. I’m going to describe one possible way to do it.

Important Stuff

The class that will help us detect the location of the app is the ApplicationView class. The members of interest of this class are, AdjacentToLeftDisplayEdge, AdjacentToRightDisplayEdge, and IsFullScreen. We can acquire an instance of this class for the current application by calling, GetForCurrentView() static method.

Code Stuff

In XAML based apps we must attach an event handler to Window.Current.SizeChanged event. This will trigger when the screen size changes or if the app is moved around. However, I have seen that this doesn’t trigger when the app is displayed in full screen mode. We may also need to attach an event to SizeChanged event for the XAML page. See the code snippet below.

For JavaScript based apps we only need to add the app.onresize event.

C# code snippet:

Be sure to include namespace Windows.UI.ViewManagement.

   1:  ApplicationView appView = 
   2:      ApplicationView.GetForCurrentView();
   3:   
   4:  if (appView.IsFullScreen)
   5:  {
   6:      // App is full screen
   7:  }
   8:  else
   9:  {
  10:      if (!appView.AdjacentToLeftDisplayEdge && 
  11:          !appView.AdjacentToRightDisplayEdge)
  12:      {
  13:          // App is in the center and not full-screen
  14:      }
  15:      else if (appView.AdjacentToLeftDisplayEdge)
  16:      {
  17:          // App is on the left edge
  18:      }
  19:      else if (appView.AdjacentToRightDisplayEdge)
  20:      {
  21:          // App is on the right edge
  22:      }
  23:  }
C++/CX code snippet:

Be sure to use namespace Windows::UI::ViewManagement.

   1:  ApplicationView^ appView = 
   2:      ApplicationView::GetForCurrentView();
   3:   
   4:  if (appView->IsFullScreen)
   5:  {
   6:      // App is full screen
   7:  }
   8:  else
   9:  {
  10:      if (!appView->AdjacentToLeftDisplayEdge && 
  11:          !appView->AdjacentToRightDisplayEdge)
  12:      {
  13:          // App is in the center and not full-screen
  14:      }
  15:      else if (appView->AdjacentToLeftDisplayEdge)
  16:      {
  17:          // App is on the left edge
  18:      }
  19:      else if (appView->AdjacentToRightDisplayEdge)
  20:      {
  21:          // App is on the right edge
  22:      }
  23:  }
JavaScript code snippet:

Most other parts of code are similar to C# snippet.

   1:  var appView = 
   2:      Windows.UI.ViewManagement.ApplicationView.getForCurrentView();

Visual Studio 2013:


Leave a Reply