How to capture DialogViewController refresh in Xamarin.iOS? - ios

I am using Xamarin to build a simple app. In my app I use a series of classes that inherit from DialogViewController. In some cases, when the user clicks on an item, I use:
NavigationController.PushViewController( new DialogViewClass() , true );
This when the DialogViewClass() starts and sets up a new view, it might alter the state of the data that requires my current Dialog to be refreshed.
When the user finally backs out of the stack, and reshows my dialog, how do I capture "the event" that says my dialog is being redisplayed, so that I can update my view with current information?

Found my answer. In the class that inherits from DialogViewController, add this override:
override void ViewWillAppear( bool animated ) {
base.ViewWillAppear( animated );
// Show the page
}
In my case, simply rebuilding the interface based on the values in my constructor is good enough whether the page is being loaded for the first time, or is being reloaded after a POP action.

Related

Xamarin.Forms set ModalInPresentation

Is there a way to set the ModalInPresentation value from Xamarin.Forms? I can set On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet); on my ContentPage but I"m not able to prevent a dismiss of the page for specific cases as I would need it.
but I"m not able to prevent a dismiss of the page for specific cases as I would need it.
Generally,we can use ModalInPresentation = true; to prevernt the page be dismissed in page renderer.
public class CustomPageRenderer :PageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
ModalInPresentation = true;
}
}
It works in Xamarin.iOS. However, it not works in Xamarin Forms now. I will check that where problem is.
I've uploaded a sample project here:
www.otherwise.com/ModalPresentation.zip
The MainPage just has a button that shows a modal panel via:
Navigation.PushModalAsync(new OTNavigationPage(new ModalPage()));
OTNavigationPage is a subclass of NavigationPage. I use it to set the modal presentation style:
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet);
There is also OTContentPage which exists only so I can have a native renderer to try to set the ModalInPresentation flag to true. I do this in a variety of places trying to find one that works. None do.
I expect setting ModalInPresentation = true should prevent the modal panel from being dismissed via swiping. It does not.
There is also a bug which I think the team knows of where swiping to dismiss corrupts the navigation stack. If I try to show the modal page again I get:
Warning: Attempt to present <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x10782cc00> on <ModalPresentation_iOS_OTNavigationPageRenderer: 0x107128600> whose view is not in the window hierarchy!
This post talks about it: https://github.com/xamarin/Xamarin.Forms/issues/7364

How to disable back operation of Flutter's Navigator class

After a login page, a page gets replaced by an overview page like so:
Navigator.popAndPushNamed( context, MyApp.ROUTE_TESTER_TASK_OVERVIEW );
This removes the current page from the Navigator's stack and pushes the new page on it. Fine.
Q: But how to I disable, that a user performs a back navigation? The user shouldn't bee able to leave the Task Overview page.
Should I keep the stack holding one and only one page all the time.
Or does Navigator has another option to disable a back navigation?
Q: Additionally, I want to disable the swipe right gesture, so than it doesn't show the previous page [as I the user clicked Android's back button].
One possible (probably not the best) solution is to wrap the second page within a WillPopScope widget. In the onWillPop parameter you can just return Future.value(false) to intercept all pop actions.

How to have one button do both "enable" and "disable" in ASP.net MVC

I am new to ASP.Net MVC, and still trying to wrap my head around the controller and passing data to the view and back.
Here is my question. I have a model in my view with a property that is "isEnabled", which can be true or false.
I have an edit button, and an enable/disable button. Edit just takes me to a new view with a form.
I want the enable/disable button to change the property of the model to enabled or disabled.
Right now I have two separate buttons. When I click on them, it fires the appropriate action from the controller (EnableModel, DisableModel), and just reloads the current view.
How can I make it so, if the model is disabled the button shows and fires the enable action, and when it is enabled, the button shows and fires the disable action.
So here are the options I thought of.
1. Two buttons, I hide them as needed. I can use an if statement to check if the model is showing or not in razor.
2. Use javascript two to the above
3. Use javascript to physically change the button
What would be the best method?
Alright so looking back can't believe I ever even asked this haha.
I went the javascript route. I had a single button, and a simple onClick javascript class that would handle the toggling.

Vaadin: force Button to be visually disabled

I have several TextField's inside a window along with a Button, e.g. aButton.
The TextField's, Button, and window all have setImmediate(True).
When a TextField loses focus some validation code is executed and if it fails it calls:
aButton.setEnabled(False);
When incorrect data is entered into one TextField and then focus is lost the debugger shows that aButton.setEnabled(False) is called but aButton still looks enabled.
Two possible things can happen from here:
1.) If one modifies data in another TextField and exits that field (loses focus), the validation can be successful or not for that field but the system knows to call aButton.setEnabled(False) as the previous TextField is still invalid. This time though aButton is visually disabled.
2.) If one clicks on aButton which is visually enabled it produces this warning then visually becomes disabled:
Warning: Ignoring variable change for disabled component < class 'ui.button.Button'>, caption=OK
Currently using Vaadin 6.7.3
Are there any known work arounds to force aButton to visually become disabled immediately (force the client to update) after manually setting it to be disabled?
Sadly I have only Vaadin 7 at my disposal right now, but I checked this anyway. It works as you wanted it to work and I have to jump to the conclusion that this should be the same in Vaadin 6.7.3. This part is not really different in Vaadin7... Have you tried this feature in an isolated code (only a textbox and the button)?
VerticalLayout vlTestContent = new VerticalLayout();
final Button butChangeMe = new Button("Enabled");
final TextField tf = new TextField("Blur", "default value");
tf.addBlurListener(new BlurListener() {
private static final long serialVersionUID = 5544993392287938660L;
#Override
public void blur(BlurEvent event) {
butChangeMe.setCaption("Disabled");
butChangeMe.setEnabled(false);
}
});
Button but = new Button("Change button", new ClickListener() {
private static final long serialVersionUID = -2235317499126190105L;
#Override
public void buttonClick(ClickEvent event) {
butChangeMe.setCaption("Enabled");
butChangeMe.setEnabled(true);
}
});
vlTestContent.addComponent(butChangeMe);
vlTestContent.addComponent(tf);
vlTestContent.addComponent(but);
(The second button is just for fun)
button.setVisible(false) will always work. You need to be careful to not fire up a another event on the focus lost event that ends up setting the visibility of the button to true.
You can request a repaint of a component or the whole window, but the whole point of the framework is that you will never need to do that, because visually modified components will automatically repaint on each request.
Just to be curious, do you let your request to finish before trying to see if the browser updates? Or you look at your browser right after you pass the setVisible() line in your debugger ?
I think that your point nr 2 happens because you clicked on the button, and what happens in this order is: 1st your focus lost event runs (which probably disables your button), 2nd button click runs and somehow a repaint is requested for that button because a state change happened in the button but a repaint show the warning that it won't do anything with it because it is disabled (was just disable by the focus lost event)
As a side note. I think this UI won't make for a good user experience, it should be the other way arround, if a validation is ok, then show the button (or better, always show the button, but enable/disable instead) But it depends...

How to access filed on the screen using Screen Object ( UiApplication.getUiApplication().getActiveScreen())

My Query is How to access Fields on the stacked screen using Screen Object ?
The exact problem is as follows:
I have one screen which has one text field (ClientName) when user clicks on that field , application will then push a new screen and it will allow the user to search in remote database using MyWebSerivces. and when user selects the one client from the search result ,i want to set the text Field on the previous screen with the text that user has selected on the current screen..
i have tried the pushScreen( new screen("text) ) and that might be the result if i want to do this operation only once but this is not the option for me since there is two more such field which will go to other screen to fetch the data from webservices . and if i every time i push new screen then after every pushscreen operation i will only get one field set with the desired text
This not a blackberry (or any specific programming language) related question. This is a question of application architecture and common sense. If one screen should change a Field of another screen, then just pass a reference of the Field to the screen that will change it.
hi i once had same problem and i did like this:
Screen1
------------------
Client Name | text field |
------------------
When user clicks on this text field or any button you push Screen2
In screen 2 when user selects a particular value then u do this.
1) take a static variable in main class say clientName.
2) set value of this variable.
3) pop active screen
UiApplication.getUiApplication().getActiveScreen();
when this code is called then u come back to Screen1
Now in screen1 a method is called
public void onExposed()
{
//here u can set the text in textfield using the static variable
invalidate(); // for repainting
}
i have found the answer to my question. the solution was there lying in my question but at first i was not able to find it.
solution was very simple
when i wrote i want to use
UiApplication.getUiApplication().getActiveScreen()
that was almost the right way and i was proceeding in right direction but the thing that i was missing was " I was not casting the screen (that i have just retrieved form the stack top ) to its type
only thing i should have done is "should have casted screen to its type.like this
UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen()
now i am able to access all the fields on the retrieved screen (MyScreen1)
things to keep in mind
make sure u cast the screen to its type only otherwise bb will give u resource not found error
Benifits of using screen on Stack
u can use already created screen from the stack no need to create new one
if u will create new screen it will be stacked in memory and will consume more and more memory even if its of no use ( make habit to pop the screen if it is of no use instead of leaving it on stack))
no need to create any static variable since u will be able to set all the field right away from other screen

Resources