How to change targetframework WP81 app - windows-phone-8

I have a Windows Phone 8.1 app in VS2015.
I am trying to add a property to my model that is not saved to the database. However, when I try to use the [NotMapped] annotation, I get the error:
The type or namespace name 'NotMapped' could not be found
I then added this using statement and tried to add it as a reference to the project. But apparently, I need to change my targetFramework in order to use this reference.
using System.ComponentModel.DataAnnotations.Schema;
Can a WP 8.1 app use the [NotMapped] annotation like below? Or is this not allowed in a WP app?
[NotMapped]
public double MyColumnName { get; set; }

The NotMappedAttribute is not available on Windows Phone 8.1.
Universal Windows Platform
Available since 10
.NET Framework
Available since 4.5
Source: MSDN
As Entity Framework is not available on Windows Phone 8.1, it's no use trying to use data annotations on the client. You'll have simple DTO classes on the client and more extensive models on the server backend where data-access to your database is handled. Converting between these 2 types can be done easily with tools like AutoMapper.
If you want to have some database on the WP client, you'll have to fall back to one of these options:
SQL CE
SQLite
Any other file based storage (json, xml, document based databases)

Related

Im using c# for a windows app , i want to use a arraylist , but i have system.collections in but it stil will not work

Hi I am trying to create a windows app in vs 2013, I want to use an array list, I do have system.collections in but it will not find array list what is the problem ?.
You want to use List<T> instead. ArrayList is not available in Windows runtime.
MSDN: List Class
Remember to include
using System.Collections.Generic;
The ArrayList is not available for Windows phone or you can say for > .net 3.0 .
They have removed and put the generic collections so you can possibly use a different collection class instead? Perhaps the List<T> type?
And System.Collections namespace for Metro Style applications lacks of ArrayList type.

how to lock the screen programmatically in windows phone 8?

We can prevent the screen to lock using the below code
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
and
PhoneApplicationService.Current.UserIdleDetectionMode= IdleDetectionMode.Disabled
but how to lock the screen from my app. Like the below app
http://www.windowsphone.com/en-us/store/app/one-touch-lockscreen/a3b1220b-1f9a-4bf0-93bc-21ed02792279
Thanks in advance
It's pretty hacky. It's not in the official API, so it could stop working at any time, just like the volume control API. Anyway, it you want to do it, you need to use this external method:
[System.Runtime.InteropServices.DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
For WP8.0 app this needs to be in a Windows Runtime Component (you should reference its output, as the project cannot be referenced).
From what I understand, though, this won't work on WP8.1 devices, so you'll need a separate WP8.1 app and I think it needs to be a XAML (Windows Store) app.
What #yasen wrote is correct.
[DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
I've tried the following cases:
Runtime 8.1 C# (Passed store certification)
Runtime 8.1 C++ with Runtime Component 8.1 C# (Haven't tried to publish this in store)
Silverlight/DirectX 8.0 C++ (Passed store certification)
Here's the link to my app that's using the last solution mentioned above.
http://www.windowsphone.com/s?appid=38bf5918-025e-4f23-b515-2cac451a84ab
And I've heard about cases in store using Silverlight that supports 8.0 and 8.1.
You can get Screen is locked or not by Windows.Phone.System.SystemProtection.ScreenLocked
but Unfortunately There is no way to lock the screen via code in Windows Phone 7.x or 8.

What is the MvvmCross version of DeviceNetworkInformation.IsNetworkAvailable

I'm re-writing a Windows Phone app to make it cross platform using the excellent MvvmCross framework.
On Windows Phone I usually test DeviceNetworkInformation.IsNetworkAvailable to ensure I have a network connection before calling a REST service.
Is there a way of doing this in a cross-platform way using MvvmCross?
There is a cross-platform plugin Cirrious.MvvmCross.Plugins.Network specifically for Network functionality and this was originally built specifically to provide Reachability
However, sadly the WindowsPhone part of this isn't yet implemented! See https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network.Phone/Plugin.cs
If you need Reachability within a cross-platform app including WindowsPhone, I'd probably opt for adding this Network plugin, and then also modifying your WindowsPhone Setup to register something like:
public class MyReachability : IMvxReachability
{
public bool IsHostReachable(string host)
return // something using DeviceNetworkInformation.IsNetworkAvailable
}
}
// registered in Setup using:
protected override void InitializeLastChance() {
base.InitializeLastChance();
Mvx.RegisterType<IMvxReachability, MyReachability>();
}
Longer term, I'd be happy to see a decent implementation pushed back into the MvvmCross repository.
Also linking this question to: MvvmCross Reachability on Windows Phone and Network state with mvvmcross?

Windows RunTime Component with NetworkCredential in windows 8

I have created sample WindowsRunTimeComponent app in windows 8, with one property my class looks like..
namespace WindowsRunTimeComponentTest
{
public sealed class Class1
{
public NetworkCredential Credentials {get; set;}
}
}
when I tried to build this, its giving error :
Method 'WindowsRunTimeComponentTest.class1.Credentials.get()' returns System.Net.Credentials', which is not a valid Windows Runtime type. Methods exposed to Windows Runtime must return only Windows Runtime types.
I have vs2012.
please any idea what I have to change to resolve this issue?
My best guess is, when you create a Windows Runtime Component, your component can be used by languages that are not managed, like Javascript or C++.
Those languages don't know how to create specific .NET types such as NetworkCredentials.
For more info see the MSDN documentation here and this stackoverflow post.

Microsoft Azure dll throws an exception in .NET 4.0

I have developed on EXE project(use for startup task) and use following dlls of Microsoft Azure ,
It's work very well in .Net framework 3.5 but in my case i need to use system.runtime.serialization to serialize class as json string as per following way
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
ms.Dispose();
return retVal;
}
For this i need to change framework to 4.0 but at that time i got exception from Azure dlls
like
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
I think all Microsoft's dlls are with backward compatibly so what's going wrong in this matter?
I should find another way to serialize to json string?
OR
I should to change Azure's dlls to latest version?
Thanks in Advance.
If you write a console app in .NET4 and want to use the RoleEnvironment then you’ll get an error:
The type initializer for ‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’ threw an exception.
To get around this, just add a “useLegacyV2RuntimeActivationPolicy” to the startup tag generated in the default app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
This is because Microsoft.WindowsAzure.ServiceRuntime.dll is a mixed mode assembly. The useLegacyV2RuntimeActivationPolicy attribute is required for referencing any mixed mode assembly, not only the Windows Azure ones.
One thing you might want to check is target framework for your .Net project in Visual Studio. By default when you create a project in VS using .Net framework, it uses ".Net Framework 4 Client Profile". Try changing it to ".Net Framework 4" and see if that helps.