xamarin.Android ViewRenderer中的AppCompatActivity

时间:2019-01-23 12:52:15

标签: xamarin xamarin.forms xamarin.android android-calendar viewrendering

我正在使用Com.Alamkanak.Weekview在xamarin表单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在“内容”页面中加载事件活动。

谢谢。

0 个答案:

没有答案