In Xamarin Form Project Create ExtendedEditor Class that Inherit the Editor Class
ExtendedEditor.cs
using System;using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace MeChatApp.Renderer
{
public class ExtendedEditor :Editor
{
}
}
Then in Android Project Create the Class ExtendedEditorRenderer.cs that Inherit the Editor Renderer
ExtendedEditorRenderer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MeChatApp.Droid.Renderer;
using MeChatApp.Renderer;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(ExtendedEditor), typeof(ExtendedEditorRenderer))]
namespace MeChatApp.Droid.Renderer
{
public class ExtendedEditorRenderer : EditorRenderer
{
public ExtendedEditorRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (Control != null)
{
GradientDrawable gd = new GradientDrawable();
gd.SetCornerRadius(50);
gd.SetStroke(3, Android.Graphics.Color.Gray);
Control.SetAutoSizeTextTypeWithDefaults(AutoSizeTextType.Uniform);
Control.SetMinHeight(200);
Control.SetBackground(gd);
}
}
}
}
Now you can use that in Xaml Page
Tab1.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:customControl="clr-namespace:MeChatApp.Renderer"
x:Class="MeChatApp.Views.TabbedPages.Tab1" Title="Buzz" Icon="menubuzz">
<ContentPage.Content>
<StackLayout>
<customControl:ExtendedEditor AutoSize="TextChanges" Placeholder="Write Something" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
No comments:
Post a Comment