简体   繁体   English

Xamarin.Forms平台特定的代码

[英]Xamarin.Forms platform specific code

Good day readers, i'm trying to use a method that is ment for android how do i cast the ContentPage to an Activity of android in PCL is it even possible ? 祝读者好运,我正在尝试使用针对android的方法我如何将ContentPage转换为PCL中的android活动,甚至可能?

Tried with directives but its also not working 尝试过指令,但也不起作用

 public static void AddEvent(GSDEvents ev, Activity ac)
        {
            // Id++;
            Calendar cal = Calendar.GetInstance(Java.Util.TimeZone.Default, Locale.Default);
            ContentValues eventValues = new ContentValues();
            eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, Id);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, ev.Title);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, ev.Description);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(ev.Year, ev.Month, ev.Day, ev.Hour, ev.Minute));
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(ev.Year, ev.Month, ev.Day, ev.Hour, ev.Minute));
            eventValues.Put(CalendarContract.Events.InterfaceConsts.AllDay, ev.AllDay ? "1" : "0");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, ev.HasAlarm ? "1" : "0");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "GMT+1:00");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "GMT+1:00");

            var uriCalendar = ac.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);

            ContentValues remindervalues = new ContentValues();
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, ev.ReminderMinute);
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, Id);
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)Android.Provider.RemindersMethod.Alert);

            var uriCalendarReminder = ac.ContentResolver.Insert(CalendarContract.Reminders.ContentUri, remindervalues);

        }

in my contentpage 在我的内容页面

#if __ANDROID__

            GSDEvents ev = new GSDEvents();
            ev.Title = "Test Event";
            ev.Description = "Dit is nog een test van de beschrijving";
            GSDEvents.AddEvent(ev, __THEPROBLEM HOW CAN I GET THE ACTIVITY);    
#endif

does someone know how achieve this i'm working in PCL Hope someone can point me to the right direction. 有人知道我如何在PCL中实现这一目标吗?希望有人能指出我正确的方向。

Kind Regards, Stefan 亲切的问候,斯特凡

You only have one activity. 您只有一项活动。 Main you find it in your Droid app. 主要是您在Droid应用中找到它。 If you need something specifically up in the activity code it there and initiate it from withen your Xamarin forms Page with an event. 如果您需要在活动代码中专门添加一些内容,然后在Xamarin表单页面中通过事件将其启动。 Pages don't really correlate to Activities at least not in the way your thinking. 网页与活动没有真正的关联,至少与您的思维方式没有关联。

Xamarin Forms is Cross Platform by design thus if you couldn't do it on IOS, WP and Droid you cant do it inside Forms. Xamarin Forms在设计上是跨平台的,因此,如果您无法在IOS,WP和Droid上执行此操作,则无法在Forms中执行。 Since obviously theres no Activities on the other 2 platforms Forms has no concept of an activity withen the PCL. 因为显然在其他两个平台上没有活动,所以Forms没有PCL的活动概念。

Im not familiar enough with what a GSDEvent is to help further. 我对GSDEvent的帮助还不够熟悉。 But to do what you want your going to have to put an event on your ContentPage. 但是要做您想做的事情,就必须在ContentPage上放置一个事件。 Assign the Code to the event from the Activity in Your Droid Project and fire it inside your PCL when you want it to function. 将代码分配给Droid项目中的“活动”中的事件,并在希望其起作用时在PCL内部触发它。

Alternately you could create a Class in your PCL with an event on it Instantiate it in your droid project and assign the event and then put it into an IOC container that you access from the PCL. 或者,您可以在PCL中创建一个带有事件的类,在您的droid项目中实例化它并分配该事件,然后将其放入可从PCL访问的IOC容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin.Forms Prism中特定于平台的代码 - Platform specific code in Xamarin.Forms Prism 在 Xamarin.Forms 中编写特定于设备平台的代码 - Write device platform specific code in Xamarin.Forms 为什么ASMX在Xamarin.Forms中特定于平台? - Why ASMX is platform specific in Xamarin.Forms? 如何使用 Xamarin.Forms 中的 DependencyService 在共享代码中获取平台特定代码的 static 成员? - How to get static member of platform specific code in shared code using DependencyService in Xamarin.Forms? 如何从 xamarin.forms 调用特定于平台的页面 - how to call platform specific page from xamarin.forms 将数据从平台特定页面传递到Xamarin.Forms中的PCL - Passing data from platform specific page to PCL in Xamarin.Forms Xamarin.Forms,无法从特定于平台的项目中上课 - Xamarin.Forms, cannot reach class from platform specific projects Xamarin Forms:如何实现平台特定的代码 - Xamarin Forms: how to implement platform specific code Xamarin.forms无法使用Xamarin.Auth和特定的android平台从对象转换为system.type - Xamarin.forms cannot convert from object to system.type with Xamarin.Auth and specific android platform Xamarin Forms - TabbedPage 平台特定 xaml 代码到代码隐藏 - Xamarin Forms - TabbedPage platform specific xaml code to code-behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM