Disable button in MT.Dialog and change image - ios

Can anyone help, i want to change my image(button), when i press my buttonImage i open MT.Dialog and then i login, and when i login i want the button to change how do i do that, i have found the code, but it doesn't work in MT.Dialog
Here is how i do it.
cmdLogin.TouchUpInside += delegate {
cmdLogin.SetImage(UIImage.FromFile("Images/Logout.png"), UIControlState.Normal);
};
and for the hidden thing i tried(But doesn't work)
if(cmdLogin.Hidden == True)
{
cmdLogout.Enabled;
}else{
cmdLogout.Hidden;
}
but that doesn't work in MT.Dialog ofcourse because i don't do anything with my string element(My string element got the name login and if someone got a link to a good login system w/ database that would be very helpful.
and ofcourse here is my MT.Dialog code
cmdLogin.TouchUpInside += delegate {
_window.RootViewController = new DialogViewController(new RootElement("Login") {
new Section ("B.V. Electronic"){
(password = new EntryElement ("Password", "", "", true))
},
new Section () {
(login = new StringElement ("Login", delegate {
if(password.Matches("1234")){
GoBackToView();
}else{
new UIAlertView("Wrong code", "It's the wrong code", null, "Ok", null).Show();
}
}))
},
new Section (){
new StringElement ("Cancel", delegate {
GoBackToView();
})
}
});
};

I am not real clear on exactly what you want to do. However, one suggestion I have for you is to look at this:
https://github.com/xamarin/prebuilt-apps/tree/master/FieldService
This is a sample application that was built by Xamarin that has a nice login screen that you could try and get some ideas from. It does not use Monotouch.Dialog for the login screen, so if you want that you can look at this:
http://docs.xamarin.com/recipes/ios/content_controls/tables/create_a_login_window_using_monotouch.dialog
Your code is similar to that, but it looks like you modified it a little.
If you want to change your Login StringElement, you need to modify it, then call Root.Reload(login, UITableViewRowAnimation.Automatic); afterwards. I don't think there is a simple way to just change the background image of a StringElement. You will need to make your own subclass of StringElement and customize the GetCell() routine to. You can refer to this SO question for more ideas on that:
How can I create a custom styled EntryElement with MonoTouch.dialog?
I hope that helps.

Related

How can I clear a write("message")

Basically, I have a button that write("message"+myVar).
Then I want to press a button that will delete the written message, but not mess with the variable at all.
I am very new to coding. I code on Code.org which is powered by javascript.
Much thanks
Welcome to SO. Always try to share your code so anyone can help you better. As much as I understand there are lots of ways to achieve this. The most straightforward one could be to create a textLabel with an empty string and then modify it with the setText property of code.org. Like so;
var myVar = "something";
textLabel("messageId","");
button("createButton", "create");
onEvent("createButton", "click", function( ) {
setText("messageId", "message" + myVar);
});
button("deleteButton", "delete");
onEvent("deleteButton", "click", function( ) {
setText("messageId",myVar);
});

How do I set the title for the back button on a Nav Bar in Xamarin.Forms?

I have to remove the title on the back button in several pages. I tried with this code and it works fine.
private void OnBtn ()
{
var nav = (Page)ViewFactory.CreatePage<DebugViewModel, DebugPage> ();
NavigationPage.SetHasNavigationBar (nav, true);
NavigationPage.SetHasBackButton (nav, true);
NavigationPage.SetBackButtonTitle (nav, "");
((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync (nav);
}
But in some other place of the code I have this and it doesn't set the title to an empty string.
this.SettingsPageCommand = new Command (() => {
this.IsBusy = true;
NavigationPage.SetHasNavigationBar (settingsPage, true);
NavigationPage.SetHasBackButton (settingsPage, true);
NavigationPage.SetBackButtonTitle(settingsPage, "");
((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync (settingsPage);
//((MasterDetailPage)App.Current.MainPage).IsPresented = false;
this.IsBusy = false;
}, () => !this.IsBusy);
I'm trying to avoid making a renderer as I want to keep as much shared code as possible.
Any ideas?
Thanks!
#hrishi's answer is correct, however if you wish to have different text shown in the Title Bar (this.Title) than shown for the Back button text on subsequent pages you can alternatively call the following method. You would call this in the constructor for the page whose title should be different on the back button:
NavigationPage.SetBackButtonTitle(this, "CustomText");
Typically I only set Title unless it needs to be different when shown for back button (ex: shorter text) in which case I set both Title and call the above method with the alternative back button text.
Title property of content page is used on next page as title of back button.
Try Setting this.Title="" on previous page of settings page

Record sound from microphone in Monotouch.Dialog

Xamarin example found here : http://docs.xamarin.com/samples/Sound works, but the GUI is not Monotouch.Dialog, and it looks poor together with the rest of my MD APP.
How to add a Monotouch.Dialog controller, to start and stop recording, and show the elapsed time while recording.
Apple made this http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html with a VU meter included.
Look at this class inside the Xamarin sample https://github.com/xamarin/monotouch-samples/blob/master/Sound/Sound/SoundViewController.cs
Basically, you would want to create you're own DialogViewController:
You will need the using statements from the sample.
using MonoTouch.AVFoundation;
using System.Diagnostics;
using System.IO;
using MonoTouch.AudioToolbox;
public class SoundRecorder : DialogViewController {
this.Title = "Record Sound";
root = new RootElement() {
new section () {
new StringElement ("Record", delegate {
// sound recording code from sample for the first button
}
}
}
}
This should give you a start.
You may want to separate the elements and declare them separately like this:
StringElement myElement = new StyledStringElement("record something");
You can then subscribe to the tapped event with a delegate and handle the when a button is hit that way too.
So that you can do a little more. For more styling choices you would want a StyledStringElement
Hope this helps

Monotouch.Dialog - How to push a view from an Element

It seems like this should be very easy, but I'm missing something. I have a custom Element:
public class PostSummaryElement:StyledMultilineElement,IElementSizing
When the element's accessory is clicked on, I want to push a view onto the stack. I.e. something like this:
this.AccessoryTapped += () => {
Console.WriteLine ("Tapped");
if (MyParent != null) {
MyParent.PresentViewController(new MyDemoController("Details"),false,null);
}
};
Where MyDemoController's gui is created with monotouch.dialog.
I'm just trying to break up the gui into Views and Controlls, where a control can push a view onto the stack, wiat for something to happen, and then the user navigates back to the previous view wich contains the control.
Any thought?
Thanks.
I'd recommend you not to hardcode behavior in AccessoryTapped method, because the day when you'll want to use that component in another place of your project is very close. And probably in nearest future you'll need some another behavior or for example it will be another project without MyDemoController at all.
So I propose you to create the following property:
public Action accessoryTapped;
in your element and its view, and then modify your AccessoryTapped is that way:
this.AccessoryTapped += () => {
Console.WriteLine ("Tapped");
if (accessoryTapped != null) {
accessoryTapped();
}
};
So you'll need to create PostSummaryElement objects in following way:
var myElement = new PostSummaryElement() {
accessoryTapped = someFunction,
}
...
void someFunction()
{
NavigationController.PushViewController (new MyDemoController("Details"), true);
}

How to push new screen from global screen in blackberry?

Here I am display push notification in globalscreen in blackberry, I need to push screen by clicking OK button of the dialog. I want to start app by clicking the ok button.
Please help me.
Thanks in advance!
I'm not 100% sure I understand what you want, but if this doesn't work, just add a comment and I'll try to give you a better answer.
First, read this on pushing global screens
and this on performing actions after receiving global alerts
Your code, if I'm understanding correctly, should be similar to the second link's example.
Then, if you implement the DialogClosedListener, like in the second link, you might have something like this:
called from the background when you get notified:
Dialog myDialog = new Dialog(Dialog.D_OK_CANCEL, "Hello", Dialog.OK, null, 0);
myDialog.setDialogClosedListener(new MyListener());
UiApplication.getUiApplication().pushGlobalScreen(myDialog, 1, true);
implementation of your dialog listener:
private class MyListener implements DialogClosedListener {
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
// ok clicked
UiApplication.getUiApplication().requestForeground();
break;
case Dialog.CANCEL:
// cancel clicked. or escape pressed
break;
default:
break;
}
}
}
And, then in your UiApplication class, you can respond to activation, which will happen if the user selects Ok from the Dialog:
public class MyApp extends UiApplication {
private boolean _nextScreenShowing = false;
public void activate() {
super.activate();
if (!_nextScreenShowing) {
pushScreen(new NextScreen());
_nextScreenShowing = true;
}
}
}
I show the _nextScreenShowing variable, just to make sure you think about whether pushing the next screen is appropriate. It probably won't be every time activate is called. You may need to keep track of that boolean flag by responding to the Application.deactivate() method, or maybe Screen.onExposed() or Screen.onObscured(). All that depends on how your app works.

Resources