EzDevInfo.com

windows-phone-8 interview questions

Top windows-phone-8 frequently asked interview questions

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)

Why does the Synchronized method always return false?

In Windows Phone 8 (only on device!) try running this code:

public MainPage()
{
    InitializeComponent();

    var myTrue = GetTrue();
    Debug.WriteLine(myTrue);
    // false
}

[MethodImpl(MethodImplOptions.Synchronized)]
private static bool? GetTrue()
{
    return true;
}

You will see myTrue always is False! Why?! How it can be?!

UPDATE: Tested on devices: Nokia Lumia 920, HTC 8X, Nokia Lumia 925


Source: (StackOverflow)

Advertisements

Windows Phone 8: How to animate page navigation?

I am new to Win Phone 8 development and after a tiresome unfruitful Googling, I am posting this simple question here:

How to animate page navigation?

Yes, I know how to navigate from one page to another:

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

But this navigation is instant, and doesn't include any kind of transition. Please help SO!


Source: (StackOverflow)

.Net - DateTime.ToString("MM/dd/yyyy HH:mm:ss.fff") resulted in something like "09/14/2013 07.20.31.371"

I have a WP8 app, which will send the current time to a web service.

I get the datetime string by calling DateTime.ToString("MM/dd/yyyy HH:mm:ss.fff"). For most users it works great and gives me the correct string like "09/10/2013 04:04:31.415". But for some user the resulted string is something like "09/14/2013 07.20.31.371", which causes problem in my web service.

Is it because some culture format issue? How can I make sure the result string is delimited by colon instead of dot?


Source: (StackOverflow)

UDP multicast group on Windows Phone 8

OK this is one I've been trying to figure out for a few days now. We have an application on Windows Phone 7 where phones join a multicast group and then send and receive messages to the group to talk to each other. Note - this is phone to phone communication.

Now I'm trying to port this application to Windows Phone 8 - using the 'Convert to Phone 8' feature in Visual Studio 2012 - so far so good. Until I try to test the phone to phone communication. The handsets seem to join the group fine, and they send the datagrams OK. They even receive the messages that they send to the group - however, no handset ever receives a message from another handset.

Here is the sample code behind to my page:

// Constructor
public MainPage()
{
    InitializeComponent();
}

// The address of the multicast group to join.
// Must be in the range from 224.0.0.0 to 239.255.255.255
private const string GROUP_ADDRESS = "224.0.1.1";

// The port over which to communicate to the multicast group
private const int GROUP_PORT = 55562;

// A client receiver for multicast traffic from any source
UdpAnySourceMulticastClient _client = null;

// Buffer for incoming data
private byte[] _receiveBuffer;

// Maximum size of a message in this communication
private const int MAX_MESSAGE_SIZE = 512;

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    _client = new UdpAnySourceMulticastClient(IPAddress.Parse(GROUP_ADDRESS), GROUP_PORT);
    _receiveBuffer = new byte[MAX_MESSAGE_SIZE];

    _client.BeginJoinGroup(
        result =>
        {
            _client.EndJoinGroup(result);
            _client.MulticastLoopback = true;
            Receive();
        }, null);
}

private void SendRequest(string s)
{
    if (string.IsNullOrWhiteSpace(s)) return;

    byte[] requestData = Encoding.UTF8.GetBytes(s);

    _client.BeginSendToGroup(requestData, 0, requestData.Length,
        result =>
        {
            _client.EndSendToGroup(result);
            Receive();
        }, null);
}

private void Receive()
{
    Array.Clear(_receiveBuffer, 0, _receiveBuffer.Length);
    _client.BeginReceiveFromGroup(_receiveBuffer, 0, _receiveBuffer.Length,
        result =>
        {
            IPEndPoint source;

            _client.EndReceiveFromGroup(result, out source);

            string dataReceived = Encoding.UTF8.GetString(_receiveBuffer, 0, _receiveBuffer.Length);

            string message = String.Format("[{0}]: {1}", source.Address.ToString(), dataReceived);
            Log(message, false);

            Receive();
        }, null);
}

private void Log(string message, bool isOutgoing)
{
    if (string.IsNullOrWhiteSpace(message.Trim('\0')))
    {
        return;
    }

    // Always make sure to do this on the UI thread.
    Deployment.Current.Dispatcher.BeginInvoke(
    () =>
    {
        string direction = (isOutgoing) ? ">> " : "<< ";
        string timestamp = DateTime.Now.ToString("HH:mm:ss");
        message = timestamp + direction + message;
        lbLog.Items.Add(message);

        // Make sure that the item we added is visible to the user.
        lbLog.ScrollIntoView(message);
    });

}

private void btnSend_Click(object sender, RoutedEventArgs e)
{
    // Don't send empty messages.
    if (!String.IsNullOrWhiteSpace(txtInput.Text))
    {
        //Send(txtInput.Text);
        SendRequest(txtInput.Text);
    }
}

private void btnStart_Click(object sender, RoutedEventArgs e)
{
    SendRequest("start now");
}

In order to simply test out the UDP stack, I downloaded the sample from MSDN found here and I tested this on a pair of Windows Phone 7 devices and it works as expected. Then I converted to Windows Phone 8 and deployed to my handsets, again the devices seem to initiate their connection, and the user can enter their name. However, again the devices can't see or communicate with other devices.

Finally I implemented a simple communication test using the new DatagramSocket implementation, and again I see successful initiation, but no inter-device communication.

This is the same code behind page using the datagram socket implementation:

// Constructor
public MainPage()
{
    InitializeComponent();
}

// The address of the multicast group to join.
// Must be in the range from 224.0.0.0 to 239.255.255.255
private const string GROUP_ADDRESS = "224.0.1.1";

// The port over which to communicate to the multicast group
private const int GROUP_PORT = 55562;

private DatagramSocket socket = null;

private void Log(string message, bool isOutgoing)
{
    if (string.IsNullOrWhiteSpace(message.Trim('\0')))
        return;

    // Always make sure to do this on the UI thread.
    Deployment.Current.Dispatcher.BeginInvoke(
    () =>
    {
        string direction = (isOutgoing) ? ">> " : "<< ";
        string timestamp = DateTime.Now.ToString("HH:mm:ss");
        message = timestamp + direction + message;
        lbLog.Items.Add(message);

        // Make sure that the item we added is visible to the user.
        lbLog.ScrollIntoView(message);
    });
}

private void btnSend_Click(object sender, RoutedEventArgs e)
{
    // Don't send empty messages.
    if (!String.IsNullOrWhiteSpace(txtInput.Text))
    {
        //Send(txtInput.Text);
        SendSocketRequest(txtInput.Text);
    }
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    socket = new DatagramSocket();
    socket.MessageReceived += socket_MessageReceived;

    try
    {
        // Connect to the server (in our case the listener we created in previous step).
        await socket.BindServiceNameAsync(GROUP_PORT.ToString());
        socket.JoinMulticastGroup(new Windows.Networking.HostName(GROUP_ADDRESS));
        System.Diagnostics.Debug.WriteLine(socket.ToString());
    }
    catch (Exception exception)
    {
        throw;
    }
}

private async void SendSocketRequest(string message)
{
    // Create a DataWriter if we did not create one yet. Otherwise use one that is already cached.
    //DataWriter writer;
    var stream = await socket.GetOutputStreamAsync(new Windows.Networking.HostName(GROUP_ADDRESS), GROUP_PORT.ToString());
    //writer = new DataWriter(socket.OutputStream);
    DataWriter writer = new DataWriter(stream);

    // Write first the length of the string as UINT32 value followed up by the string. Writing data to the writer will just store data in memory.
   // stream.WriteAsync(
    writer.WriteString(message);

    // Write the locally buffered data to the network.
    try
    {
        await writer.StoreAsync();
        Log(message, true);
        System.Diagnostics.Debug.WriteLine(socket.ToString());
    }
    catch (Exception exception)
    {
        throw;
    }
    finally
    {
        writer.Dispose();
    }
}

void socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
{
    try
    {
        uint stringLength = args.GetDataReader().UnconsumedBufferLength;
        string msg = args.GetDataReader().ReadString(stringLength);

        Log(msg, false);
    }
    catch (Exception exception)
    {
        throw;
    }
}

Last night I took the handsets home to test them on my home wireless network, low and behold I get successful device communication.

So to recap - my legacy Windows Phone 7 code runs fine on my work network. The port to Windows Phone 8 (no actual code change) does not send inter-device communication. This code does work on my home network. The code runs with the debugger attached and there are no signs of errors or exceptions anywhere during execution.

The handsets I'm using are:

Windows Phone 7 - Nokia Lumia 900 (* 2), Nokia Lumia 800 (* 3) Windows Phone 8 - Nokia Lumia 920 (* 1), Nokia Limia 820 (* 2)

These are all running the latest OS, and are in developer mode. Development environment is Windows 8 Enterprise running Visual Studio 2012 Professional

I cant tell you much about the work wireless network - other than the Phone 7 devices have no trouble.

As for the home wireless network i used, that's just a basic BT Broadband router with none of the 'out the box' settings altered.

Clearly there is an issue with the way that the two network are configured, but there is also very clearly an issue with the way Windows Phone 8 implements UDP messages.

Any input would be appreciated as this is driving me mad right now.


Source: (StackOverflow)

Controls on Pivot disappear

I have an app with a pivot control. The pivot control has two items (pages), both contain a grid. The grids contain a few buttons and one a map and the other a text block. When the app first runs the pivot works as expected. However, after the app has been running some time, like a day, all the controls on the pivot disappear after pivoting (or swiping). They appear momentarily while swiping, but disappear again once the pivot rests.

Has anyone else experienced this? What could be the cause and solution?

Video: http://www.youtube.com/watch?v=nd7bfTJ53Nk

Code: https://github.com/JamieKitson/TrackLog/


Source: (StackOverflow)

Install Visual Studio 2013 on Windows 7

I would like to install Visual Studio 2013 on Windows 7 64-bit.

For some reason, the installer says "Setup Blocked" with an error "This version of Visual Studio requires a computer with a newer version of Windows".

Error on installing Visual Studio 2013

This error is not exactly descriptive of what's wrong. The least I could do was verify that I have the following installed :

  1. Windows 7 Professional (64-bit) with Service Pack 1
  2. Internet Explorer 10
    • Version: 10.0.9200.16750
    • Update Versions: 10.0.12 (KB2898785)
  3. All Windows Updates that were available for installing on 11th of Dec. 2013.

Executed the installer with the /log winexp.log argument and got the following : winexp.log.

Any ideas of what else could be the problem ?

Thanks.

Edit : by looking at this question there was a crack that allowed installing Windows Phone's SDK on Windows 7 - does anyone know a similar solution for VS 2013 ?


Source: (StackOverflow)

How to Install Windows Phone 8 SDK on Windows 7

I have all my workspace and everything set up on Windows 7 but I also want to develop Windows Phone 8 but as stated on Microsoft website that It can not be installed on Windows 7.

Do anybody knows how to install in on Windows 7. I have found a crack but I don't know how to run this. You can get this from here Please tell me if anybody knows how to install it. here is a link to WP 8 ISO file

Edit:

There could be several reasons to install WP 8 in Windows 7. Like I have purchased a Wndows 7 recently and I don't want to make shift to Windows 8 right now, because I don't feel comfortable with its UI. Its more for a tablet or touch screen PC.

I have set-up all my workspace and other projects on Windows 7, I don't want to waste my time in setting up on Windows 8, I don't even know that how they gona perform on Windows 8. So there are so many genuine reasons.


Source: (StackOverflow)

Windows Phone 8 emulator error - Something happened while creating a switch

I have a similar problem like mentioned in this question:

Windows Phone 8 - Unable to create the virtual machine

But, my problem is a bit different in the error description:

enter image description here

The Windows Phone Emulator wasn't able to create the virtual machine: Something happened while creating a switch: Xde couldn't find an IPv4 address for the host machine.

I have SLAT compatible hardware, virtualization is enabled in BIOS, my Windows 8 installation is 64bit and it's not virtualized. Hyper-V is installed (tried reinstalling it, but it didn't help). EDIT: VirtualBox or any other virtualization software (except for Hyper-V) is not installed

EDIT2: Seem to have been some other networking software which was installed. Having to remove it sucks big time because I need it professionally. I hope they fix it.

EDIT3: I wrote about it in more details with all I could find on my blog.


Source: (StackOverflow)

How to interpret this stack trace

I recently released a Windows phone 8 app. The app sometimes seem to crash randomly but the problem is it crash without breaking and the only info I get is a message on output that tells me there were an Access violation without giving any details. So after releasing, from the crash reports I was able to obtain some more information, but they're kinda cryptical to me.

The info are:

Problem function: unknown //not very useful
Exception type: c0000005 //this is the code for Access violation exception
Stack trace: 
Frame    Image        Function      Offset 
0        qcdx9um8960                0x00035426 
1        qcdx9um8960                0x000227e2

I'm not used to work with memory pointer et similia and I'm not used to see a stack trace like that.

So I have those question:

  1. How should I interpret/read those information, what's the meaning of every piece of information?
  2. Is there a way to leverage those information to target my search for the problem?
  3. Is there a way to get those information while debugging in VS2012

Notes:

  • I'm not asking what an Access Violation is
  • I tagged this as c# and c++ because my code is in c# but the exception is generated (I'm semi-guessing) by c++ implementation for the WebBrowser component

edit:

I tried setting the Debug type to Native only, this let me obtain the same info I had in the crash report on the dev center. This way the debugger break when the exception is thrown and let me see the disassebled code, unfortunately there's no qcdx9um8960 .pdb file (even on Microsoft Symbol Server), so I don't know the function name that caused the error.


Source: (StackOverflow)

Windows Phone 8 emulator can't connect to the internet

I have Windows 8 installed inside of an emulator, and the new WP8 SDK installed on it. My problem is that the emulator can't connect to the internet. I don't have any proxy, and even disabled the firewall. It still doesn't seem to work though. When I look at the Network Connections sections I can see the new connections the hyper-v manager created for the emulator, and also the automatic bridge created, but even there the network status is "No Internet Connection".

Are there some properties I can manually change in Hyper-V or for the network to make everything work?

Update: I've done everything suggested including create my own switch and delete all others. It still doesn't work however. It doesn't work on cable and not on wifi. Maybe I'm missing something with how to set this up?

Also the WP emulator keeps offering me to connect to the internet every time. It always erases all of the definitions I've set up, replacing it with it's own definitions.


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)

Get Unique Device ID (UDID) under Windows Phone 8

Is there any unique device ID (UDID) or any similar ID I can read out on Windows Phone 8 (WP8) that doesn't change with hardware changes, app-reinstallation etc.?

In older Windows Phone versions there were such IDs: WP7: Device Status for Windows Phone

WP7.1: DeviceStatus Class

But they doesn't work anymore with SDK 8.0.

Why I ask: The idea is that a user gets some free credits with the first start of the the app and I want to avoid that the user just re-installs the app for getting new free credits. A registration with email or phone number could solve this, but if I can, I don't want do bother users at the first start with a registration.

---///---SOLUTION----------

I can confirm that DeviceExtendedProperties.GetValue("DeviceUniqueId") still works in WP 8.0. Got a little bit confused when I read the following text:

In Windows Phone OS 7.0, this class was used to query device-specific properties. In Windows Phone OS 7.1, most of the properties in DeviceExtendedProperties were deprecated, and the new DeviceStatus class should be used instead. However, where appropriate, you can still use any of the below properties that are not deprecated.

MSDN:DeviceExtendedProperties Class

I can run the following code, delete the app and re-install it and get the same ID:

byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
MessageBox.Show(DeviceIDAsString);

Source: (StackOverflow)

WP7 Application Bar Icons not showing on Simulator (but works in Blend)

It is most probably a stupid mistake, but can anyone tell me why my icons are showing in Blend, but not in the simulator (and not in VS10, but that's not really an issue)?

WP7 Application Bar Icons. Blend (left), Simulator (right)

Edit - Here is my XAML :

    <phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/share.png" Text="Partager"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar.edit.rest.png" Text="Note"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.camera.rest.png" Text="Photos/Vidéos"/>
        <shell:ApplicationBarIconButton IconUri="/Images/calendar.png" Text="Rendez-vous"/>
        <shell:ApplicationBar.MenuItems> 
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

My four .png files are 48x48, transparent .png with black foreground, since the appbar.*.rest.png files where like that and found in the Microsoft icons folder


Source: (StackOverflow)

Unable to create the virtual machine

I was so happy today that I have been finally able to install Windows Phone 8 SDK and try it a bit. I installed fresh new installation of Windows 8 Pro into my virtual machine (I am running if from Parallels) and then installed Windows Phone 8 SDK.

Everything went smooth, Visual Studio Express is installed and running, but when I created new project and tried to deploy it, VS fails with really weird message.

First of all, message box informing that "The Windows Phone Emulator wasn't able to create the virtual machine: Generic failure" appears. Really informing, really professional - generic error, that's really good. Then the information that deployment failed appears (thanks a lot for keeping me informed about that, I didn't noticed that it crashed completely). And then in the Error List, there is an information about "Invalid pointer" - even better. No clue at all about what failed or what's wrong.

Can anybody help me with that? There is nothing on the internet about this topic so far and I don't know where the problem is. I scanned the Windows events and logs, but there is nothing (probably I haven't been searching properly, so please guide me through that if you can).

Anybody can help?


Source: (StackOverflow)