<inputLayout:SfTextInputLayout
Hint="Name" ErrorColor="Red"
EnablePasswordVisibilityToggle="true">
<inputLayout:SfTextInputLayout.Triggers>
<DataTrigger TargetType="inputLayout:SfTextInputLayout"
Binding="{Binding Source={x:Reference entry},Path=Text.Length}"
Value="0">
<Setter Property="ErrorText" Value="*Required" />
<Setter Property="HasError" Value="True"/>
</DataTrigger>
</inputLayout:SfTextInputLayout.Triggers>
<Entry Text="John" x:Name="entry" />
</inputLayout:SfTextInputLayout> |
Hi Tayyip Emre ÖRNEK,Greetings from Syncfusion.Your requirement has been achieved by using ErrorText with HasError properties. We have prepared the demo sample to show the required field update when there is have an empty text in Entry inside the SfTextInputLayout and customizing its color by using ErrorColor as per in below code snippet
<inputLayout:SfTextInputLayoutHint="Name" ErrorColor="Red"EnablePasswordVisibilityToggle="true"><inputLayout:SfTextInputLayout.Triggers><DataTrigger TargetType="inputLayout:SfTextInputLayout"Binding="{Binding Source={x:Reference entry},Path=Text.Length}"Value="0"><Setter Property="ErrorText" Value="*Required" /><Setter Property="HasError" Value="True"/></DataTrigger></inputLayout:SfTextInputLayout.Triggers><Entry Text="John" x:Name="entry" /></inputLayout:SfTextInputLayout>Sample Link: https://www.syncfusion.com/downloads/support/forum/154890/ze/IsRequired_Update1278177557
To know more about this, please refer below UG documentsRegards,
Hemalatha M.
StackLayout stackLayout = new StackLayout();
Entry entry = new Entry() { Text = "John" };
SfTextInputLayout sfTextInputLayout = new SfTextInputLayout()
{
ErrorColor = Color.Red,
Hint = "Name",
InputView = entry,
EnablePasswordVisibilityToggle = true,
Triggers =
{
new DataTrigger(typeof(SfTextInputLayout))
{
Binding = new Binding()
{
Source = entry,
Path = "Text.Length"
},
Value = 0,
Setters =
{
new Setter(){Property = SfTextInputLayout.ErrorTextProperty,Value = "*Required"},
new Setter(){Property = SfTextInputLayout.HasErrorProperty,Value = true},
}
}
},
};
stackLayout.Children.Add(sfTextInputLayout);
this.Content = stackLayout; |
Hi Tayyip Emre ÖRNEK,Thanks for your update.Please find the c# code of the same implementation in below
StackLayout stackLayout = new StackLayout();Entry entry = new Entry() { Text = "John" };SfTextInputLayout sfTextInputLayout = new SfTextInputLayout(){ErrorColor = Color.Red,Hint = "Name",InputView = entry,EnablePasswordVisibilityToggle = true,Triggers ={new DataTrigger(typeof(SfTextInputLayout)){Binding = new Binding(){Source = entry,Path = "Text.Length"},Value = 0,Setters ={new Setter(){Property = SfTextInputLayout.ErrorTextProperty,Value = "*Required"},new Setter(){Property = SfTextInputLayout.HasErrorProperty,Value = true},}}},};stackLayout.Children.Add(sfTextInputLayout);this.Content = stackLayout;Please let us know if you need any further assistance.Regards,
Hemalatha M.
SfTextInputLayout sfTextInputLayout = new SfTextInputLayout()
{
ErrorColor = Color.Red,
Hint = "Name",
InputView = entry,
EnablePasswordVisibilityToggle = true,
Triggers =
{
new DataTrigger(typeof(SfTextInputLayout))
{
Binding = new Binding()
{
Source = entry,
Path = "Text.Length",
Converter = new TextToPopup(),
ConverterParameter = this
},
Value = 0,
Setters =
{
new Setter(){Property = SfTextInputLayout.ErrorTextProperty,Value = "*Required"},
new Setter(){Property = SfTextInputLayout.HasErrorProperty,Value = true},
}
}
},
}; |
private bool isShow;
public bool IsShow
{
get { return isShow; }
set
{
isShow = value;
if(IsShow)
{
DisplayAlert("Error", "Please enter valid name", "OK");
}
OnPropertyChanged("IsShow");
}
}
.. |
public class TextToPopup : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(parameter is MainPage)
{
MainPage page = parameter as MainPage;
page.IsShow = (int)value == 0;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
|