Close ModalView on back button.(Xamarin) - xamarin

I am showing a ModalView(Navigation page) on button click.
Its working well. I want to close Modalview on Back button.
If you have any idea guide me.
My code as follows.
Button click event
protected void btnEdit_Click(object sender, EventArgs e)
{
var navigation = new NavigationPage(new Settings());
UIViewController navc = navigation.CreateViewController();
navc.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
this.PresentViewController(navc, true, null);
}
Setting Form code
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Settings : ContentPage
{
public Settings()
{
var backItem = new ToolbarItem
{
Text = "Back"
};
this.ToolbarItems.Add(backItem);
backItem .SetBinding(MenuItem.CommandProperty, "BackClicked");
backItem .Clicked += (object sender, System.EventArgs e) =>
{
**// This code Not working**
Navigation.PopModalAsync(false);
};
InitializeComponent();
}
}

You appear to be mixing native iOS code with Xamarin.Forms code, as #Jason mentions in the comment. To open a modal view from XamForms, you can call Navigation.PushModal():
protected async void btnEdit_Click(object sender, EventArgs e)
{
var navigation = new NavigationPage(new Settings());
await Navigation.PushModalAsync(navigation);
}
Update based on comment
public class MyTabbarPage : TabbarPage
{
...
public void ButtonClicked()
{
var navigation = new NavigationPage(new Settings());
await Navigation.PushModalAsync(navigation);
}
}
// Inside renderer
protected async void btnEdit_Click(object sender, EventArgs e)
{
(Element as MyTabbarPage).ButtonClicked();
}

I did as below code to call XamForms class function an its worked.
protected void btnEdit_Click(object sender, EventArgs e)
{
Maintabpage obj =(Maintabpage)Xamarin.Forms.Application.Current.MainPage;
obj.ButtonClicked();
}

Related

CarouselPage change current page

App.xaml.cs
MainPage = new NavigationPage(new Home());
Home.xaml.cs
public partial class Home : CarouselPage
{
public Home()
{
Children.Add(new CarPage1());
Children.Add(new CarPage2());
CurrentPage = new CarPage2();
}
}
CarPage2.xaml.cs
public partial class CarPage2 : ContentPage
{
public CarPage2()
{
InitializeComponent();
}
private void Btn_Clicked(object sender, EventArgs e)
{
//Do something
//I wanna change screen to CarPage1 without use Navigation.PushAsync(new CarPage1());
}
}
How to change current screen to CarPage1 not use Navigation.PushAsync ?
I have done a sample to test and setting the CurrentPage property worked correctly, you can try the following code:
public partial class CarPage2 : ContentPage
{
public CarPage2()
{
InitializeComponent();
}
private void Btn_Clicked(object sender, EventArgs e)
{
var home = this.Parent as CarouselPage;
home.CurrentPage = home.Children[0];
}
}

GTK# - PropertyNotifyEvent doesn't seem to work

I try to make my app to react on property change of a widget, but the signal PropertyNotifyEvent is never invoke.
For test purpose i make a very simple application containing a label and a button. Pressing the button change text property of label but the PropertyNotifyEvent isn't responding.
using System;
using Gtk;
public partial class MainWindow : Gtk.Window
{
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Build();
label1.AddEvents((int)(Gdk.EventMask.PropertyChangeMask));
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
protected void OnButton1Clicked(object sender, EventArgs e)
{
label1.Text = "new text";
}
protected void OnLabel1PropertyNotifyEvent(object o, PropertyNotifyEventArgs args)
{
Console.WriteLine("label property change");
}
}
I have no idea what I do wrong, do I missing something?
Found a solution:
label1.AddNotification("label", (o, args) => {Console.WriteLine("label property change");});

Calling button click from another button click

How to press RoutedEventArgs e button (button in page) from EventArgs e button (button on application bar) in windows phone 7
private void button3_Click(object sender, EventArgs e)
{
button0_Click(sender, e);
}
private void button0_Click(object sender, RoutedEventArgs e)
{
}
when i am using above code its giving me
cannot convert from 'System.EventArgs' to 'System.Windows.RoutedEventArgs'
Please Help
SMS CODE:
SmsComposeTask SCT = new SmsComposeTask();
PhoneApplicationService PAS = PhoneApplicationService.Current;
public string SMSNO;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
object sample;
if (PAS.State.TryGetValue("numbertext", out sample))
SMSNO = sample as string;
if (PAS.State.TryGetValue("messagetext", out sample))
txtOutput.Text = sample as string;
base.OnNavigatedTo(e);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (txtOutput.Text != "")
{
SCT.To = SMSNO;
SCT.Body = txtOutput.Text;
SCT.Show();
}
else
{
MessageBox.Show("Output is Empty to send SMS.", "Wait!", MessageBoxButton.OK);
}
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
PAS.State["numbertext"] = SMSNO;
PAS.State["messagetext"] = txtOutput.Text;
base.OnNavigatedFrom(e);
}
If you don't use the parameter inside button0_Click, you can just call button0_Click(sender, null); (the reason is that the event from the application bar don't bubble that's why they don't have a RoutedEventArg parameter)

photo chooser task windows phone 7.1

i need to take a picture from the directory of Windows phone in my application so i add a child Windows when i click on the text in this child Windows i add a button and i called
public partial class AnnotationControl : ChildWindow
{
public ObservableCollection<string> cercle { get; set; }
public AnnotationControl()
{
InitializeComponent();
}
private void ChildWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void btnsave_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void btnCancel_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void browse_Click(object sender, RoutedEventArgs e)
{
PhotoChooserTask objPhotoChooser = new PhotoChooserTask();
objPhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooseCall);
objPhotoChooser.Show();
}
but when i clicked on the button to choose a picture the application crashed
"Application_UnhandledException"
some one have any idea please
Use this may be helpful
private void changeImage(object sender, RoutedEventArgs e)
{
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
photoChooserTask.Show();
}
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
imageTapped.Source = bmp;
}
}

Getting a concrete event from WP7 calendar

I'm working on a WP7 application and I need it to play the song in the first link if the current event on the calendar is "Meeting". However, with the current code, it plays the second song instead if the first one even though the event is set correctly.
Here is my code:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Set the data context of the listbox control to the sample data
DataContext = App.ViewModel;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
// Load data for the ViewModel Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Appointments appts = new Appointments();
//Identify the method that runs after the asynchronous search completes.
appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = DateTime.Now;
int max = 1;
//Start the asynchronous search.
appts.SearchAsync(start, end, max, "Appointments Test #1");
textBlock3.Text = DateTime.Now.ToString("hh:mm:ss tt");
}
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
try
{
AppointmentResultsDataLINQ.DataContext =
from Appointment appt in e.Results
where appt.IsAllDayEvent == false
select appt;
}
catch (System.Exception)
{
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if ((AppointmentResultsDataLINQ.DataContext).Equals("Meeting"))
{
mediaElement1.Source = new Uri("http://www.opendrive.com/files/NV8zNTMwNDYwX2hxRXZR/Crystallize.mp3", UriKind.Absolute);
}
else
{
mediaElement1.Source = new Uri("https://www.opendrive.com/files/NV8zMjAxODY0X0VBNDJY/Hetken%20tie%20on%20kevyt%20(piano%20cover)%20-%20YouTube.mp3", UriKind.Absolute);
}
mediaElement1.Play();
}
}
The problem appears to be this line:
if ((AppointmentResultsDataLINQ.DataContext).Equals("Meeting"))
You're comparing the result of calling the ToString() method on the Appointment instance with the string "Meeting".
You probably want:
if ((AppointmentResultsDataLINQ.DataContext as Appointment).Subject.Equals("Meeting"))
Update
You're actually checking an Enumerable of Appointments.
Here's how to check if any of them are "Meeting":
if ((AppointmentResultsDataLINQ.DataContext as IEnumerable<Appointment>).Any(app => app.Subject.Equals("Meeting")))

Resources