New Page on Xamarin.ios - c#

I am very new to Xamarin.
I have created a login page for my app but I need a new page to use as the main menu. The new page should be editable on Xcode to design the UI. It also needs a ViewController.cs to run some code inside it.
Are there any possible ways that I can create a page which needs my requirements that I have just mentioned?

I solved the issue by creating a new ViewControl in Xcode then I specified it's class at identity inspector and I also gave it a storyboard ID from the same menu.
Then I wrote the following code to display the new ViewControl.
MainViewController mainViewController = this.Storyboard.InstantiateViewController("MainViewController") as MainViewController;
mainViewController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
PresentViewController(mainViewController, true, null);
MainViewController is the class that I mentioned in identity inspector and second MainViewController which is inside the quotation mark is my storyboard ID.

Related

Disable runtime cache in Microsoft.Web.WebView2.Wpf

I am creating a webview2 wpf application, everything works well till now, but when I tried to load HTML file which is having youtube link, It's worked well along with autoplay .
But when I change the HTML file to some another site , the audio of youtube video still playing in background and webview2 load the new content.
I want something to disable the cache to be stored will runtime instead of clearing the cache.
If someone is having any idea related to above issue please help
This is the common issue faced by the webview2 when external site media player is played.
To overcome this issue you have to create a new instance of webview2 before you load second content to webView, this will create new Webview Page but still the UI will not stop the audio, so use Webview.dispose() as well.
WebView.Dispose()
Note : this will give you issue related to Null object reference for the 1st time .
So you have the check the the object before doing dispose.
Code should be like this :
MainPage :
WebViewPage webpage;
private void updateNewContent ()
{
...
WebView2 webView2 = Mywebvew2; // MYwebview2 is UI object from webviewPage,
//you have to pass this object from webview Page
if (webView2 != null)
{
webView2.Dispose();
}
webpage = null;
webpage = new WebViewPage();
GridPrincipal.Children.Add(webpage);
...
}

Activity Destroyed when trying to call a new Fragment page - Xamarin.Android

I am using a Xamarin.Android template (BottomNavigationView) to create an app with a bottom menu. I am trying to get it so that one of the pages that is on the menu ie a profile page has a button that will take me to another fragment. However when I call the SupportFragmentManager I am getting an error saying "the activity has been destroyed".
I'd like both those buttons to go to other pages that also display the bottom menu button (as i would like it to be consistent throughout my app). The code I am using is:
FragmentActivity fragmentActivity = new FragmentActivity();
fragmentActivity.SupportFragmentManager.BeginTransaction()
.Replace(Resource.Id.content_frame, ShowFriendRequests.NewInstance())
.Commit();
The template I am using uses the android.support.v4.app.Fragment and has a MainActivity that I think uses FragmentActivity. But I'm not entirely sure because it was all premade. I have just added the fragment files.
Any idea why I'd be getting this error?
Thank you
Anyway I think you are not preforming FragmentTransaction correctly instead of using FragmentActivity use FragmentTransaction to replace one Fragment with another or to Add another Fragment. For example in Java code that would go like this:
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, new ShowFriendRequests()).commit();
In c# I suppose something like this:
FragmentTransaction fragmentTx = FragmentManager.BeginTransaction();
ShowFriendRequests friendRequest = new ShowFriendRequests();
// Id is ID of your layout which you want to replace with fragment
fragmentTx.Replace(Resource.Id.content_frame, friendRequest);
fragmentTx.Commit();

Xamarin forms image import to new page

I want to import an camera/Gallary image into a page, not into the App() page, the function ShouldTakePicture() doesn't work, can anyone provide a sample code where I can import image to another page and display in a listview?
This import image was done form code in the link http://xforms-kickstarter.com/#camera
However when doing in another page, the MainActivity throws bellow error
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'Gallary2.Injury' to 'Xamarin.Forms.Application' Gallary2.Droid C:\Users\haris\Documents\Visual Studio 2015\Projects\Gallary2\Gallary2\Gallary2.Droid\MainActivity.cs 32 Active
can anyone help me with image import demo project in Xamarin Forms? (Only c# please, we are not making changes in XAML )
It sounds like you created a new page and in that new page you created a ShouldTakePicture property of type Action. The reason that the code is now failing, is because of this line in the iOS and Android projects:
(Xamarin.Forms.Application.Current as App).ShouldTakePicture += () => {
That line is expecting the ShouldTakePicture property to be in your App class, but it has been moved to your new page.
To fix this, you could either move that property back into your App class and then reference it from your new page by calling Command = new Command(o => App.ShouldTakePicture()),.
A better way to fix this would be to use Xamarin's DependencyService, info about that is here. If you need help setting up the DependencyService, let me know.

Navigation between pages in WP8.1

I'm trying to migrate my app from WP8 to WP8.1. And I don't get how to navigate to already opened page with another parameters.
For example, I'm showing user info on UserPage giving it user's id as parameter. And when page is already is the content of the Frame I want to open UserPage again but for other user giving it another id.
My problem is that, using NavigationCacheMode set to Required for UserPage means that there will be no navigation with other parameters. But when NavigationCacheMode is set to Disabled navigation with another parameter is success but when I press back button old instance of UserPage is using data from new one.
In WP8 passing new parameters was enough to create new instance of a page with it's own cache. How to do similar in WP8.1 using WRT APIs?
Thanks to Romansz for the tip about using UserControl. Using UserControl binding to a ContentControl and handling BackKeyPress solves my problem with navigation.

Load a custom server control from another custom server control

I have two custom server controls in a ASP.NET page,
one builds a chart, the other one plays the builded chart.
so my problem is to load the player when the chart is built.
so i send the file to the builder and now ii want just to load it
gChartPlayer Player = new gChartPlayer();
Player.XML_FILE = ChartFile;
something like Player.Load(),
can someone help me??
Question isn't really clear but if you want to decide when to load a usercontrol you can use LoadControl http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx
You can use Add Method
Code : this.Controls.Add
Link : http://msdn.microsoft.com/en-us/library/aa277578(v=vs.60).aspx

Categories