Gluon Mobile Scrollable Dropdown Button - gluon

Is there a way to make the dropdown button contents scrollable? I have a lot of menu items that extend the dropdown list beyond the screen of the device.
try {
DropdownButton merchantChooser = (DropdownButton) this.view.lookup("#review-merchant-chooser");
VBox container = (VBox) this.view.lookup("#review-container");
TextArea area = (TextArea) this.view.lookup("#review-text");
StackPane sp = (StackPane) this.view.lookup("#review-wrapper");
Button btn = (Button) this.view.lookup("#review-submit");
Utility.setBackground(sp, Utility.bannerImg2);
Utility.setFadedBackground(true, container);
merchantChooser.getItems().clear();
if (MainView.merchants.isInitialized()) {
btn.setDisable(false);
MenuItem firstItem = null;
for (int i = 0; i < MainView.merchants.size(); i++) {
Label label = new Label(MainView.merchants.get(i).getName());
label.setWrapText(true);
MenuItem item = new MenuItem(label.getText());
merchantChooser.getItems().add(item);
if(i == 0)
firstItem = item;
}
merchantChooser.setSelectedItem(firstItem);
merchantChooser.setPrefWidth(200);
}
else
{
btn.setDisable(true);
}
btn.setOnMouseClicked(e -> {
//ENTER BACKEND POST HERE TO SEND REVIEW TO DATABASE!!
});
} catch (NullPointerException nex) {
System.out.println("Null pointer at AddReviewView");
} catch (Exception ex) {
System.out.println("Other exception in discount view");
System.out.println(ex.getMessage());
}

If you have many items, maybe the DropdownButton is not the best control for the job. It doesn't provide a way to make it scrollable.
You can have a look at other options, like the PopupView control.
This control allows custom content, so you can add a ScrollPane with a VBox that will contain all the items. Instead of MenuItem controls, you can use regular Button ones.
This is a quick implementation, but it is also styled as the DropdownButton.
public BasicView(String name) {
super(name);
Button button = new Button("Click me", new Icon(MaterialDesignIcon.ARROW_DROP_DOWN));
button.getStyleClass().add("flat");
button.setStyle("-fx-border-color: lightgray; -fx-border-width: 0 0 1 0");
button.setContentDisplay(ContentDisplay.RIGHT);
PopupView popup = new PopupView(button);
VBox vBox = new VBox();
for (int i = 0; i < 100; i++) {
Button item = new Button("item " + i);
item.setPrefWidth(100);
item.getStyleClass().add("flat");
item.setOnAction(e -> {
System.out.println("item " + item.getText());
popup.hide();
});
vBox.getChildren().add(item);
}
ScrollPane scrollPane = new ScrollPane(vBox);
scrollPane.setMaxHeight(200);
scrollPane.setPrefWidth(110);
popup.setContent(scrollPane);
button.setOnAction(event -> popup.show());
setCenter(button);
}

Related

Is it possible to add a SwipeView to a grid row is Xamarin Forms

I am building a grid in the C# code of my Xamarin Forms app. I want to provide the user with ability to swipe on a row and have a swipeview tray display. I have tried to follow the documentation here - https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/swipeview.
Below is the code I have:
private void AddSwipeControl(int pi_RowNumber)
{
try
{
//Add the swipeview
//Add a swip control to the and have it go all the way across. See if this works
// SwipeItems
SwipeItem tobj_DeleteSwipeItem = new SwipeItem
{
Text = "Delete",
BackgroundColor = Color.LightGreen
};
tobj_DeleteSwipeItem.Invoked += tobj_DeleteSwipeItem_Invoked; ;
List<SwipeItem> tobj_swipeItems = new List<SwipeItem>() { tobj_DeleteSwipeItem };
// SwipeView content
Label swipeContent = new Label()
{
BackgroundColor = Color.Pink,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
var tobj_SwipeGestureRecognizer = new SwipeGestureRecognizer() { Direction = SwipeDirection.Right };
tobj_SwipeGestureRecognizer.Swiped += tobj_SwipeGestureRecognizer_Swiped;
swipeContent.GestureRecognizers.Add(tobj_SwipeGestureRecognizer);
SwipeView swipeView = new SwipeView
{
LeftItems = new SwipeItems(tobj_swipeItems) { Mode = SwipeMode.Reveal },
Content = swipeContent
};
//Add the swipeview to the grid
grdDataGrid.Children.Add(swipeView, 0, pi_RowNumber);
Grid.SetColumnSpan(swipeView, grdDataGrid.ColumnDefinitions.Count);
}
catch (Exception ex)
{
SharedErrorHandler.ProcessException(ex);
}
}
private void tobj_SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
{
try
{
if (e.Direction == SwipeDirection.Right)
{
var tobj_SwipeView = ((Label)sender).Parent as SwipeView;
tobj_SwipeView.Open(OpenSwipeItem.LeftItems);
}
}
catch (Exception ex)
{
SharedErrorHandler.ProcessException(ex);
}
}
I can see the content of my swipeview in my grid row exactly where I want it and the swipe event of the label control fires as expect. However the swipe tray never opens even if I attempt to programmatically open it using tobj_SwipeView.Open(OpenSwipeItem.LeftItems); This leads me to think I am doing something wrong in building my swipe view. I have tested on Android and UWP. Any ideas what I am doing wrong?.
UPDATE: So this only appears to be a challenge on UWP. Below is my updated code. I have a button on the screen I press to run the Button_Clicked event.
private void tobj_SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
{
try
{
if (e.Direction == SwipeDirection.Right)
{
var tobj_SwipeView = ((Label)sender).Parent as SwipeView;
tobj_SwipeView.Open(OpenSwipeItem.LeftItems);
}
}
catch (Exception ex)
{
//SharedErrorHandler.ProcessException(ex);
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void Button_Clicked(object sender, EventArgs e)
{
try
{
//First add two rows
grdDataGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
grdDataGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
//First add some data columns to the grid
grdDataGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto});
grdDataGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grdDataGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
//Add data to each row
grdDataGrid.Children.Add(new Label() { Text = "Row 0 Col 0" }, 0 , 0);
grdDataGrid.Children.Add(new Label() { Text = "Row 0 Col 1" }, 1, 0);
grdDataGrid.Children.Add(new Label() { Text = "Row 0 Col 2" }, 2, 0);
grdDataGrid.Children.Add(new Label() { Text = "Row 1 Col 0" }, 0, 1);
grdDataGrid.Children.Add(new Label() { Text = "Row 1 Col 1" }, 1, 1);
grdDataGrid.Children.Add(new Label() { Text = "Row 1 Col 2" }, 2, 1);
var ti_RowNumber = -1;
foreach (RowDefinition tobj_Row in grdDataGrid.RowDefinitions)
{
ti_RowNumber += 1;
//Add the swipeview
//Add a swip control to the and have it go all the way across. See if this works
// SwipeItems
SwipeItem tobj_DeleteSwipeItem = new SwipeItem
{
Text = "Delete",
BackgroundColor = Color.LightGreen
};
tobj_DeleteSwipeItem.Invoked += OnDeleteSwipeItemInvoked; ;
List<SwipeItem> tobj_swipeItems = new List<SwipeItem>() { tobj_DeleteSwipeItem }; //comment out
// SwipeView content
Label swipeContent = new Label()
{
BackgroundColor = Color.Pink,
Text = "test",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
var tobj_SwipeGestureRecognizer = new SwipeGestureRecognizer() { Direction = SwipeDirection.Right };
tobj_SwipeGestureRecognizer.Swiped += tobj_SwipeGestureRecognizer_Swiped;
swipeContent.GestureRecognizers.Add(tobj_SwipeGestureRecognizer);
SwipeView swipeView = new SwipeView
{
LeftItems = new SwipeItems(tobj_swipeItems) { Mode = SwipeMode.Reveal },
Content = swipeContent
};
//Add the swipeview to the grid
grdDataGrid.Children.Add(swipeView, 0, ti_RowNumber);
Grid.SetColumnSpan(swipeView, grdDataGrid.ColumnDefinitions.Count);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
This seems to work fine on iOS and Android but on UWP, the swipe event for the label fires but the Swipe tray never opens. Is this a known UWP challenge?
I create a simple demo based on your code , and it works properly on my side.
You can refer to the following code:
<StackLayout Margin="20">
<Grid x:Name="grdDataGrid" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions >
<RowDefinition Height="60" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Button Text="add" Clicked="Button_Clicked" />
</StackLayout>
The c# code is:
private void AddSwipeControl()
{
try
{
//Add the swipeview
//Add a swip control to the and have it go all the way across. See if this works
// SwipeItems
SwipeItem tobj_DeleteSwipeItem = new SwipeItem
{
Text = "Delete",
BackgroundColor = Color.LightGreen
};
tobj_DeleteSwipeItem.Invoked += OnDeleteSwipeItemInvoked; ;
List<SwipeItem> tobj_swipeItems = new List<SwipeItem>() { tobj_DeleteSwipeItem }; //comment out
//SwipeItems tobj_swipeItems = new SwipeItems();
//tobj_swipeItems.Add(tobj_DeleteSwipeItem);
// SwipeView content
Label swipeContent = new Label()
{
BackgroundColor = Color.Pink,
Text = "test",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
var tobj_SwipeGestureRecognizer = new SwipeGestureRecognizer() { Direction = SwipeDirection.Right };
tobj_SwipeGestureRecognizer.Swiped += tobj_SwipeGestureRecognizer_Swiped;
swipeContent.GestureRecognizers.Add(tobj_SwipeGestureRecognizer);
SwipeView swipeView = new SwipeView
{
LeftItems = new SwipeItems(tobj_swipeItems) { Mode = SwipeMode.Reveal },
Content = swipeContent
};
//Add the swipeview to the grid
grdDataGrid.Children.AddVertical(swipeView);
// grdDataGrid.Children.Add(swipeView, 0, pi_RowNumber);
// Grid.SetColumnSpan(swipeView, grdDataGrid.ColumnDefinitions.Count);
}
catch (Exception ex)
{
// SharedErrorHandler.ProcessException(ex);
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void tobj_SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
{
try
{
if (e.Direction == SwipeDirection.Right)
{
var tobj_SwipeView = ((Label)sender).Parent as SwipeView;
tobj_SwipeView.Open(OpenSwipeItem.LeftItems);
}
}
catch (Exception ex)
{
//SharedErrorHandler.ProcessException(ex);
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
Note:
When adding the SwipeControl to Grid, I used code:
grdDataGrid.Children.AddVertical(swipeView);
And to simplify the code,I removed the parameter of function AddSwipeControl().

How to update tabbar badge-icon in Xamarin.Forms.iOS?

I can successfully work with the badge on my tabbar if i use it straight in my ViewWillAppear function but if i create a function where i try to control it then the badge does not appear.
This is the tabbedpaged renderer where I have to the function that changes the badge.
public override void ViewWillAppear(bool animated)
{
if (TabBar == null) return;
if (TabBar.Items == null) return;
var tabs = Element as TabbedPage;
if (tabs != null)
{
for (int i = 0; i < TabBar.Items.Length; i++)
{
UpdateItem(TabBar.Items[i], tabs.Children[i].Icon);
}
}
base.ViewWillAppear(animated);
}
private void UpdateItem(UITabBarItem item, string icon)
{
TabBar.UnselectedItemTintColor = UIColor.White;
}
public void UpdateBadge ()
{
var tabs = Element as TabbedPage;
if (tabs != null)
{
Device.BeginInvokeOnMainThread(() =>
{
var tab = TabBar.Items[3];
tab.BadgeValue = "New";
tab.BadgeColor = UIColor.Red;
});
}
}
Then I have another file where I handle a pushnotification and this is where I call the UpdateBadgefunction to both push a notification and also update the badge in the app.
void IPush.SendPush()
{
var notification = new UILocalNotification();
notification.SoundName = UILocalNotification.DefaultSoundName;
UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
TabbedPage_Renderer tpr = new TabbedPage_Renderer();
tpr.UpdateBadge();
}
But as stated above this does not add the badge.
If I however add...
var tab = TabBar.Items[3];
tab.BadgeValue = "New";
tab.BadgeColor = UIColor.Red;
...inside the ViewWillAppear straight away it successfully shows an iconbadge when i start the app up but the idea is to control it so i can update the badge whenever i want.
We should not use the instance of the Renderer directly.
If you want to change the UI in the platform's renderer, we can try to define a BindableProperty in the forms. Then tell the renderer do some configuration when this property changed.
Firstly, define a BindableProperty in the page which you want to change its Badge like:
public static readonly BindableProperty BadgeTextProperty = BindableProperty.Create(nameof(BadgeText), typeof(string), typeof(MainPage), "0");
public string BadgeText {
set
{
SetValue(BadgeTextProperty, value);
}
get
{
return (string)GetValue(BadgeTextProperty);
}
}
Secondly, in the renderer, we can set the badge text when this property changed like:
for (int i = 0; i < TabBar.Items.Length; i++)
{
UpdateItem(TabBar.Items[i], tabs.Children[i].Icon);
//register the property changed event
tabs.Children[i].PropertyChanged += TabbarPageRenderer_PropertyChanged;
}
private void TabbarPageRenderer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var page = sender as Page;
if (page == null)
return;
if (e.PropertyName == "BadgeText")
{
if (CheckValidTabIndex(page, out int tabIndex))
{
switch(tabIndex)
{
case 0:
UpdateBadge(TabBar.Items[tabIndex], (page as MainPage).BadgeText);
break;
case 1:
//Second Page, you can expand this switch depending on your tabs children
UpdateBadge(TabBar.Items[tabIndex], (page as SecondPage).BadgeText);
break;
default:
break;
}
}
return;
}
}
public bool CheckValidTabIndex(Page page, out int tabIndex)
{
tabIndex = Tabbed.Children.IndexOf(page);
return tabIndex < TabBar.Items.Length;
}
private void UpdateItem(UITabBarItem item, string icon)
{
TabBar.UnselectedItemTintColor = UIColor.White;
...//set the tabItem
}
private void UpdateBadge(UITabBarItem item, string badgeText)
{
item.BadgeValue = text;
item.BadgeColor = UIColor.Red;
}
At last, set the BadgeText in the forms when you want to update the badge.

Xamarin Forms - retrieve value of dynamically added entry control value on button click

I want to get all entry controls value on button click.
My code is as below - this is how I am adding dynamic control on page:
public BookSeat()
{
ScrollView scroll = new ScrollView();
StackLayout stack = new StackLayout();
int count = Convert.ToInt32(Application.Current.Properties["NoPersonEntry"]);
for (int i = 0; i < count; i++)
{
stack.Children.Add(
new StackLayout()
{
Children = {
new Label (){TextColor = Color.Blue, Text = "First Name: ", WidthRequest = 100,StyleId="FnameLabel"+i },
new Entry() {StyleId="FnameEntry"+i }
}
}
);
}
Button button = new Button
{
Text = "Save"
};
button.Clicked += OnButtonClicked;
stack.Children.Add(button);
scroll.Content = stack;
this.Content = scroll;
}
And below code is for I want to get value on button click
public void OnButtonClicked(object sender, EventArgs e)
{
// Here I want to get value
}
What you can do is to store your entries in a list so that you can access them later on.
For example :
private List<Entry> _myentries = new List<Entry>();
public BookSeat()
{
ScrollView scroll = new ScrollView();
StackLayout stack = new StackLayout();
int count = Convert.ToInt32(Application.Current.Properties["NoPersonEntry"]);
for (int i = 0; i < count; i++)
{
var entry = new Entry() {StyleId="FnameEntry"+i };
_myentries.Add(entry);
stack.Children.Add(
new StackLayout()
{
Children = {
new Label (){TextColor = Color.Blue, Text = "First Name: ", WidthRequest = 100,StyleId="FnameLabel"+i },
entry
}
}
);
}
[...]
}
Now you can do this :
public void OnButtonClicked(object sender, EventArgs e)
{
foreach(var entry in _myentries)
{
var text = entry.Text;//here we go
}
}

xamarin forms dynamically adding custom font labels to scrollview is extremely slow

So I have a horizontal scrollview that I'm trying to dynamically populate when the user takes a certain action. The items I am throwing into the view each contain 4 labels that are using custom fonts. When I try to add about 10 of these items it lags for about 1.5 seconds on android and 1 second on IOS. If I take the custom font out then its about 1 second on each platform. If I take out 3 of the labels and only display one then its almost instantaneous. Is there any known reason for the lag? And is there any way around it so I can still use a custom font without a huge lag?
Here's a quick sample I made that pretty much does what I'm doing in my app. However, my app has more stuff so the lag isn't quite as bad here but it is still very noticeable
public class App : Application
{
public int count;
public ScrollView scroll, scroll2, scroll3;
public App ()
{
count = 1;
scroll = new ScrollView {
VerticalOptions = LayoutOptions.Center,
Orientation = ScrollOrientation.Horizontal
};
scroll2 = new ScrollView {
VerticalOptions = LayoutOptions.Center,
Orientation = ScrollOrientation.Horizontal
};
Button button = new Button(){
Text = "click",
};
button.Clicked += (sender, e) => AddStuff();
Button button2 = new Button(){
Text = "click",
};
button2.Clicked += (sender, e) => AddStuff2();
MainPage = new ContentPage {
BackgroundColor = Color.White,
Content = new StackLayout{
Children={
button,
scroll,
button2,
scroll2
}
}
};
}
//this one is instantaneous
public void AddStuff()
{
StackLayout stack = new StackLayout () {
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 200,
};
for (int i = 0; i < 11; i++)
stack.Children.Add (
new StackLayout(){
Children = {
new Label (){TextColor = Color.Blue, Text = "Size: ", WidthRequest = 100 },
}
}
);
scroll.Content = stack;
count++;
}
//this one takes forever
public void AddStuff2()
{
StackLayout stack = new StackLayout () {
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 200,
};
for (int i = 0; i < 11; i++)
stack.Children.Add (
new StackLayout(){
Children = {
new Label (){TextColor = Color.Blue, Text = "Size: ", WidthRequest = 100 },
new Label (){TextColor = Color.Blue, Text ="" + count*i, WidthRequest = 100 },
new Label (){TextColor = Color.Blue, Text = "Size: ", WidthRequest = 100 },
new Label (){TextColor = Color.Blue, Text ="" + count*i, WidthRequest = 100 }
}
}
);
scroll2.Content = stack;
count++;
}
}
and the custom font label for droid
[assembly: ExportRenderer (typeof (Label), typeof (CustomFontLabel_Droid))]
namespace df.Droid
{
public class CustomFontLabel_Droid:LabelRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.Label> e) {
base.OnElementChanged (e);
var label = (TextView)Control;
Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "SourceSansPro-Semibold.otf");
label.Typeface = font;
}
}
}
Just incase anyone else is having a similar problem, if you make a static typeface property in the android MainActivity instead of calling createFromAsset inside the Label.OnElementChanged function every time then it gets rid of the extra lag on android.
CustomFontLabel_Droid.cs
[assembly: ExportRenderer (typeof (Label), typeof (CustomFontLabel_Droid))]
namespace df.Droid
{
public class CustomFontLabel_Droid:LabelRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.Label> e) {
base.OnElementChanged (e);
var label = (TextView)Control;
// this guy slows things down-> Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "SourceSansPro-Semibold.otf");
label.Typeface = MainActivity.semiBoldFont;
}
}
}
MainActivity.cs
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
public static Typeface semiBoldFont = null;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new App ());
semiBoldFont = Typeface.CreateFromAsset (Forms.Context.Assets, "SourceSansPro-Semibold.otf");
}
}

How to handle list picker in Wp7

I have a list picker which is displayed in my phone application page.I have created list picker in starting of class,and i am adding the list picker in the phoneApplicationPage_loaded() method.When the page is launched the first time, ,the scenario works perfectly and its navigates further to second page.When i navigate back to previous page(containing list picker),it shows Invalid Operation Exception occured stating "Element is already the child of another element."
I want to know how to handle these scenarios?
Code is below
namespace My.Design
{
public partial class myclass : PhoneApplicationPage
{
String[] values = null;
ListPicker picker = new ListPicker();
StackPanel sp;
StackPanel mainFrame;
String statementInfo = "";
public myclass()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Phone Application Page Loaded_>>>>>>");
List<String> source = new List<String>();
displayUI();
}
public void displayUI()
{
Debug.WriteLine("About to display UI in miniStatement");
Debug.WriteLine("<-------------Data--------->");
Debug.WriteLine(statementInfo);
Debug.WriteLine("<-------------Data--------->");
int count = VisualTreeHelper.GetChildrenCount(this);
if (count > 0)
{
for (int i = 0; i < count; i++)
{
UIElement child = (UIElement)VisualTreeHelper.GetChild(this, i);
string childTypeName = child.GetType().ToString();
Debug.WriteLine("Elements in this Child" + childTypeName);
}
}
List<String> source = new List<String>();
String[] allParams = ItemString.Split('#');
source.Add("PleaseSelect");
for (int i = 0; i < allParams.Length; i++)
{
Debug.WriteLine("All Params Length" + allParams[i]);
if (!(allParams[i].Equals("") && (!allParams[i].Equals(null))))
{
if (values != null)
{
Debug.WriteLine("Values length" + values.Length);
values[values.Length] = allParams[i];
}
else
{
Debug.WriteLine("Allparams Length" + allParams[i]);
source.Add(allParams[i]);
}
}
}
//picker = new ListPicker();
this.picker.ItemsSource = source;
mainFrame = new StackPanel();
TextBlock box = new TextBlock();
box.Text = "> DEmoClass";
box.FontSize = 40;
mainFrame.Children.Add(box);
Canvas canvas = new Canvas();
StackPanel sp = new StackPanel();
TextBlock box1 = new TextBlock();
box1.Text = "Number";
box1.HorizontalAlignment = HorizontalAlignment.Center;
box1.FontSize = 40;
SolidColorBrush scb1 = new SolidColorBrush(Colors.Black);
box1.Foreground = scb1;
sp.Children.Add(box1);
picker.Width = 400;
picker.Height = 150;
sp.Children.Add(picker);
Canvas.SetTop(sp, 150);
canvas.Children.Add(sp);
mainFrame.Children.Add(canvas);
this.ContentPanel1.Children.Add(mainFrame);
}
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
/*
Debug.WriteLine("OnNavigatingFrom>>>.>>MainPage");
if (sp != null)
{
sp.Children.Remove(picker);
}*/
base.OnNavigatingFrom(e);
}
}
}
If you are not intending to update the listpicker after navigating back from the second page add the following line in your Loaded event handler
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= PhoneApplicationPage_Loaded;
Debug.WriteLine("Phone Application Page Loaded_>>>>>>");
List<String> source = new List<String>();
displayUI();
}
i don't know why you can not use that case when app resume from tombstoned.
error happened because when you back to your page , loaded event runs again.
by the way,
Application_Activated 's argument can tell you app resumes from tombstoned or not--.
if (e.IsApplicationInstancePreserved)
{
IsTombstoning = false;
}
else
{
IsTombstoning = true;
}
I'm curious why you're creating it in code and not leaving it in XAML? Also the error is coming from the fact that you're attempting to add it twice into a location that can probably only have a single content element. What's the higher level problem you're trying to solve?

Resources