EzDevInfo.com

windows-phone-8.1 interview questions

Top windows-phone-8.1 frequently asked interview questions

Hide Status bar in Windows Phone 8.1 Universal Apps

How to hide the Status bar in Windows Phone 8.1 (C#, XAML)?

In Windows Phone 8 it was done by setting shell:SystemTray.IsVisible="False" at any page. But its not available in Windows Phone 8.1


Source: (StackOverflow)

Windows Phone 8.1 - Page Navigation

Coming from Windows Phone 8 I have never thought there will be a lot of changes done to the Windows Phone 8.1 code. Basically I'm just wondering how to do page navigation just like how you would do it on Windows Phone 8. To do that you should add:

NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

but that code doesn't work for Windows Phone 8.1.

Can someone please help me with this? If possible provide any links or documentation on all the new Windows Phone 8.1 methods.


Source: (StackOverflow)

Advertisements

Animate (smoothly) ScrollViewer programatically

Is there a way to smoothly animate a ScrollViewers vertical offset in Windows Phone 8.1 Runtime?

I have tried using the ScrollViewer.ChangeView() method and the change of vertical offset is not animated no matter if I set the disableAnimation parameter to true or false.

For example: myScrollViewer.ChangeView(null, myScrollViewer.VerticalOffset + p, null, false); The offset is changed without animation.

I also tried using a vertical offset mediator:

/// <summary>
/// Mediator that forwards Offset property changes on to a ScrollViewer
/// instance to enable the animation of Horizontal/VerticalOffset.
/// </summary>
public sealed class ScrollViewerOffsetMediator : FrameworkElement
{
    /// <summary>
    /// ScrollViewer instance to forward Offset changes on to.
    /// </summary>
    public ScrollViewer ScrollViewer
    {
        get { return (ScrollViewer)GetValue(ScrollViewerProperty); }
        set { SetValue(ScrollViewerProperty, value); }
    }
    public static readonly DependencyProperty ScrollViewerProperty =
            DependencyProperty.Register("ScrollViewer",
            typeof(ScrollViewer),
            typeof(ScrollViewerOffsetMediator),
            new PropertyMetadata(null, OnScrollViewerChanged));
    private static void OnScrollViewerChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
    {
        var mediator = (ScrollViewerOffsetMediator)o;
        var scrollViewer = (ScrollViewer)(e.NewValue);
        if (null != scrollViewer)
        {
            scrollViewer.ScrollToVerticalOffset(mediator.VerticalOffset);
        }
    }

    /// <summary>
    /// VerticalOffset property to forward to the ScrollViewer.
    /// </summary>
    public double VerticalOffset
    {
        get { return (double)GetValue(VerticalOffsetProperty); }
        set { SetValue(VerticalOffsetProperty, value); }
    }
    public static readonly DependencyProperty VerticalOffsetProperty =
            DependencyProperty.Register("VerticalOffset",
            typeof(double),
            typeof(ScrollViewerOffsetMediator),
            new PropertyMetadata(0.0, OnVerticalOffsetChanged));
    public static void OnVerticalOffsetChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
    {
        var mediator = (ScrollViewerOffsetMediator)o;
        if (null != mediator.ScrollViewer)
        {
            mediator.ScrollViewer.ScrollToVerticalOffset((double)(e.NewValue));
        }
    }

    /// <summary>
    /// Multiplier for ScrollableHeight property to forward to the ScrollViewer.
    /// </summary>
    /// <remarks>
    /// 0.0 means "scrolled to top"; 1.0 means "scrolled to bottom".
    /// </remarks>
    public double ScrollableHeightMultiplier
    {
        get { return (double)GetValue(ScrollableHeightMultiplierProperty); }
        set { SetValue(ScrollableHeightMultiplierProperty, value); }
    }
    public static readonly DependencyProperty ScrollableHeightMultiplierProperty =
            DependencyProperty.Register("ScrollableHeightMultiplier",
            typeof(double),
            typeof(ScrollViewerOffsetMediator),
            new PropertyMetadata(0.0, OnScrollableHeightMultiplierChanged));
    public static void OnScrollableHeightMultiplierChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
    {
        var mediator = (ScrollViewerOffsetMediator)o;
        var scrollViewer = mediator.ScrollViewer;
        if (null != scrollViewer)
        {
            scrollViewer.ScrollToVerticalOffset((double)(e.NewValue) * scrollViewer.ScrollableHeight);
        }
    }
}

and I can animate the VerticalOffset property with DoubleAnimation:

Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.EnableDependentAnimation = true;
da.From = Mediator.ScrollViewer.VerticalOffset;
da.To = da.From + p;
da.Duration = new Duration(TimeSpan.FromMilliseconds(300));
da.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseOut };
Storyboard.SetTarget(da, Mediator);
Storyboard.SetTargetProperty(da, "(Mediator.VerticalOffset)");
sb.Children.Add(da);

sb.Begin();

Mediator is declared in XAML. But this animation is not smooth on my device (Lumia 930).


Source: (StackOverflow)

Device Unique id in Windows Phone 8.1

How to get the device unique id in Windows Phone 8.1? The old way of using DeviceExtendedProperties.GetValue("DeviceUniqueId") does not work for Windows Universal app.


Source: (StackOverflow)

Windows Phone Silverlight 8.1 project app submission error

I submit a test Windows Phone Silverlight Project 8.1 and get this error when submit

The package identity associated with this update doesn't match the uploaded appx: "2e740376-677c-4df8-b1af-95b72863f017"

Windows Phone 8.0 project dont meet that error. Any suggestion? Thanks


Source: (StackOverflow)

Disable web page navigation on swipe(back and forward)

On a Windows phone, in IE users can go back and forward by swiping on the screen if the swipe is coming from the edge. This OS level functionality is hampering my webpage's UX.

Is there any js or css which can disable that? Some hack would also do.

A snapshot from windowsphone's website: enter image description here

Here is the link to the reference page: http://www.windowsphone.com/en-in/how-to/wp8/basics/gestures-swipe-pan-and-stretch

Please note that I still need touchaction enabled for horizontal scrolling.


Source: (StackOverflow)

"A specified communication resources(port) is already in use" when attaching the debugger

I have just upgrade my windows phone 8 to windows phone 8.1. When I connect my phone to pc and run my project it gives me

a specified communication resources(port) is already in use by another application.

I restarted my PC and Phone, removed all connected external devices but still getting same error while running my code through Visual Studio 2012.

I can see it's deployed on phone but I can't debug it. Debugger is not attaching.

Here is my screen shot:

enter image description here


Source: (StackOverflow)

Make a phone call in Windows Phone 8.1

I'm writing a Universal App for Windows 8.1 / Windows Phone 8.1 that at some point displays a list of phone numbers. What I would like to do is allow the user to press one of these numbers and have the device call (or ask permission to call) that number if running on Windows Phone 8.1. I know this was previously possible in Windows Phone 8 by doing the following:

using Microsoft.Phone.Tasks;

PhoneCallTask phoneCallTask = new PhoneCallTask();

phoneCallTask.PhoneNumber = "2065550123";
phoneCallTask.DisplayName = "Gage";

phoneCallTask.Show();

NOTE: This code is wrapped in #if WINDOWS_PHONE_APP

However, when trying to import Microsoft.Phone.Tasks, Visual Studio is unable to find the reference. I know that "ID_CAP_PHONEDIALER" had to be enabled in WMAppManifest.xml in Windows Phone 8, but this doesn't seem to be possible with the universal app model. I've been searching around for a solution but can't find a recent one that includes Windows Phone 8.1 (not Silverlight).

Is there any way to make a phone call from within a universal app? Or is it simply not possible at the moment?


Source: (StackOverflow)

ListView in Windows Phone 8.1 Wobbles while scrolling though long list (XAML)

I'm having issues with scrolling through ListViews in my Windows Phone 8.1 App. Short lists scroll just fine, scrolling smoothly however as soon Virtualization kicks in the entire ListView "wobbles" to the left slightly, but noticeable enough to be annoying.

I've tried remove all the transitions to no effect as well as having items load incrementally to no success. Setting the item panel to a StackPanel (removing virtualization) fixes the issue but is not preferable.

My listviews are binding to a property in the DefaultViewModel that comes with the Basic Page Template.

What am I doing wrong and what are causing my ListViews to exhibit this behavior?

XAML:

<ListView x:Name="searchResultsList" IsItemClickEnabled="True" ItemClick="ListView_ItemClick" ItemsSource="{Binding searchResults}">
   <ListView.ItemContainerStyle>
      <Style TargetType="ListViewItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
          <Setter Property="Margin" Value="0,0,0,20" />
      </Style>
   </ListView.ItemContainerStyle>
   <ListView.ItemTemplate>
      <DataTemplate>
          <Grid>
             <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="*" />
             </Grid.ColumnDefinitions>

             <Border Width="80" Height="80">
                <Image Source="{Binding Image}" />
             </Border>

             <StackPanel Grid.Column="2">
                <TextBlock Text="{Binding PodcastTitle}" TextWrapping="WrapWholeWords" FontSize="{StaticResource TextStyleExtraLargeFontSize}" />
                <TextBlock Text="{Binding LastUpdated, Converter={StaticResource dateConverter}}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" />
                <TextBlock Text="{Binding PodcastArtist}" TextWrapping="WrapWholeWords" Style="{ThemeResource ListViewItemContentTextBlockStyle}" />
             </StackPanel>
           </Grid>
       </DataTemplate>
   </ListView.ItemTemplate>
 </ListView>

Source: (StackOverflow)

Suspending event not raising using WinRT

I'm having a problem with suspending event on Windows Phone 8.1 using WinRT, it does not fire. I don't know why. This is my code:

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
    InitializeComponent();

    Suspending += OnSuspending;
#if DEBUG
    this.displayRequest = new DisplayRequest();
#endif
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">
/// The source of the suspend request.
/// </param>
/// <param name="e">
/// Details about the suspend request.
/// </param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    deferral.Complete();
}

I set a breakpoint on the line var deferral = e.SuspendingOperation.GetDeferral(); and debugged it with Visual Studio. Then I pressed the start button on my phone and ran another app and waited about 10 seconds. OnSuspending is not running.

Any ideas?


Source: (StackOverflow)

Universal Apps MessageBox: "The name 'MessageBox' does not exist in the current context"

I want to use MessageBox for showing download errors in my WP8.1 app.

I added:

using System.Windows;

but when I type:

MessageBox.Show("");

I get error:

"The name 'MessageBox' does not exist in the current context"

In Object Browser I found that such class should exist and in "Project->Add reference... ->Assemblies->Framework" is shown that all assemblies are referenced.

Do I miss something? Or is there another way how to show something like messagebox?


Source: (StackOverflow)

Getting Windows Phone version and device name in Windows Phone 8.1 XAML

In Windows Phone 8 Silverlight I use

 Environment.OSVersion.ToString()

to get Windows Phone version and

DeviceStatus.DeviceManufacturer+" "+DeviceStatus.DeviceName

to get device name.

These APIs no longer work with Windows Phone 8.1 XAML. I have found

Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()

this seems to return the manufacturer and device name but OS is returned as just "Windows Phone".

Is there a way to get the exact Windows phone version?


Source: (StackOverflow)

ArgumentException - Use of undefined keyword value 1 for event TaskScheduled in async

Getting System.ArgumentException - Use of undefined keyword value 1 for event TaskScheduled in async apis.

There is something wrong when running the first await statement in an Universal app with Visual Studio 2013 Update 3.

I am using WP8.1 Universal and silverlight apps after I installed Visual Studio 2013 Update 3.

The exceptions happens in Emulator/Device modes. I have spent a couple of days researching this issue without any resolution.

I have a sibling article at Windows Dev center forum but I have not heard any answers from Microsoft.

The code is straight forward. Once the internal exception is thrown, the await never returns.

Is anyone else having these issues with async ?? resolution ?

public async Task<StorageFolder> FolderExists(StorageFolder parent, string folderName)
{
    StorageFolder result = null;
    try
    {
        // Exception happens here. The code never returns so the thread hangs
        result = await parent.GetFolderAsync(folderName);
    }
    catch (Exception ex)
    {
        if (FeishLogger.Logger.IsDebug)
            ex.LogException(() => string.Format("FolderExists File: {0}\\{1}", parent.Path, folderName));
    }

    return result;
}

Full exception:

System.ArgumentException occurred
  _HResult=-2147024809
  _message=Use of undefined keyword value 1 for event TaskScheduled.
  HResult=-2147024809
  IsTransient=false
  Message=Use of undefined keyword value 1 for event TaskScheduled.
  Source=mscorlib
  StackTrace:
       at System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UInt64 keywords, String eventName)
  InnerException: 

I have a sample project available. Creating a shell Universal App and adding some await statement makes the problem reocur.

private async Task AsyncMethod()
{
    Debug.WriteLine("({0:0000} - Sync Debug)", Environment.CurrentManagedThreadId);

    // Uncomment this line to make it work
    //await Task.Delay(1);

    // Fails only if the line above is commented
    await Task.Run(() => Debug.WriteLine("({0:0000} - Async Debug)", Environment.CurrentManagedThreadId));
}

VS error

Here is the full OnLaunched code with calls to AsyncMethod

   protected override async void OnLaunched(LaunchActivatedEventArgs e)
    {
      #if DEBUG
        if (System.Diagnostics.Debugger.IsAttached)
        {
            this.DebugSettings.EnableFrameRateCounter = true;
        }
      #endif

        Frame rootFrame = Window.Current.Content as Frame;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();

            // TODO: change this value to a cache size that is appropriate for your application
            rootFrame.CacheSize = 1;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // TODO: Load state from previously suspended application
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }

        if (rootFrame.Content == null)
        {
         #if WINDOWS_PHONE_APP
            // Removes the turnstile navigation for startup.
            if (rootFrame.ContentTransitions != null)
            {
                this.transitions = new TransitionCollection();
                foreach (var c in rootFrame.ContentTransitions)
                {
                    this.transitions.Add(c);
                }
            }

            rootFrame.ContentTransitions = null;
            rootFrame.Navigated += this.RootFrame_FirstNavigated;
         #endif

            await AsyncMethod();

            await AsyncMethods();
            await AsyncMethods();
            await AsyncMethods();


            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }
        }

        // Ensure the current window is active
        Window.Current.Activate();
    }

Source: (StackOverflow)

Get device screen resolution in Windows Phone 8.1 XAML

In Windows Phone 8 I can get the screen resolution using DeviceExtendedProperties or Application.Current.Host.Content.ScaleFactor. None of this works in Windows Phone 8.1 XAML.

I could not find a way how to get the screen resolution in Windows Phone 8.1 XAML, is there a way?


Source: (StackOverflow)

Windows Phone 8.1 Universal App terminates on navigating back from second page?

I have 2 pages in my Windows Phone 8.1 Universal App.

I navigate from Page1.xaml to Page2.xaml by using a button with the click event code:

this.Frame.Navigate(typeof(Page2));

When I am on Page2, and I use the hardware back button the app closes without an exception or anything. It just returns to the startscreen.

I already tried the following on Page 2:

public Page2()
    {
        this.InitializeComponent();
        Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    }

    void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
    {
        Frame.GoBack();
    }

As far as I know I do not clear the back stack.

What is going on, and how can I fix this?

Kind regards, Niels


Source: (StackOverflow)