WP8 - Automatically open keyboard on &123 option - c#

while developing a new Windows Phone 8 software, I got stuck with this issue.
I'd need to open the keyboard straight to this view:
But all I can do is this (just giving focus to a text-box, that's easy enough!):

Set the TextBox InputScope properties to Digits in your xaml code
<TextBox InputScope="Digits " Name="txtNumbers" />
and your code behind page use below line of code
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
txtNumbers.Focus();
}

Check this link for allowed scopes:
http://msdn.microsoft.com/en-us/library/system.windows.input.inputscopenamevalue%28VS.96%29.aspx
I believe the view you are after is called "Numeric Mode"; This following link has some images as well.
http://www.informit.com/articles/article.aspx?p=1706099&seqNum=2

Related

c# - How to access a variable from outside its class in a method in some other class?

I am a beginner in c# programming and I am developing windows phone application after reading some tutorials.
My idea is when the user clicks a button in a windows page, some other button in other windows phone page must change color from red to green.
Pardon me if I am too Basic.
This I have defined in a page named "IndexPage.xaml"
<Button x:Name="One_green"
Content="1"
Background="Green"
Click="One_Click"
/>
<Button x:Name="One_red"
Content="1"
Background="Red"
Click="One_Click"
/>
Now I see red color button in my window as green button is hidden in the back.
Now, the following code is from another windows phone page "1.xaml"
<Button Content="GO" Click="Button_Click"/>
Now when the user clicks the "GO" Button I want the button to change to red to green in "IndexPage.xaml". So I tried a code something like this in "1.xaml.cs"
private void Button_Click(object sender, RoutedEventArgs e)
{
One_red.Visibility = Visibility.Collapsed;
One_green.Visibility = Visibility.Visible;
}
But I am not able to access the "One_red" or "One_green" button in the above code. Please shed me directions.
Also I want that code to execute only once. (i.e.) when the IndexPage.xaml loads again I want that button to be green always.
Thank you very much in advance.
Please tell me if some other details are required.
You could define a public or internal static variable inside the "Index.xaml" class specifying what button will show on load until otherwise specified. This variable could be accessed outside the class, and possibly even outside the project depending on the modifier chosen. The constructor of the "Index.xaml" class could have code to reset it to the default to ensure it only happens on the next creation of the page. If you aren't creating a new page everytime, you would have to put the default resetters in a method called when you want to bring it to foreground.
It seems to me that you are trying to learn, rather than having a SPEC to follow and implement.
Because of that, and because you are starting with C# in 2014 (almost 2015),
it will be quite beneficial for you to jump straight to data-binding declarative over imperative, going MVVM (MVVx) over MVC (MVx).
XAML was designed around this pattern. It's the natural way of doing things in XAML, a perfect fit and the perfect platform to learn the pattern.
It requires lots of learning, thinking, and re-learning, but it will open your eyes to modern programming techniques.
That said... there are too many ways of doing what you asked for, and while none are exactly wrong, there are 2 current trends in .Net/C#/MsTech which IMO are NOT a waste of your time:
Functional Reactive Programming and OOP/MVVx (the x is for whatever).
Examples are ReactiveUI, Reactive Extensions, PRISM, Caliburn.Micro and many more. They can be combined, the same way you can combine traditional event-driven/event callbacks with MVVM and/or Reactive Programming. However, I would advise against it.
I'll start with the most documented way.
Look at Data binding for Windows Phone 8. It was the first result when I googled "windows phone 8 xaml data binding," and deals with Colors and controls.
If you follow that example and add a resource to your application, you are done.
Of course, you can still use event => onClick + static class to hold the value in between View instances, but if I was right on the assumption that you are trying to learn, I wouldn't go that route.
Sorry if I drifted. :)
You may not be able to access the button click event because it is private, you may need to make it protected or public, the default access specifier would probably be ok as well.
public void Button_Click(object sender, RoutedEventArgs e)
or default would be:
void Button_Click(object sender, RoutedEventArgs e)

Functions like Focus() and properties like Focusable not available for silverlight, only .NET?

Short version: Solutions like the following: How Do I Give a Textbox Focus in Silverlight?
Don't seem to work because functions like Focus and properties like Focusable DON'T EXIST for silverlight and only exist for .net apparently.
Background/Long Version: So I've been trying to get my XNA game to work on silverlight. Porting it was a nightmare but I managed to do it somehow. Currently I want to use ViewBox's so my game is as big as a players browser instead of a set size. When I tried to do it, it VISUALLY worked, but it was impossible to send any keyboard commands to the game. I'm pretty sure its preventing me from focusing it. When I google how to give focus, it gives me links like these where people are saying to use functions like .focus() which DON'T EXIST on silverlight 5 only .NET apparently. For example go here: http://msdn.microsoft.com/en-us/library/system.windows.controls.control(v=vs.110).aspx
It shows the .NET 4.5 version. If you change it to silverlight at the top, all the nice functions and settings disappear. Am I missing something here? How do I access the .Net versions of these classes in silverlight? If its not possible why are all those answers mentioned above use Focus() etc?
Assuming C#...
On your silverlight page, select yourPage_Created from write code menu
Add the following:
partial void YourPage_Created() // this line should be autogenerated
{
this.FindControl("YourControl").ControlAvailable += YourFieldAvailable;
}
private void YourFieldAvailable(object sender, ControlAvailableArguments e)
{
((System.Windows.Controls.Control)e.Control).GotFocus += YourRoutine;
}
private void YourRoutine(object sender, System.Windows.RoutedEventArgs e)
{
// do your focus specific code in here
}
You will now have a custom focus event for the specified control.
Hope this helps :)

How to resolve back button issue in windows phone 8 game application?

This question may be possible duplicate of
WP8 back button go two steps back
My game page structure as follow
MainPage(Select New Game) - > Level1 Page(After complete 60 sec this page automatically goto next page->Alert page (it contain TryAgain-Home-Exit Buttons if user click TryAgain Button "Level1" Page Show)
My problem start here..
Now User in "Level1" user click phone back button it show the Alert Page . it's wrong
but correct way is from "Level1" to MainPage
I try following code in Level1 Page
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
RootFrame.RemoveBackEntry();
base.OnBackKeyPress(e);
}
I got error in RootFrame The name 'RootFrame' does not exist in the current context
Any one tell me where i made mistake and what code i need to add for RootFrame. this is my first Wp8 game app development. Thank You
I just had this same problem. The tutorial uses RootFrame.RemoveBackEntry();
The default is NavigationService.RemoveBackEntry();

Reference is not a valid visual DependencyObject

I'm trying to use the coding4fun toolkit for windows phone 7.
InputPrompt input = new InputPrompt();
whoAreYou.Completed += input_Completed;
input.Title = "Who are you?";
input.Message = "Enter your name";
input.Show();
void input_Completed(object sender, PopUpEventArgs<object, PopUpResult> e)
{
//add some code here
InputPrompt input = sender as InputPrompt;
MessageBox.Show(input.Value);
}
This throws the exception below:
Reference is not a valid visual DependencyObject
I want to ask the user for his/her name.
I'm following this tutorial and have added the necessary assembly references.
How can I get the coding4fun toolkit to work?
Edit:
If I do this in xaml like
<c4f:InputPrompt x:Name="input" Completed="input_Completed_1" />
Then this works, but I need it to work with code.
I've reproduced your bug when I've added the code presented to the Main Page constructor. It seems like an InputPrompt isn't added to the visual tree (just a theory) and that's why can't be shown.
When I've changed the code to show InputPrompt upon Loaded event, everything worked fine. Basically, you have to wait until the page is loaded or put the control in your XAML file.

In Silverlight, what's the difference between UserControl_Loaded and Page_Loaded?

I'm trying to write a silverlight application that takes in InitParams and then uses those InitParams to make a change to the Source of the MediaElement on the page. I'm trying to figure out the proper place to put my code.
I watched Tim Heuer's excellent video on InitParams, but in the video (which was for Silverlight 2), it shows the following on the Page.xaml.cs:
void Page_Loaded(object sender, RoutedEventArgs e)
{
}
I don't see Page_Loaded when I open MainPage.xaml.cs, and I'm wondering if that was automatically created in the Silverlight 2 SDK and left out of the Silverlight 3 SDK. Or perhaps Tim added that in his video manually.
I find that I can go into the opening UserControl tag of MainPage.xaml and add Loaded="<New_Event_Handler>" which creates the following in MainPage.xaml.cs:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
}
By default, there's also the following in MainPage.xaml.cs, which is run during the Application_Startup event in App.xaml.cs:
public MainPage()
{
InitializeComponent();
}
I need to figure out where is the best place to insert my code to change the Source on my MediaElement in my xaml. Should I put it in MainPage? Should I add the Loaded event handler and put it into UserControl_Loaded? If it's supposed to be Page_Loaded, where do I find that in Silverlight 3?
Any help would be much appreciated.
"UserControl_Loaded" and "Page_Loaded" are just method names and the names don't matter (you could name the method "Foo" if you wanted). What makes these methods do anything is the fact that they are attached to the Loaded event on the UserControl (which is what you did when you edited the MainPage.xaml file).

Categories