Xamarin Android App - c#

I'm developing an Android app with Xamarin and I was able to understand how to create a button and go from the main layout1 to layout2 but when I try to go from layout2 to layout3 the button doesn't work and I've been trying to research and get nothing.
I tried putting this code in the MainActivity.cs and in the second Activity so it can go to layout3 but I noticed my code works from MainActivity.cs to go to layout3 but the code doesn't work from layout2 to go to layout3 - help please?
Button BreakFast = FindViewById<Button>(Resource.Id.BTN_MAINMENU_BREAKFAST);
BreakFast.Click += delegate {SetContentView(Resource.Layout.BreakfastMenu);};

I'm not sure, because what you're doing is kind of freakish to me, but since you're setting a new layout you should bind the new id's to the button. I'm guessing you have a button on layout 2, which should take you to layout 3. You should bind the variable to a view's id.
Also... don't do that. Create another activity, so when it start onCreate will be called and that will bind your views.

Related

Setting InputAccessoryView into UISearchController

I'm currently trying to extend my Xamarin.Forms app with search bars in the navigation bar by this guide: https://codetraveler.io/2019/10/05/adding-a-search-bar-to-xamarin-forms-navigationpage/
So far it works great. But now I also want to add custom action to the keyboard based on what is available on this page. But it seems like the InputAccessoryView has no available setter for the UISearchController. So how can I set those custom actions and a Done button to it? Is there some other way to add this? Or is it maybe a bug by Xamarin that the InputAccessoryView is not setable?
nvm sometimes a bit of sleep helps a lot. The InputAccessoryView needs to be set on the SearchBar within the UISearchController of course and not directly on the UISearchController...

Page navigation Xamarin.Forms

I'm new to android apps and xamarin.
I'm trying to build an android app, which exists of 2 views.
1 view with a listview, and 1 view to add a new item to the listview.
My idea is that whenever you press the button, the second view appears.
And when you click on the button add, it switches back to the first view.
I thought this code would work:
await Navigation.PushAsync (new ContactPage());
But as you can see,
The term Navigation is not being recognized.
One mistake I see in your code is using await with Navigation, it's not needed their.Second It seems like you are just setting your first page as MainPage in App.cs.
In order to use the Navigation class in Xamarin.Forms you have to first create NavigationPage instance usually people do that in App.cs like following :
MainPage = New NavigationPage (New ContentPage());
And then in any page they can use navigation by using following code like
Navigation.PushAsync(New ContentPage());
You can only use Navigation with NavigationPage.
So i've found the solution.
First of all it is not possible to have a App.cs file if you don't use cross-platform, which in my case is true.
To solve the problem, you have to use another method, which is called android Multiscreen. Here's a link if you want to check it out.

MvvmCross Navigate From ViewModel Event

I read about "ViewModel to ViewModel navigation" and "View Model Lifecycle" from here:
https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation
https://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle
I can use Init() or Start() methods to initialise current ViewModel.
Also I can pass parameters from one ViewModel to another and receive it in the Init() method.
So my question:
When I created windows phone apps I used "NavigateTo" and "NavigateFrom" methods.
Init() is similar to "NavigateTo".
But I didn't find alternative for "NavigateFrom" method in mvvmcross and I don't know how to reload data when I move 'back' by "Close(this)" or using back button on windows phone.
Could you hint me?
Thanks in advance!
updated
I found out that Messenger (MvvmCross plugin) can help me with informing first ViewModel, when an other second ViewModel has changed data (for example add an item to a collection).
So when the second ViewModel add a new item, first ViewModel reloads the data in the OnCollectionChanged(CollectionChangedMessage obj) method.
Stuart showed how to work with this plugin in the NPlus1DaysOfMvvmCross/N-13-CollectABull-Part2.
Link here: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-13-CollectABull-Part2
But I didn't find alternative for "NavigateFrom" method in mvvmcross and I don't know how to reload data when I move 'back' by "Close(this)" or using back button on windows phone.
In general, you don't need to reload data in this event - because the ViewModel is already created and initialised from the previous navigation in the forwards direction.
If you do want to do some refresh of the ViewModel when navigating back, then the IVisible pattern in the N=42 video may help but you'll need to add this to your View and ViewModel yourself - see http://slodge.blogspot.co.uk/2013/11/n42-is-my-viewmodel-visible-can-i-kill.html

Using GroupedItemsPage as main Menu

I'm kind of standing on a pipe (if that saying works as it does in german) with my current problem.
I would like to create a Windows Store app which uses the GroupedItemsPage as kind of a main Menu with each tile navigating to a new page/part of the application.
Now all Tutorials/Examples I found are using the GroupItemsPage to display the same kind of content. So each tile is of the same kind of datatype and mostly stored in a list or something.
The step between coming from a background where I would love to simply create each tile by doing something like SettingsPage mySettingsPage = new SettingsPage(); and adding that to the right View to something different is difficult right now.
The only idea I would have right now to fill my GroupedItemsPage would be to create a new DataSource of a generic Type and add each and every single page to this DataSource, but that seems strange to me ...
What's the best practice here?
Use this:
https://skydrive.live.com/?cid=3a5ca8204ec61147&id=3A5CA8204EC61147%2135841&authkey=!AAOLlNWZh4K-FkQ
to main page add this in xaml:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.DefaultViewModel["Groups"] = e.Parameter;
}
and copy from this project classes to your project.

How do you navigate to a new page in a metro app?

trying to write a metro app in C# right now. Ran into a problem while trying to navigate to a new page.
<HyperLinkButton NavigateUri="foo.xaml"/>
doesn't work, as the NavigateUri field doesn't exist.
The Windows.Navigate namespace isn't available either, so no luck there. What's the proper way to go to a new page in my app in metro?
You can handle the Button control's Click event (in fact, you can use all events with the following code) because Metro's HyperLink button only inherits the ButtonBase class without any special properties or events, such as NavigateUri.
If you want to navigate to another page in your metro app, add a frame in the .xaml page and put this code in the button's event handler:
this.Frame.Navigate("VideoStoryCreator.ComposePage");
There are two ways of Navigating to another page -
Client app way ->
You'll implement this in click event -
var page = new PageName();
Window.Current.Content = page;
Similar to Silverlight Navigation
If you are using Frame/Page Navigation then you can do it like this -
Create a shell page (master page) with the element declared. Then instead of creating new pages with create .
The easiest way to do this is to replace UserControl with Page
This is nicely explained in this tutorial -
http://www.markermetro.com/2011/11/technical/windows-8-metro-style-apps-implementing-navigation-with-xaml/
Hope it helps!
Regards,
Bhavik
Handle the Click event on the button and then call the Navigate method on your Frame
just type the following code in your click event
this->Frame->Navigate(TargetPageName::typeid,this);

Categories

Resources