I have a page with "internal navigation". That means that I show some list on that page and when user picks an item, I (download some data and) repopulate that list.
I made my own history stack, so when user wants to go back, I repopulate the list from history stack. User can go back by flicking or by clicking on hw back button.
Flicking works ok, but back button is weird.
I am canceling the back button event and instead I run my back navigation history. So I am still on the same page. BUT the back button click hides the application bar (even though I am canceling that event). And when I click it again and debug it, the ApplicationBar property is null.
// this overriden method causes ApplicationBar being hidden (or destroyed)
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Messenger.Default.Send(...some notification here...); // this runs the internal navigation
ApplicationBar.IsVisible = true; // this doesn't help and on the second try, it throws NullReferenceException
}
// this method is ok, repopulating is working without any problem
private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
Messenger.Default.Send( ...some notification here... ); // this run exactly same internal navigation
}
So question is - how to have ApplicationBar not destroyed/hidden? What is back button doing, when I cancel the navigation (it must do something with the AppBar)?
OK, this happens only when I use BindableApplicationBar and its Extensions (from here maxpaulousky.com).
It happens because Extensions handles back button event on page itself.
Solution was to check the Cancel property, and destroy it only when it's false (in BindableApplicationBar class in the Extensions).
Related
Hi I'm facing a problem with my small xamarin app.
I have my small xamarin-form app that everytime the user enter a product Id click OK button retrieves a single (data related to that product Id only) data thru Web API from page A, and then pass it to a collectionview in another page B.
then there is a back button to go back to page A and the user must enter another product Id again and the app must fetch data thru web api again and pass it again to page B in the collectionview.
So the problem is now, when I click on back button in Page B, it's clear the collectionview data, whereas I need the collectionview to keep the state even If I pop back.
I'm not using any MVVM pattern or complicated stuff from now as I'm new to xamarin; it's just a simple architecture.
Or maybe I'm using wrong technics to achieve this and can advise me a better way to achieve that. I'm please open to your suggestion !!!
In brief, I need to be able not to reload CollectionView after clicking on Back button.
Below is the code that Bind to the View on Page B
public async void OnGetProductDetailButton(object sender, EventArgs e)
{
await Navigation.PushAsync(new ProductDetailPage
{
BindingContext = productDetails
});
}
I have a custom DatePicker, which is opened if the user taps on it. It uses the same mechanics like the Xamarin.Forms DatePicker. The scenario is like the following:
user taps on the custom DatePicker
instead of picking a date he opens another dialog
two dialogs are now opened at the same time
I tried to Unfocus() if the other element get's the focus, but nothing happens. The DatePicker is still displayed.
What else can I do? Should I throw manually the Unfocus event? Can I lock the UI somehow so that the user has to press the Finish button before moving on?
First, the issue doesn't occur if I switch between DatePicker and TimePicker. It only occurs if I switch from DatePicker/TimePicker to my Entry (which triggers a custom dialog in Focused event).
And Unfocus() does work, if you do it on the UI thread:
private async void someEntry_Focused(object sender, FocusEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{
this.datePicker.Unfocus();
});
// custom dialog shown to user ...
}
Consider a TreeView control containing multiple nodes. On selecting a node, certain information is displayed on a text box. This information can be modified and saved. Accidentally, if a user navigates to a different node without saving, a pop is displayed asking the user to save or cancel the action. If cancel is clicked, selection should remain on the previously selected node instead of a new node.
The logic to display pop up is written in BeforeSelect() event of TreeView. Below code works fine in c#.
But it is not working in case of VB6 because we don't have a BeforeSelect Event in VB6. Is there any way to achieve this in VB6?
private void TreeView1_BeforeSelect(object sender,TreeViewCancelEventArgs e)
{
If(Check for anychange)
{
e.Cancel=true;
}
}
My Windows Phone 7 app as a page with an edit form with a ListPicker control. One of the items in the list is "add new" which, when selected, opens another page with another edit form for adding a new lookup value. Problem is, page navigation is asynchronous, so when the source page navigates to the target page, code execution continues and I don't know how to get a notification from the target page when the user saves. I want the value they just added to be inserted and selected in the ListPicker on the source page. I'm not even sure how to look this up on Google.
On your first page you will need to override the OnNavigatedTo method (or attach a second event handler)
protected override void OnNavigatedTo(NavigationEventArgs e) {
// Check for state
}
Your second page will need to write a piece of state into a location both pages can access, then the first page can see if this state exists.
A simple Dictionary<string,object> off the static App object can be a starting point for this sort of state.
I've read somewhere that longlistselector from the toolkit is better in performance than the existing listbox. So, I changed the listbox to longlistselector. Now I have a image button control to keep in the longlistselector (that acts like a checkbox). When I click on the button, the list selection changed event is fired along with the button click. The button in listbox works fine as expected but not in longlistselector. How can I stop the list selection changed event? I searched a lot on this but couldn't find anything useful. First of all is it possible?
I wouldn't take it for granted that the long list selector performs better than the listbox. The listbox uses a virtualizing stack panel when binding is involved and is pretty performant. I went down the road of using the list picker from the toolkit and ended up regretting it due to some bad performance problems. If it works with the listbox I'd say stick with the listbox and only move away if you find you have perfomance issues in the future.
When a button is clicked a button event handler is triggered and when a item in the long list selector is changed the corresponding selection changed event is triggered IF it is also registered. But the button is clicked on the same selected item, only the button event handler is triggered. I suggest to have only a button event handler and get the selected item from it.
private void ButtonEvent_Click(object sender, RoutedEventArgs e)
{
HoldingClass clicked=((sender as Button).DataContext as HoldingClass);
//Do something with the HoldingClass as this is the binding element to the long list selector
}
Change the ClickMode to Press in XAML
ClickMode="Press"
and inside you Click event handler make (YourListName).SelectedItem = null;
private void deleteButton_Click(object sender, RoutedEventArgs e)
{
MainLongListSelector.SelectedItem = null;
..
}