Navigate to XAML page when tile is pressed - c#

I'm working in WP8 and I would like to know if it's possible to redirect the user to a custom page instead of the default MainPage when the application's tile is pressed.
For example, Toast Notifications have a NavigationUri that let's you enter a custom page to load after it's pressed. On tiles you can only get that information and not set it.
So there is any other way or I'm missing something?

This is all covered nicely in this blog post: http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx?wa=wsignin1.0
Essentially the idea is to cancel the default navigation and then request a navigation to whichever Page you want.

When you are creating the tile, you are specifying the URL to which to navigate. Simply include an additional parameter, such as comingFrom and set it to tile - in the view OnNavigatedTo, check whether the parameter is present (QueryString is your friend).
If it is - you navigated from a tile. If it's not - you didn't.

Sounds like you need a SecondaryTile. SecondaryTiles allow you to navigate to a different page than your "MainPage" if you so desire.
Here is an example of how to create a secondary tile
ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Page2.xaml"));
if (tileToFind == null) // have not pinned this page yet!
{
// Create the tile if we didn't find it already exists.
var tileData = new StandardTileData
{
Title = "Navigate To Page2",
};
// Create the tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
ShellTile.Create(new Uri("/Page2.xaml", UriKind.Relative), tileData);
}
This will place a new tile on the start screen and when you tap it, it will navigate to Page2.

Related

Xamarin iOS - UIPageControl - Disable left/right tap to decrement/increment

I have a question that I believe is a little bit weird due to the lack of information I'm finding online.
In my program, there is a UIPageViewController that is overlayed by a UIPageControl. In my UIPageViewController, each View Controller has a table inside with a number of items. With pages being the name for my UIPageControl, when I use pages.UserInteractionEnabled = false; my tap gesture taps underneath of the UIPageControl and taps one of the items in the table, pushing a new view controller for that item. I don't want that to happen, but I also don't want the typical functionality of UIPageControl, which is to scroll left or right depending on the location of the touch. I want this UIPageControl on my user interface for purely the indication of how many pages and which page is the current page.
I've tried removing any existing gesture recognizers from the pages.GestureRecognizers collection and that didn't work. I've tried setting pages.AllTouchEvents += (sender, e) => { return; } which also did nothing.
A thought: I have the UIPageControl as a view that spans the width of the view. Could I add a UIView and then add the UIPageControl as a subview of that, and then call its .SizeToFit() method?
In any case, thanks for taking a look. Any help and/or ideas are appreciated.
Please try pageControl.DefersCurrentPageDisplay = true; to achieve your effect.
When it is set True, the current page indicator will not be rendered until we set the pageControl's CurrentPage to change its selected indicator.

Windows Phone 8.1 phone parameter data on backward navigation

I am creating a Windows Phone 8.1 App.
There are some screens on my app. On the first screen, I am navigate my screen to second screen with a parameter data. now i want to navigate to first screen from second screen with different parameter data.
Using Frame.Navigate(typeof(frame1),parameter); I can pass data from first screen to second screen (forward navigation)
Frame.Navigate(typeof(frame1), "data");
but how can I pass data from second screen to first screen (backward navigation) ?
The only solution I can think of is to declare a global variable in App.xaml.cs so that you can access it from Frame2 and set a value, then you get the value from Frame1.
public static Object navigationData
{
get;
set;
}
And from everywhere you access it using
var data = App.navigationData;
There is no easy solution. Using the Frame.GoBack method you cannot pass a parameter. Furthermore if you use NavigationHelper.GoBack you cannot pass a parameter neither. This is by desing. If you go back, you will open the view that was previous open. That is the definition of going back. You want to "restore" a previous state.
But there would be a possible solution, when you store your new data into a variable that you can access from frame1.
Can you state why you would use a different data for backwards navigation?
Another, better possibility is to use a ContentDialog. There you can add your desired ViewModel to the DataContext prior opening. After that the ContentDialog is closed you can validate the data passed to it.
ContentDialog cd = new MyContentDialog();
if (parameter != null)
{
cd.DataContext = // set context here;
}
await cd.ShowAsync();
//now lets validate or process the necessary data.

Is it Possible to Place a Permanent ShellTile on the Start Screen

I'm wondering if it is possible to leave out the Uri QueryString parameter so that when a user pins a tile, it may not link to the application. This would be for design reasons when pinning several ShellTiles onto the Start Screen. The user would of course have the option to delete the tile manually from the Start Screen or from a button within the app itself. It seems when trying this I am still taken to the application but a debug error also occurs.
An example of when I create the ShellTile is as follows
ShellTile.Create(new Uri("/MainPage.xaml?" + Constants.Key + title, UriKind.Relative), LiveTile);
Can this be modified somehow?
Your secondary tile must have unique navigation URI. However you could navigate to some page that would immediately close itself. It is not the best solution but there isn't any better way.
For uniqueness just use Guid. You can close app in code with Application.Current.Terminate() for example.

How to make a touchable notice top bar in windows phone?

How to make a touchable notice top bar in windows phone ?
I am new to C# and windows phone world.So may be my question has a simple
way to solve,but I google a lot ,and didn't work out.
here is my purpose: I have a timer running throughout my app,it request a
service for notice info every one hour, and show a "notice bar" on the top of
screen.
it is easy to get the information ,but when I want to show them to the Page,
here is my problem:
1.
I used system tray to show my info.
It works,but then I found there is no touch or click event for Progress
Indication bar.
I even add an event to Touch.FrameReported in App.xaml.cs , but still ,
when i touch the system tray area, the event doesn't fire.
2.
Then I want to use a Dynamic way to achieve it: add a text block to the
current page
I got the current page handler ,but case I only know the current page
handler's type is PhoneApplicationPage, I can't get my Root UI element
(all my page has a root element named "LayoutRoot")
And when I try to use reflect method to get the "LayoutRoot" property,
the return value is null.
The code looks like this :
Type type = PhoneApplicationPageHandler.getType()<
//I checked,the type is my page's type
type.getProperty("LayoutRoot") or type.getField("LayoutRoot")
//they all return null
BTW: LayoutRoot is a grid, and it is described in my page's .xmal file.
Now My option is to make all my page inherit a defalut page ,in this page ,I will
implement a method to fulfill my second way to simulate a "touchable top bar".
but I think this coding is ugly .
So, can anyone tell me :
1.how to add touch event to a SystemTray
or
2.how to get a handler of an ui element which is described in xaml, while I only have a PhoneApplicationPage type handler of that page.
You may use
1) a toast prompt described here http://windowsphonegeek.com/articles/WP7-Toast-Prompt-in-depth
2)or shell toast described here http://www.c-sharpcorner.com/UploadFile/ae35ca/working-with-toast-notification-in%C2%A0windows-phone-7/ according to what suits your requirement the best. 3)You may also create a custom control which you may place on the top on your mainPage and handle its tap event accordingly.

MonoTouch.Dialog: Back item in NavigationBar

I m having a hard time with this issue.
My MainWindow.xib, has a NavigationController, the view for which is inherited from another xib.
Now, i push a DialogViewController from the main view, but i cannot see a back button on the second view's navigation bar.
Is there anything specific that i need to set for the DialogViewController when it is being pushed from a UIViewController.
Thanks and Regards
Abhishek
The constructor for DialogViewController has a parameter called pushing which you should set to true:
new DialogViewController(rootElement, true); // true will show the back button
Without seeing your code, I'm not sure exactly what's going wrong here. However, from what I know of UINavigationController, the view controller stack starts empty. When you push the first view controller, it gives the navigation controller a view to display, but it has nothing to go 'back' to, so it does not display a back button. If you push a second view, you may get a back button.
Also, be sure that the Title property is set on your child view controllers if you want the back button to reflect the view you will be going back to.
I have a tab bar controller which then hands off to a nav controller (in a storyboard with flyoutnavcontollers too). One of the viewcontrollers from here launches into a dialogviewcontroller for MT.D stuff.
I wanted a lovely pointed/tapered back button from monotouch dialog back to my calling point in the navigation controller.
But launching into MT.D loses the navigation even when im using the current navigation controller for some reason i.e. the button is not displayed and no way to get back. Subsequent mt.d screens give a back button.
Apparently your supposed to pass a true boolean into call to enable back button whilst pushing onto existing stack but this didnt work for me:
this.NavigationController.PushViewController (dv, true);
Dan's above solution didnt work for me. But popping the current dialogviewcontroller whilst at the root MT.D screen helps to get back to my previous position in the original nav controller in the storyboard (or flyoutnav controller).
Not sure if this hack is the correct way but it works.
dv.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Back",UIBarButtonItemStyle.Bordered,delegate(object sender,EventArgs e)
{
NavigationController.PopViewControllerAnimated(true);
});
* update
I manged to get a back button by adding the dialogviewcontroller to current viewcontrollers subview:
dvc = new MyDvcController(this.NavigationController);
this.View.AddSubview(dvc.TableView);
the corresponding MyDvcController mainly loooks like this:
public partial class MyDvcController : DialogViewController
{
public MyDvcController (UINavigationController nav): base (UITableViewStyle.Grouped, null)
{
navigation = nav;
Root = new RootElement ("Demos"){
new Section ("Element API"){
new StringElement ("iPhone Settings Sample", DemoElementApi),
}
};
}
}
this allowed the monotouch.dialog to be part of the current navigation controllers stack and achieve automatic back button with the tapered look ..yay
You can also implement by yourself
dialogViewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Back",UIBarButtonItemStyle.Bordered,delegate(object sender,EventArgs e)
{
NavigationController.DismissModalViewControllerAnimated(true);
});

Categories

Resources