How to get notified if we move to next page in CarouselView? - xamarin

I would like to get notified if I move to the next page in CarouselView in Xamarin.Forms.
Is it possible?
Any event or property or method available?
Thanks in advance.

CarouselView has an ItemSelected event that can be subscribe to:
PizzDeals.ItemSelected += (object sender, SelectedItemChangedEventArgs e) =>
{
System.Diagnostics.Debug.WriteLine(e.SelectedItem);
var pizza = e.SelectedItem as SpecialtyPizzaDeals;
System.Diagnostics.Debug.WriteLine(pizza.name);
};

Related

WPF Shown Event fires while not fully painted

I want to open a form, make a screenshot and close it.
So I tried the Shown Event, but this fired before everything is painted.
Since Shown is the last event fired (according to MSDN), what can I do?
I think just delaying isn't such a good idea in an event driven environment.
Any advice? Thx in adv.
<
{
InitializeComponent();
UpdateData();
this.Shown += new System.EventHandler(this.PrintForm_Shown);
this.ShowDialog();
}
private void PrintForm_Shown(object sender, EventArgs e)
{
DoPrintForm();
Close();
}
>

Xamarin DataPicker how to handle done button click event

I added to my DataPicker unfocused event. And in this event I would like to check if Done button was clicked.
private void DatePicker_Unfocused(object sender, FocusEventArgs e)
{
}
Or other option.
Is it possible to add listener to button Done, and if was clicked then fired some method?
How can I do it?
Thank you.
Every UI control which receives input always has some event handlers which you can listen to.
In your case the DatePicker has an Event Handler which fires when the Date property changes.
Here is the documentation:
DatePicker Event Handler - Xamarin Documentation
The implementation of this handler is simple:
DatePicker datePicker;
DateTime newDate;
DateTime oldDate;
public YourPage()
{
datePicker.DateSelected += Date_DateSelected;
}
void Date_DateSelected(object sender, DateChangedEventArgs e)
{
newDate = e.NewDate;
oldDate = e.OldDate;
}
Always read the documentation first, as that's the best way to learn how to use a specific control.

Listbox item is not getting fired

I am using listbox inside panorama, like if panorama has 5 items then each panorama item contains a listbox.
The listitem is not getting fired at times, mainly for the second time. For the first them when the list item is clicked then it navigates to next page. When i come back and again i tap on the listitem is not getting fired.
Am using SelectionChanged for list click listener.
I have got a suggestion from web search to use stackpannel instead of grid in , but in some places am unable to use stack pannel because of the component arrangement.
Please suggest me does changing to stackpannel is the only way or is there any other solution for this.
Any kind of ideas are welcome.
When one item is selected in a ListBox, it keeps the record of the selectedindex. When the same element is tapped again, there is no change in the selectedindex and hence the SelectionChanged is not fired. Hence what you can do is setting the selectedindex back to -1 after each selection or after the back navigation to the listbox page
//In the onnavigatedto function, set the listbox selectedindex to -1
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
MyListBox.SelectedIndex = -1;
}
And modify your selectionchanged event like this
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//let our code run only if index is not -1
if (MyListBox.SelectedIndex != -1)
{
//Your selectionchanged code
}
}
Hope this helps
UPDATE: For your Panorama case
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listbox = (sender as ListBox);
//let our code run only if index is not -1
if (listbox.SelectedIndex != -1)
{
//Your selectionchanged code
At the end of it set the index back to -1
listbox.SelectedIndex = -1;
}
}

LoadedPivotItem event on Pivot control not fired first time, WP7

is there any reason why event LoadedPivotItem is not fired when DataContext of Pivot is being assigned therefore creating Pivot Items ?
It is only fired when I swype to next pivot item which is already handled by _SelectionChanged event.
protected override void OnNavigatedTo
(System.Windows.Navigation.NavigationEventArgs e)
{
var someData = LoadData();
pivot.DataContext = someData;
base.OnNavigatedTo(e);
}
void pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
// Will not stop here after data being assigned to DataContext
}
I need this event in particular cause I need PivotItem and it's data context for further operations.
Is there something I am doing wrong, or is there some other event that I can use here while getting a PivotItem ( PivotItemEventArgs ).
Thanks
I think the problem is the timing of how your page is loading. I don't see you attaching an event handler in your code, so I'm assuming that you're specifying the event handler in your XAML. The event may be firing too early, before everything on your page is fully loaded and wired up.
Try removing the event handler from your XAML and moving it to your OnNavigatedTo event (pseudocode):
protected override void OnNavigatedTo (NavigationEventArgs e)
{
var someData = LoadData();
pivot.DataContext = someData;
OnLoadedPivotItem += pivot_LoadedPivotItem;
base.OnNavigatedTo(e);
}
If that doesn't work, this article might be helpful. It describes the sequence of events that happens as the control tree is loaded. The suggestion that jumped out as potentially useful was attaching to the LayoutUpdated event instead of the Loaded event.

OnClick on generated Textblock

Howdy,
I'm generating a bunch of Textblocks in a StackPanel. I would love to open another page when clicking on one Textbox:
sp.Children.Add(new TextBlock { Text = "Click me, I wanna open new content" });
How could I do that, it's probably something with "triggers" but I couldn't find anything on the web :-/.
Thanks!
You could use the Toolkit to add a gesture listener for the Tap event.
Alternatively you could use a HyperlinkButton as this contains a Click event.
Edit:
Example of using HyperlinkButton:
var sp = new StackPanel();
var hlb = new HyperlinkButton {Content = "click me"};
hlb.Click += hlb_Click;
sp.Children.Add(hlb);
ContentPanel.Children.Add(sp);
private void hlb_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
}
Use TextBlock.ManipulationStarted event to detect a touch on it.

Resources