0

我正在使用 Com.Alamkanak.Weekview 在我的 xamarin forms android 应用程序中处理日历事件。我的要求是在内容页面中加载日历事件。

为此,我在内容页面中创建了 ViewRenderer 和我的代码,例如

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:controls="clr-namespace:App.CustomControls"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:app.CustomControls">
    <ContentPage.Content>
             <StackLayout Orientation="Vertical">
                <ContentView>
                    <OnPlatform x:TypeArguments="View">
                        <OnPlatform.Android>
                            <local:CustomCalendarEvent/>
                        </OnPlatform.Android>
                    </OnPlatform>
                </ContentView>
            </StackLayout>
          </ContentPage.Content>
</ContentPage>

我的 CustomCalendarEvent 是

    public class CustomCalendarEvent : View{ }

我的 ViewRenderer 就像

    [assembly: ExportRenderer(typeof(CustomCalendarEvent), typeof(CustomCalendarEventRenderer))]
    namespace App.Droid.CustomRenderers
    {
    public class CustomCalendarEventRenderer : ViewRenderer
    {
    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
    {
        base.OnElementChanged(e);
        if (Control == null)
        {
            try
            {
                var intent = new Intent(Forms.Context, typeof(Events));
                Forms.Context.StartActivity(intent);

                //var context = Xamarin.Forms.Forms.Context;
                //LayoutInflater inflater = context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                //var _view = inflater.Inflate(Resource.Layout.EventView, this, false);
                //mWeekView = _view.FindViewById<WeekView>(Resource.Id.weekView);
                //SetNativeControl(_view);
            }
            catch (Exception ex)
            {
                string Message = ex.Message;
            }
        }    
    }
}

我的活动活动就像

    public class Events : AppCompatActivity, WeekView.IEventClickListener, WeekView.IEventLongPressListener, MonthLoader.IMonthChangeListener
        {
            private SupportToolbar mToolbar;

            private static int TYPE_DAY_VIEW = 1;
            private static int TYPE_THREE_DAY_VIEW = 2;
            private static int TYPE_WEEK_VIEW = 3;
            private int mWeekViewType = TYPE_THREE_DAY_VIEW;
            private WeekView mWeekView;
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.EventView);
                ---
            ----------  
                ---
            ---------- 
                ---
            ---------- 

             }
      }

如果我使用 StartActivity,我的事件页面将显示为单独的页面,如果我使用 SetNativeControl(_view),我的事件不会显示在内容页面中。请帮助我了解如何使用 ViewRenderer 在内容页面中加载事件活动。

谢谢。

4

0 回答 0