Reputation: 65
I'm setting up a series of buttons, one for each item in a table. What I need to do is set the Navigate parameter for each button, is there anyway I can set the following from the .cs code?:
<ec:NavigateToPageAction TargetPage="/MissionPage.xaml"/>
Here's the code I'm using to make the buttons:
foreach (string i in missionQ)
{
Button btn = new Button() { Content = "Run", Width=120, Height=90 };
btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
btn.VerticalAlignment = System.Windows.VerticalAlignment.Top;
btn.Margin = new Thickness(0, (100*x), 20, 0); }
Upvotes: 0
Views: 246
Reputation: 609
You could try this code in your Click event of the button
using System.Windows.Navigation;
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/MissionPage.xaml.xaml", UriKind.Relative));
}
Upvotes: 1
Reputation: 352
The way I would handle this is by, creating a new eventhandler for the tap event on each button. Pass i as reference to the function.
btn.Tap += functionToHandleTap(i);
In the function it self I would create a switch or if statement and then navigate based on the i parameter passed to funtionToHandleTap.
private void functionToHandleTap(string i)
{
string naviString = string.Empty;
if (i == "something")
{
naviString = "some xaml here";
}
else
{
naviString = "another xaml here";
}
_rootFrame.Navigate(new Uri(naviString, UriKind.Relative));
}
Upvotes: 0