- Home
- Forum
- Xamarin.Forms
- Custom renderer for SfNumericUpDown is not invoked
Custom renderer for SfNumericUpDown is not invoked
We are using the SfNumericUpDown control in our application for various purposes, and we have to perform some styling customizations specifically on Android. In fact, we have a general background style for all EditText controls on Android, and we want to override this style particularly for the SfNumericUpDown controls.
using Android.Views;
using Android.Widget;
using MyApp.Droid.Renderers;
using Syncfusion.SfNumericUpDown.XForms;
using Syncfusion.SfNumericUpDown.XForms.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(SfNumericUpDown), typeof(CustomNumericUpDownRenderer))]
namespace MyApp.Droid.Renderers
{
public class CustomNumericUpDownRenderer : SfNumericUpDownRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SfNumericUpDown> e)
{
base.OnElementChanged(e);
if (Control != null)
{
for (int i = 0; i < Control.ChildCount; i++)
{
var child = Control.GetChildAt(i);
if (child is EditText editText)
{
editText.SetForegroundGravity(GravityFlags.CenterVertical);
editText.SetBackgroundResource(Resource.Drawable.edit_background_numeric);
...
}
}
}
}
}
}
The problem we are facing is that our custom renderer is not invoked at all. We also tested this behavior on UWP, with the same result, i.e. the OnElementChanged method not being invoked. Any suggestions on what might be the reason therefore? We are using the latest version of the SfNumericUpDown (18.1.0.44) and Xamarin Forms 4.4.0.991640.
The problem we are facing is that our custom renderer is not invoked at all. We also tested this behavior on UWP, with the same result, i.e. the OnElementChanged method not being invoked. Any suggestions on what might be the reason therefore? We are using the latest version of the SfNumericUpDown (18.1.0.44) and Xamarin Forms 4.4.0.991640.
SIGN IN To post a reply.
3 Replies
AS
Anandraj Selvam
Syncfusion Team
April 21, 2020 07:03 AM UTC
Hi Florian,
Greetings from the Syncfusion.
We have checked the provided code snippet and we would like to let you know that to invoke this custom renderer, please use the extended class of SfNumericUpdown as per in below code snippet
Code Snippet:
Existing Code:
|
[assembly: ExportRenderer(typeof( |
Modified Code:
|
[assembly: ExportRenderer(typeof(CustomNumericUpDown), typeof(CustomNumericUpDownRenderer))] |
MainPage.cs
|
public class CustomNumericUpDown : SfNumericUpDown
{
} |
CustomNumericUpDownRenderer
|
[assembly: ExportRenderer(typeof(CustomNumericUpDown), typeof(CustomNumericUpDownRenderer))]
namespace CustomBorder.Droid
{
class CustomNumericUpDownRenderer : SfNumericUpDownRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SfNumericUpDown> e)
{
base.OnElementChanged(e);
if (Control != null)
{
for (int i = 0; i < Control.ChildCount; i++)
{
var child = Control.GetChildAt(i);
if (child is EditText)
{
var control = child as EditText;
control.SetBackgroundResource(Resource.Drawable.layout1);
}
}
}
}
}
} |
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/CustomBorder411694152
Please revert us for further investigation.
Regards,
Anand Raj S.
UN
Unknown
April 22, 2020 10:55 AM UTC
Hi Anand,
Thank you very much for your fast response. I've just modified our renderer accordingly, and things are working now like a charm.
Regards,
Florian
AS
Anandraj Selvam
Syncfusion Team
April 23, 2020 08:21 AM UTC
Hi Florian,
Thanks for the update and we will wait to hear from you.
Regards,
Anand Raj S.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
UN Unknown
- Apr 20, 2020 07:57 AM UTC
- Apr 23, 2020 08:21 AM UTC