Reputation: 1931
I have Custom Renderers for some controls (Button
, Picker
, Label
) and there are some common properties, which I have set in the Custom Renderers and in some cases, I want to set different properties, which I have set from XAML. But, because of Custom Renderers, the properties set in XAML are overridden. Is there any way to check in the Custom Renderers, if those properties are set from XAML and to avoid the common behaviour?
Upvotes: 0
Views: 165
Reputation: 13601
You can add check using the DefaultValue
property on the corresponding bindable property.
For example, following code will assign new value only if the BackgroundColor
property on the control was not set in XAML, style, or binding.
if(Element is Label lbl)
{
if(lbl.BackgroundColor.Equals(Label.BackgroundColorProperty.DefaultValue))
{
lbl.BackgroundColor = newValue;
}
}
Upvotes: 2