0

I am working on calendar events in my xamarin forms android app by using Com.Alamkanak.Weekview. My requirement is to load calendar events in Content page.

For that I have created ViewRenderer and My code in Content page like

    <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>

my CustomCalendarEvent is

    public class CustomCalendarEvent : View{ }

my ViewRenderer is like

    [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;
            }
        }    
    }
}

and my Events activity is like

    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);
                ---
            ----------  
                ---
            ---------- 
                ---
            ---------- 

             }
      }

If I am using StartActivity my event page is showing as separate page and if I use SetNativeControl(_view) my events are not showing in Content page. Please help me for how to load events activity with in Content page by using ViewRenderer.

Thanks.

asv
  • 33
  • 2
  • 7
  • You are creating a new Activity, a Form's application lives entirely within one activity (typically MainActivity). You should review how to create a View renderer: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view – SushiHangover Jan 23 '19 at 12:57
  • As far as I can see this is not compatible with Xamarin.Forms. You should use Xamarin.Android instead. – Ivan Ičin Jan 23 '19 at 13:06

0 Answers0