How do I set an orientation specific background in a Windows Store Application? - windows-runtime

I have a Windows Store Application where I've been supplied a different background image asset depending on whether the app is running in Portrait or Landscape mode.
Other than this background image, there are no other orientation specific differences.
What is the tidiest way to implement this requirement?

You can set it in Window.Current.SizeChanged handler:
Window.Current.SizeChanged += (sender, args) =>
{
if (ApplicationView.Value == ApplicationViewState.FullScreenLandscape)
{
// ...
}
else if (ApplicationView.Value == ApplicationViewState.FullScreenPortrait)
{
// ...
}
};

Related

Call showTab in the screen created event

I am using LightSwitch HTML and I have a screen with multiple tabs, and in the screen 'created' event I want to show one of the tabs based on some logic:
myapp.MyScreen.created = function (screen)
{
if (/* some logic */) {
screen.showTab("TabOne");
} else {
screen.showTab("TabTwo");
}
}
However this throws an error when I open the screen:
TypeError: Cannot read property 'pageName' of undefined.
Has anyone encountered this and found a workaround?
Thanks for the help,
In order to use the showTab API command in the screen's created event, its use needs to be delayed until the screen has fully displayed.
This can be achieved by using a combination of the jQuery mobile pagechange event (as the LightSwitch HTML Client uses jQuery mobile) and a setTimeout with a zero timeout (to delay the showTab until the loading screen is rendered).
The following shows a revised version of your example using this approach:
myapp.MyScreen.created = function (screen) {
$(window).one("pagechange", function (e, data) {
setTimeout(function () {
if (/* some logic */) {
screen.showTab("TabOne");
} else {
screen.showTab("TabTwo");
}
});
});
};
Alongside a more advanced alternative, this approach is covered in more detail in my answer to the following post:
LightSwitch Tabbed screen in Browse template
However, as this approach is based upon delaying the showTab until the initial screen has been fully displayed, it does result in a noticeable transition from the default tab to the one displayed by the showTab method.
Whilst slightly more involved, if you'd prefer to avoid this noticeable transition, it's possible to customise the LightSwitch library to introduce a new option into the standard showScreen method. This new option will allow the desired tab page name to be specified when showing a screen.
If you'd like to introduce this additional option, you'll need to reference the un-minified version of the LightSwitch library by making the following change in your HTML client's default.htm file (to remove the .min from the end of the library script reference):
<!--<script type="text/javascript" src="Scripts/msls-?.?.?.min.js"></script>-->
<script type="text/javascript" src="Scripts/msls-?.?.?.js"></script>
The question marks in the line above will relate to the version of LightSwitch you're using.
You'll then need to locate the section of code in your Scripts/msls-?.?.?.js file that declares the showScreen function and change it as follows:
function showScreen(screenId, parameters, options) {
//return msls_shell.showScreen(
// screenId, parameters, null, false,
// options ? options.beforeShown : null,
// options ? options.afterClosed : null);
return msls_shell.showScreen(
screenId, parameters,
options ? options.pageName : null,
false,
options ? options.beforeShown : null,
options ? options.afterClosed : null);
}
You can then use this new pageName option in any of the standard screen display methods as follows:
msls.application.showScreen("MyScreen", null, { pageName: "TabOne" });
// or
myapp.showScreen("MyScreen", null, { pageName: "TabOne" });
// or
myapp.showMyScreen(null, { pageName: "TabOne" });
This results in the screen being displayed on the desired tab, without a noticeable transition from the default tab.

How to know 720p or 1080p on windows phone 8?

Usually, I used Application.Current.Host.Content.ScaleFactor to checking my device's resolution, but now the value is the same for 720p and 1080p.
So then what differentiates them ? Thank you !
Here is a code snippet that gives the correct scale factor, even for 1080p devices:
public int ScaleFactor
{
get
{
object physicalScreenResolutionObject;
if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalScreenResolutionObject))
{
var physicalScreenResolution = (Size)physicalScreenResolutionObject;
return (int)(physicalScreenResolution.Width / 4.8);
}
return Application.Current.Host.Content.ScaleFactor;
}
}
Here are the corresponding resolutions for each scale factor values:
100 => WVGA (480*800)
150 => 720p (720*1280)
160 => WXGA (768*1280)
225 => 1080p (1080*1980)
Source: Handle 1080p in Windows Phone like a Pro!
follow the guidance as detailed in this post
http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/11/22/taking-advantage-of-large-screen-windows-phones.aspx
Here is something from the Nokia Developer blog.
public static Size DisplayResolution
{
get
{
if (Environment.OSVersion.Version.Major<8)
return new Size(480,800);
int scaleFactor=(int) GetProperty(System.Windows.Application.Current.Host.Content, "ScaleFactor");
switch (scaleFactor)
{
case 100:
return new Size(480, 800);
case 150:
return new Size(720, 1280);
case 160:
return new Size(768, 1280);
}
return new Size(480, 800);
}
}
private static object GetProperty(object instance, string name)
{
var getMethod= instance.GetType().GetProperty(name).GetGetMethod();
return getMethod.Invoke(instance, null);
}
Hope this helps!
XamlEssentials is a neat set of helpers for building XAML-based applications. Recently, it added some helper utilities to make it easy to deal with large-resolution screens.
The static property DisplayHelper.CurrentResolution returns an enum letting you know if the resolution is DisplayResolutions.WVGA, DisplayResolutions.WXGA, DisplayResolutions.HD720p, or DisplayResolutions.HD1080p.
The static property DisplayHelper.IsPhablet helps to determine if the screen size is greater than 5", which lets you render differently even if you're on a 6" 720p screen, like the Lumia 1320.
The static method ResourceHelper.AddPhabletStyle() lets you add a specific ResourceDictionary only if the screen is greater than 5 inches, so you can easily change the layout of a page depending on the size of the screen.
XamlEssentials also has other helpers that make dealing with the new additions to GDR3 easier. You can read more about those helpers here.
You can easily add XamlEssentials to your project from NuGet, or you can download the source from GitHub.
HTH!

Keep UINavigationBar height with prefersStatusBarHidden

At certain times in my app I am hiding the UIStatusBar on iOS 7.
-(UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationFade;
}
-(BOOL)prefersStatusBarHidden {
if (self.state == StateModal) {
return YES;
}
return NO;
}
However, this the y-origin of the view controller's UINavigationBar. It moves up since there is not UIStatusBar visible, but I would like to retain the height of the status bar, but makes it's content invisible.
Is this possible? I don't have to take iOS 6 into account, just iOS 7.
You can change current window windowLevel to UIWindowLevelStatusBar, when controller is appeared
https://stackoverflow.com/a/21158994/2035054

Change UIInterfaceOrientation for only one UIViewController

I have an app with one NavigationController and 4 UIViewController.
I like to have 3 UIViewController in UIInterfaceOrientationPortrait and one in the Landscape mode. The Landscape Orientation should appear immediately, when the view appears. Unfortunately, the mode changes only when I turn the device.
What can I do to change immediately to landscape without rotate the device?
Here is the code for my NavigationController.m
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
This is for the Portrait UIViewcontroller.m
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
And for the Landscape UIViewController.m :
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
// (iOS 6)
// Force to portrait
return UIInterfaceOrientationLandscapeRight;
}
In advance thanks for your help!

saving google map to image from a browser component window inside a c# application

I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.
I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}