I am implementing the Pivot control in Windows Phone 7.
I want to know which Pivot item is selected and active after the user does a swipe gesture.
How to detect the swipe gesture event related to Pivot control?
Which delegate method should I use ?
SelectionChanged is the event to wire up to for detecting Pivot item changes.
As kP suggests, SelectedIndex/SelectedItem are the properties you can access to see which item is currently selected.
Here's an example event handler to show the SelectedIndex each time it changes.
private void thisPivot_SelectionChanged(object sender, SelectionChangedEventArgs e) {
System.Diagnostics.Debug.WriteLine(thisPivot.SelectedIndex);
}
You could use the Pivot.SelectedItem method which is a getter and setter. This will allow you to return the current PivotItem the user is on. Alternatively, you could use the Pivot.SelectedIndex method if you just want to access the indexes of each PivotItem.
If you want to perform an action once the PivotItem has actually finished loading entirely and transition animation sequence is complete, take a look at the LoadedPivotItem event.
Related
I have a listbox bound to an observable collection of products. Each products has an IsFavorite bool property bind to an Image using a convertor.
I fill in the observable collection and all the product have IsFavorite=false. Then i load favorites from Isolated Storeage and in an foreach update the IsFavorite property (calling NotifyPropertyChanged) for each product in the observable collection bound to listbox. The Image does not change for the products in view. If I scoll away and then return to a changed item, the icon changes.
What is the problem? How can I force binding to refresh immediately not after scolling?
I know you said you are raising the PropertyChanged event but I am afraid your class "Product" is not implementing INotifiedPropertyChanged and incidently not raising the propertyChanged event when the bool IsFavorite changes.
Try implementing INotifiedPropertyChanged in your product class.(and on the Product.IsFavorite property)
I had a quick question on working with listboxes in WP7 using MVVM Light. Basically before I was using MVVM all I had to do was set the SelectedIndex to -1 inside of the OnNavigatedTo event when the page was navigated to. Then inside of the SelectionChanged event I would check if the SelectedIndex was equal to -1 and if so I would ignore it. The reason I did this was just in case the user wanted to select the same item again when they came back to the page.
Now with MVVM (MVVM Light) I'm binding the event to a command, which takes care of the first part. But now I'm stuck because I don't know how to set the SelectedIndex to -1 from the ViewModel which prevents the user from selecting the same item again. Any ideas?
An even better solution is to not use the selection event to trigger a navigation. Use the tap event of the indivdual item instead.
This also avoids issues of accidental navigation when scrolling.
Try creating a SelectedItem property on your viewmodel, then do a two-way between the SelectedItem viewmodel property and the SelectedItem property on your ListBox. Then you can update it with whatever value you want when your Command fires and the result will propagate back to your ListBox.
I am using a listbox in a data template - and from an earlier post I cannot reference the listbox directly in the code behind.
As a result I am capturing the last selected object in the selectionchanged event for the listbox and using this when I want to navigate.
I now need to also clear the selected object in the listbox -can I do this in the selectionchanged event (after storing it away).
Alternatively I could use the MouseLeftButtonDown event on the listbox (which I understand is the equivalent of a 'click') but can I get the selected object in the listbox in this event.
thanks
In the selection changed event set <ListboxName>.SelectedIndex = -1;
Also, do not use the MouseLeftButtonDown event. This will fire whenever the user touches the ListBox, even if they're just trying to scroll up / down and not actually selecting an item.
If you can't change the SelectedIndex in code behind then, instead of detecting the SelectionChanged event you could detect a Tap event on the ListBoxItem.
I have a list of panorama Items.
I want to know when the user has reached a particular panorama item and then take necessary action.
I tried using the eventhandler GotFocus on the panorama item but it doesn't get invoked when the user reaches the item
The Panorama control has a SelectionChanged event which is fired when the user pans from one item to the next. You can then use the SelectedItem or SelectedIndex properties to find the item which is currently in view.
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;
..
}