How to use a string between two page in windowsphone - xaml

I have two page (main page / second page). I create a string in Mainpage.xaml.cs but I want to use that string in second page.
how can I do it?

You can do it by having another static class with a static string as its member, likewise:
public static class stringWrapper{
public static string message{get; set;}
}
and then set it in the MainPage.xaml.cs and then get its value in the secondPage.xaml.cs, likewise:
MainPage.xaml.cs :
stringWrapper.message = "Whatever your string is";
secondPage.xaml.cs :
string msg = stringWrapper.message;
Hope this helps.

You can have different solutions to this :
Make the string a public static property in a wrapper class as #cybertronhac mentioned.
Use the Messenger pattern (from Mvvm Light for example) to send your string to your second page when ever it's requested.
Change the DataContext of the object in SecondPage that needs to be bound to the string object,to be the MainPage.xaml.cs class

In the App.xaml.cs, outside the constructor "public App()" declare a variable(suppose 'a'). Made it public static. Then in the Mainpage.xaml.cs put your string in that variable 'a'. As you can access 'a' from any page of your project, you will get your desired string. I hope this will help. A sample is given below.
In the App.xaml.cs Page:
public static string a = "";
In the MainPage.xaml.cs Page:
App.a = "My Name is Neymar.";
Now you can show your string in a console in second page or you can use it for another purpose. Your valuable string is in variable 'a' which can be accessed by writing "App.a":
Debug.WriteLine("" + App.a);

Related

Privately declared properties in C# don't show up in TypeScript in SPA

So, i'm not sure what i'm doing wrong here but for some reason the callback function in TypeScript that i have doesn't have anything but _proto in the response's .data property whenever i set private properties in C# and new up an object that is filled with constructed properties. However, if the properties are public and i don't use a constructor then i can see the response's .data property is filled like i would expect it to be. Here is an example of what works:
public class ThisWorks{
public string MyProperty{get;set;}
}
Inside application layer:
ThisWorks example = new ThisWorks();
example.MyProperty = myReflectedProperty;
return example;
However, this does not work:
public class ThisDoesNotWork{
private string MyPrivateProperty {get;set;}
public ThisDoesNotWork(string myPrivateProperty){
MyPrivateProperty = myPrivateProperty;
}
}
What's causing this to happen? My TypeScript service has not changed but for some reason the data isn't coming across from the service call...Any help would be greatly appreciated!

Mvc4 Model to url querystring

I'm looking for a way to convert a mvc4 model to querystring.
The built-in mechanism of mvc4 is allowing me to do something like this:
#Url.Action("SearchWithQueryString","Search", new {#Title = "Title", #Author= " Author", #Date = "date"})
The result of this command is:
Url/Search/SearchWithQueryString?Title=title&Author=author&date=date
My goal is to pass a poco model and get the same result.
for example, if I have this class:
public class Test
{
public string Title {get;set;}
public string Author {get;set;}
public string Date {get;set;}
}
I want to be able to do something like this with using the built-in mechanism:
#Url.Action("SearchWithQueryString","Search", new Test())
and get the same result as I got previously.
Any ideas?
You should use the RouteValueDictionary class. This allows you to convert a model to a QueryString:
#Url.Action("SearchWithQueryString", "Search", new RouteValueDictionary(new Test()))
Where new Test() could also be Model for example.

RESTEasy mapping parameter with '-' in their name

A simple question (I hope so...) for RESTEasy experts.
I receive a form posted via POST which contains attributes with '-' in their names :
Example :
return-code=12
I want to map all the content of this POST into a Pojo :
public class MyFormInfo {
public String attr1="";
public String return_code=""; // don't work because return-code is not mapped in return_code
...
The method declaration is the following :
#POST
#Path("/return-cic-payment")
public String receiveForm(MyFormInfo form) throws Exception {
log.info("Return-code is : {}", form.return_code);
}
I don't to map attributes one by one in the parameters lists because the form contains a large number of fields.
Because I can't have an attribute named "return-code" in my POJO, I wonder how to do toget this parameter's value.
A custom mapping can be a solution, but I don't know how to achieve that.
Other idea I try without success, to receive a Map of attribute.
Thanks for your help.
Try this: http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html_single/#_Form
class MyFormInfo{
#FormParam("return-code")
private String returnCode;
//etc.
}

Can you turn off the # that prepends all properties return by the Domino Data Service in 8.5.3

For the Domino Data Services which is new with 8.53 and the XPages Extension library I want to turn off the # that prepends all properties that are returned in the JSON data from a REST API call.
e.g. currently it looks like this:
"#title":"($DircatConfig)",
"#folder":false,
"#private":false,
"#modified":"2012-02-03T14:50:03Z",
"#unid":"50458575F2AA5F918525690D004F0AB5",
"#href":"http:\/\/192.168.1.30:80\/names.nsf\/api\/data\/collections\/unid\/50458575F2AA5F918525690D004F0AB5"
The # symbol is causing me grief in Javascript frameworks which can bind to the data directly as you cannot use the dot notation to bind to individual property names if the include an #.
The framework I am trying is http://angularjs.org/ and an example bind might be
{{databases.#title}} <-- doesnt work whereas {{databases.title}} <--works
I have tagged this as XPages as its related to the extension library.
The attribute names are set in the class com.ibm.domino.services.rest.RestServiceConstants of the extlib, for example:
...
public static final String ATTR_UNID = "#unid"; //$NON-NLS-1$
public static final String ATTR_NOTEID = "#noteid"; //$NON-NLS-1$
public static final String ATTR_LINK = "#link"; //$NON-NLS-1$
public static final String ATTR_LINK_REL = "rel"; //$NON-NLS-1$
public static final String ATTR_LINK_HREF = "href"; //$NON-NLS-1$
...
Since they are public static final Strings, you would have to extend DAS and use your extended classes.
However I believe you should be able to access the attributes in this manner instead of dot notation:
database['#title']
Hope this helps.

Populating a property of type ObservableCollection in XAML with static resources

I have created a class that contains a property of type ObservableCollection. I am trying to create an instance of the class in XAML and fill this property with members. I keep getting an exception that class T can not be converted to ObservableCollection, but this exception only occurs when I am trying to populate the list with elements that were declared as static resources.
Anybody has an idea why?
The code is as follows:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mseg="clr-namespace:SegApp.Model.DataEntities.Segments;assembly=SegApp.Model.Silverlight">
<mseg:Dot xKey="d1"/>
<mseg:Dot xKey="d2"/>
<mseg:Dot xKey="d3"/>
<mseg:Dot xKey="d4"/>
<mseg:Segment xKey="seg1">
<mseg:Segment.Dots>
<StaticResource ResourceKey="d1"/>
<StaticResource ResourceKey="d2"/>
<StaticResource ResourceKey="d3"/>
<StaticResource ResourceKey="d4"/>
</mseg:Segment.Dots>
</mseg:Segment>
</ResourceDictionary>
The Class definition is:
public class Segment : Part
{
public ObservableCollection<Dot> Dots { get; set; }
public Segment()
{
Dots = new ObservableCollection<Dot>();
}
}
And the exception says:
"
Object of type bla.bla.bla.Dot can not
be converted to type
System.Collections.ObjectModel.ObservableCollection'1[bla.bla.bla.Dot]
"
Any ideas?
As is your code, each element of the collection must be a Dot, not a resource...
Each entry of the list in your xaml code must be something like
or perhaps try
somevalue
or
{staticResource xxx }
But there is still a problem. The 1st syntax is ok, the second can work if there is a simple content for Dot, but the 3rd can't run : tag means "create an instance of Dot". And a StaticResource means "create an instance of.. and give it a key".
So last syntax will certainly not work cause you can replace the instance created by the tag with the instance coming from the resource...
But give it a try. The main problem in your code is than you're trying to feel a collection of Dot with Resource, that can't work and the compiler is not ok.. try using tag to create entry. And then play a bit to see if you can refer the resources somewhere in these tags..
In order to use collections XAML syntax change your property and remove it's setter:
public class Segment : DependencyObject
{
private readonly ObservableCollection<Dot> _dots = new ObservableCollection<Dot>();
public ObservableCollection<Dot> Dots
{
get { return _dots; }
}
}