Hello Syncfusion-Team,
in my xamarin.forms application I have a dataform generated for a modal class. But I cant figure out how to change the FontFamily for group label, editor label and also the label of the inputs. I know that I can change the FontSize of these elements by adding a custom AutoGeneratingDataFormItem function containing:
e.DataFormItem.EditorFontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
e.DataFormItem.LabelFontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
e.DataFormGroupItem.LabelFontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
But how do I change the FontFamily?
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e)
{
if (e.DataFormItem != null)
{
e.DataFormItem.HintLabelStyle = new LabelStyle() { FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster"), FontSize = 10 };
e.DataFormItem.HelperLabelStyle = new LabelStyle() { FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster"), FontSize = 10 };
e.DataFormItem.ValidationLabelStyle = new LabelStyle() { FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster"), FontSize = 10 };
}
}
public class DataFormLayoutManagerExt : DataFormLayoutManager
{
public DataFormLayoutManagerExt(SfDataForm dataForm) : base(dataForm)
{
}
protected override View GenerateViewForGroupHeader(DataFormGroupItem dataFormGroupItem)
{
Label label = new Label();
label.FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster");
label.Text = "ContactInfo";
label.FontSize = 20;
return label;
}
} |
Thank you fopr you response. But unfortunately my problem is not solved yet. To show you from what I come from, here is a picture of the previous state.
Using you suggestions I managed to configure the GroupNames a I which. I'll use Comic Sans as demo in the new screenshot a the desired FontFamily. Using the TextInputLayout for the whole DataForm was not possible due to the checkbox, which does not supported. Therfore I set the Lyout of all other elements. Which still not behaving as desired it the actual text "Hello World" in the text-input field and the Label of the Checkbox input.
The usage of the TextInputLayout changes the design a little, but this if acceptable, maybe except for the CheckBox Label, which, beside the FontFamily does not quite match to the rest of the design. But I'll figure this out after having tzhe FontFamily in line.
dataForm.RegisterEditor("Text", new CustomTextEditor(dataForm));
dataForm.RegisterEditor("Name", "Text");
public class CustomTextEditor : DataFormTextEditor
{
public CustomTextEditor(SfDataForm dataForm) : base(dataForm)
{
}
protected override void OnInitializeView(DataFormItem dataFormItem, Entry view)
{
if (dataFormItem.Name == "Name")
{
view.FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster");
}
base.OnInitializeView(dataFormItem, view);
}
}
protected override View GenerateViewForLabel(DataFormItem dataFormItem)
{
if (dataFormItem != null && dataFormItem.Name == "CheckMe")
{
Label label = new Label();
label.FontFamily = Device.OnPlatform("Lobster-Regular", "Lobster-Regular.ttf#Lobster-Regular", "Assets/Fonts/Lobster-Regular.ttf#Lobster");
label.Text = "Check Me";
label.FontSize = 10;
return label;
}
return base.GenerateViewForLabel(dataFormItem);
} |
Thank you very much. This suggestion in combination with the first one solved my issue.