Xamarin Monodevelop - Error CS0103 - macos

I just installed Xamarin Monodevelop on Mac OSX, I created a GTK# project where I have a very basic Window that I haven't even touched. This is the error it gives me on Build();
Error CS0103: The name 'Build' does not exist in the current context
using System;
using Gtk;
public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}

The Build method is created by the Stetic UI builder, akin to the InitializeComponents of the Visual Studio UI builder.
There seems to be a bug in Xamarin Studio (I'm using 5.5.4.15) where the Build method is not generated unless you add a widget to the Window. Try adding a VBox or another container and then rebuilding.

Related

Xamarin UWP : app in front/rear (method unexisting ?)

I have a app in xamarin that listen a folder and do some action when a file is created.
But the thing is that I need to be able to :
bring my app in front when a file is created
push my app in rear when acyion are finished
I have a beginning of response with
Window.Current.Activate();
but that only work if my app is not minimize (app not in first view)
I've already tried this :
IList<AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();
IList<AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
await resourceInfos[0].StartSuspendAsync();
but visual studio tell me
AppResourceGroupInfo don't have a definition for StartSuspendAsync()
but documentation mention it AppResourceGroupInfo.StartSuspendAsync Method
someone have an idea ?
UPDATE [2020-04-29 16:48] :
This is a pcl project
the intention is to use dependency service to have diferent comportement in function of platform (already implemented just need the front/rear
interface in pcl
public interface IWindowManager
{
void Minimize();
void Maximize();
}
in uwp
class WindowManager : IWindowManager
{
public async void Maximize()
{
try
{
Window.Current.Activate();
}
catch(Exception ex)
{
DependencyService.Get<IErrorLogger>().LogError(ex);
}
}
public async void Minimize()
{
IList<AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();
IList<AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
resourceInfos[0].StartSuspendAsync();
}
}
and as I say StartSuspendAsync() encounter some problem
AppResourceGroupInfo don't have a definition for StartSuspendAsync()
Derive from official document, StartSuspendAsync() available in the Windows 10 update 1803 (build 17134). So please edit the UWP project mini version to 17134.
but that only work if my app is not minimize (app not in first view)
For making the app foreground, you could use the following code.
IEnumerable<AppListEntry> appListEntries = await Package.Current.GetAppListEntriesAsync();
await appListEntries.First().LaunchAsync();
Update
If above does not work, please try use register a protocol for UWP app and launch it with Windows.System.Launcher.LaunchUriAsync method.
public async void Maximize()
{
try
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("testapp:"));
}
catch (Exception ex)
{
Debug.Write(ex);
}
}

Embedding Xamarin Forms in Native Xamarin app with MvvmCross 6.0

I'm trying to embed Forms XAML view into Xamarin Native application with MvvmCross 6.0.
I tried to reproduce effect of this solution but I got stuck on registering IMvxFormsViewPresenter. I also followed this tutorial.
I have simple MainContainerActivity with MainFragment (with corresponding MainViewModel in Core) that contains a button to Forms SettingsActivity/SettingsViewModel.
Full source can be found in the test repository.
Currently, I struggle with an exception thrown in base.OnCreate(bundle); while navigating to SettingsViewModel:
MvvmCross.Exceptions.MvxIoCResolveException has been thrown
Failed to resolve type MvvmCross.Forms.Presenters.IMvxFormsViewPresenter
I cannot find a way to register this Forms Presenter. I tried to do it in Setup but with no success.
I also tried to resolve MvxFormsAndroidViewPresenter in SplashActivity but Mvx.Resolve<IMvxViewPresenter>() as MvxFormsAndroidViewPresenter; yields null.
Do you have any idea what should I do to incorporate Forms views into MvvmCross 6.0 native application?
namespace MvvmCrossFormsEmbedding.Droid.Views
{
[Activity(Theme = "#style/AppTheme",
Label = "SettingsActivity")]
public class SettingsActivity : MvxFormsAppCompatActivity<SettingsViewModel>
{
public static SettingsActivity Instance { get; private set; }
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// #1 Initialize
Forms.Init(this, null);
SetContentView(Resource.Layout.activity_settings);
var toolbar = FindViewById<Toolbar>(Resource.Id.layout_toolbar);
SupportActionBar.Title = "Settings";
Instance = this;
// #2 Use it
var frag = new SettingsView().CreateFragment(this);
var ft = FragmentManager.BeginTransaction();
ft.Replace(Resource.Id.fragment_frame_layout, frag, "main");
ft.Commit();
}
}
}

How to navigate to a Xamarin.Android module activity from a Xamarin.forms Page? How to achieve the same in Xamarin.iOS as well?

am relatively new to Xamarin. I have a solution with Xamarin.Forms project and a Xamarin.Android(Native) project. Is it possible to launch the Activity in the Native module from a 'Page' in Xamarin.forms, say when we click on a button. Also is the same applicable in Xamarin.iOS ?
Is it possible to launch the Activity in the Native module from a 'Page' in Xamarin.forms, say when we click on a button
The answer is yes.
You can use DependencyService to achieve it.
In Android:
1) Define a interface in PCL:
public interface IOpenPage
{
void OpenPage();
}
2) Implement the interface in Android:
[assembly: Dependency(typeof(OpenPageImpl))]
namespace App2.Droid
{
class OpenPageImpl : IOpenPage
{
public void OpenPage()
{
Forms.Context.StartActivity(new Intent(Forms.Context, typeof(TextActivity)));
}
}
}
3) In your button's click event:
private void ToPage(object sender, EventArgs e)
{
DependencyService.Get<IOpenPage>().OpenPage();
}
Update:
Xamarin.forms project:

SfChart are not displaying on IOS and working properly in Android - Xamarin Forms

Syncfusion sfchart working fine in android but generating error in IOS. here is my AppDelegate class code
AppDelegate:
namespace ProjectName
{
[Register ("AppDelegate")]
public class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
new Syncfusion.SfChart.XForms.iOS.Renderers.SfChartRenderer();
global::Xamarin.Forms.Forms.Init ();
Appearance.Configure ();
LoadApplication (new App());
return base.FinishedLaunching (app, options);
}
}
}
If I remove 'new Syncfusion.SFChart.Xforms.IOS.Renderer.SfChartRenderer' from Code it run without generating any error or any result but when I put this line of code then it throw error which is
foundation.monotouchexception objective-c exception thrown
We were not able to reproduce the reported issue at our end and we have prepared a sample for this. Please check the attached sample.
Note: We suggest you to use Init method of SfChartRenderer as per the below code.
Code Example:
Syncfusion.SfChart.XForms.iOS.Renderers.SfChartRenderer.Init();
If you are still facing this issue, please update us the Xamarin Studio / Visual Studio version. Please download the sample from the following location.
Sample: http://www.syncfusion.com/downloads/support/forum/131907/ze/ChartGettingStarted1268455699
Regards,
Saravana Pandian M.

Error in executing the Xamarin.UITest for some reason

I am trying to do UI Testing using the Xamarin.UITest framework. I am trying to follow the procedure using the links that is given on their website.The application is named 'CreditCardValidator'. I downloaded the app and then did stuffs like upgrading the UITest package and not the NUnit package. As the tutorial mentions that the code that is to be mentioned is
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.iOS;
using Xamarin.UITest.Queries;
namespace CreditCardValidator.iOS.UITests
{
[TestFixture]
public class Tests
{
iOSApp app;
[SetUp]
public void BeforeEachTest()
{
Console.WriteLine ("Starting the function");
app = ConfigureApp.iOS.StartApp();
// app = ConfigureApp.iOS.AppBundle("/Users/admin/Library/Developer/CoreSimulator/Devices/57DBB268-714A-473F-A7D3-C3B4BB2BB138/data/Containers/Bundle/Application/A9151B5D-7B9C-4F9A-9EF2-F153AC994170").StartApp();
Console.WriteLine ("ending the function ");
}
[Test]
public void CreditCardNumber_TooShort_DisplayErrorMessage()
{
Console.WriteLine ("Starting the function");
app.WaitForElement(c=>c.Class("UINavigationBar").Marked("Simple Credit Card Validator"));
app.EnterText(c=>c.Class("UITextField"), new string('9', 15));
Console.WriteLine ("ending the function ");
}
}
}
MY PROBLEM :
The simulator is not opening and the tests are failing for no reason. The StartApp() functions documentation says that it LAUNCHES the app on the simulator. The error I am getting in the Test Results pad is
SetUp : System.NullReferenceException : Object reference not set to an instance of an object
They are failing at the line : app = ConfigureApp.iOS.StartApp();
I tried to replace this line with the compiled version of the app which is commented out in the code. But for that still the simulator is not opening and the error I am getting is
SetUp : System.Exception : App bundle directory doesn't contain a valid app bundle. Still the error is at the Startup function line
MORE INFO : In the second attempt I found that my .app file has a 'STOP' image on it. Could this be the reason ?
Please ask if more information is required.

Resources