Tag: xamarin

Xamarin.Forms:如何使用相对布局居中视图? `Width`和`Height`返回-1

当尝试在Xamarin.Forms中使用控件的Height和Width属性时,都返回-1,这会导致相对布局在屏幕上偏离中心。 var mainLayout = new RelativeLayout(); //Add the Switch to the center of the screen mainLayout.Children.Add(mySwitch, Constraint.RelativeToParent(parent => parent.Width / 2 – mySwitch.Width / 2), Constraint.RelativeToParent(parent => parent.Height / 2 – mySwitch.Height / 2)); //Add a Label below the switch mainLayout.Children.Add(switchLabel, Constraint.RelativeToParent(parent => parent.Width / 2 – switchLabel.Width / 2), Constraint.RelativeToView(mySwitch, (parent, view) => view.Y […]

xamarin.forms中的页面生命周期事件

我刚刚开发了我的第一个xamarin.forms应用程序。 我对xamarin.forms很兴奋,但我想念几个事件。 在xamarin.forms ContentPage中是否有任何页面生命周期事件? 我知道这两个: protected override void OnAppearing() { } protected override void OnDisappearing() { } 但OnAppearing()事件只触发一次。 在Android上,当我按下开始按钮并返回到我的应用程序时,此事件不会再次触发。 是否有解决方法(如WindowsPhone页面中的OnNavigatedTo)? 谢谢。

将UIImage转换为字节数组

我需要将UIImage转换为字节数组。 我正在使用Xamarin的Visual Studio插件来生成iOS应用程序。 下面的代码位获取图像,但我需要将其作为字节数组而不是UIImage发送到服务堆栈。 var signatureView = new SignaturePad.SignaturePadView(new RectangleF(10, 660, 300, 150)); signatureView.BackgroundColor = UIColor.White; this.View.AddSubview(signatureView); UIImage signatureImage = signatureView.GetImage();

如何在Xamarin.Android中正确编写自定义UncaughtExceptionHandler

我想要实现的只是捕获我的应用程序上的exception,以便我可以将它们发送到服务器。 我想通过在StackOverflow中回答Java中的原生Android代码编写我的自定义UncaughtExceptionHandler ,我可以做到这一点。 这是我的CustomExceptionHandler类: public class CustomExceptionHandler : Thread.IUncaughtExceptionHandler { public IntPtr Handle { get; private set; } public CustomExceptionHandler(Thread.IUncaughtExceptionHandler exceptionHandler) { Handle = exceptionHandler.Handle; } public void UncaughtException(Thread t, Throwable e) { // Submit exception details to a server … // Display error message for local debugging purposes Debug.WriteLine(e); } public void Dispose() { […]

在Xamarin.Forms中编写设备平台特定代码

我有以下Xamarin.Forms.ContentPage类结构 public class MyPage : ContentPage { public MyPage() { //do work to initialize MyPage } public void LogIn(object sender, EventArgs eventArgs) { bool isAuthenticated = false; string accessToken = string.Empty; //do work to use authentication API to validate users if(isAuthenticated) { //I would to write device specific code to write to the access token […]

IDE外部的外部终端/调试

我开始使用Xamarin Studio,并从VS迁移到它,但当我尝试运行一个控制台应用程序(此时加载的唯一一个)时,失败并在Console.Clear()中引发exception(假设我可以在集成的调试器中做到这一点,然后我认为解决它的一种方法是通过编译和运行它,就像Visual Studio一样,并在IDE之外调试应用程序,但我无法弄清楚如何。 有人能告诉我如何解决这个问题吗? 谢谢。 编辑:出于任何原因,它在选择Release时在嵌入式窗口中运行,但它无法读取输入,因此它会卡住。

是否可以从Sqlite查询返回动态对象或数据集?

我在我的Xamarin.Forms应用程序中使用Sqlite.Net 。 到目前为止,如果我的对象是这样的类,那么返回对象列表非常棒: SqliteDatabase.Connection.Query(“Select * from Customers”); 我现在想从查询中动态返回DataSet的等价物 SqliteDatabase.Connection.Query(“Select * from Customers inner join Calls on Customers.Id=Calls.CustomerId”) 现在从第二个查询我想返回一个DataSet而不是一个对象列表。 我知道我可以创建一个新的对象,它组合了Customers和Calls的列,但我不想每次想要查询数据库时都要创建对象。 是否可以动态返回Dataset或Object ?

Xamarin AlarmManager Android

我已经创建了一个快速的xamarin android项目。 最后我想学习下面的学习并将它应用到android和ios之间共享的xamarin表单项目中。 现在我只关注Android方面的事情。 我一直在努力学习如何安排本地通知在将来的某个时间出现。 快速扔掉应用程序,下面是我编写的AlarmReceiver类,以及下面的MainActivity.cs。 class AlarmReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra(“message”); var title = intent.GetStringExtra(“title”); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManager.FromContext(context); //Generate a notification with just short text and small icon var […]

Xamarin项目中SQLite-Net的通用存储库

我想知道是否有办法为我的Xamarin项目编写通用存储库,而不是为我的对象中的每个实体编写不同的存储库。 Xamarin Tasky Pro示例为Task实体提供了一个Repository,因为它是它拥有的唯一实体。 在我自己的项目中,我有多个实体,所以我的问题是如何使以下客户存储库变得通用,以便ProductManager,EmployeeManager等可以使用它。 如果你知道一个例子或博客文章,请指出我正确的方向 namespace App.DataLayer { public class CustomerRepository { private ProntoDatabase _db = null; protected static string DbLocation; protected static CustomerRepository Me; static CustomerRepository() { Me = new CustomerRepository(); } protected CustomerRepository() { //set the db location; DbLocation = DatabaseFilePath; //instantiate the database _db = new ProntoDatabase(DbLocation); } public static string […]

Xamarin Android Alarm Manager问题

我的Xamarin Android应用程序中有一个AlarmManager 。 我使用SetExact()以5分钟的时间配置它。 但它只在五秒后开始。 无论我何时配置它,它总是在5秒后触发。 我在Java中使用了完全相同的代码,它工作得很好。 代码: [BroadcastReceiver] public class AlarmReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { Log.Info(“AlarmReceiver”, “Triggered”); } public static void Start(Context context, long triggerAfterMilis) { var type = AlarmType.RtcWakeup; var alarmManager = (AlarmManager) context.GetSystemService(Context.AlarmService); var timerIntent = PendingIntent.GetBroadcast(context, 0, new Intent(context, typeof(AlarmReceiver)), PendingIntentFlags.CancelCurrent); alarmManager.Cancel(timerIntent); if (Build.VERSION.SdkInt […]