﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - How to format textfield</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-format-textfield/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to format textfield</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-format-textfield/</link><pubDate>Mon, 19 Sep 2016 07:28:55 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Sorry for the delay in sending this.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;I created a simple Crosslight (Android) project which emulate the &lt;em&gt;Email validator behavior&lt;/em&gt;. Following steps shows the detail:&lt;/span&gt;&lt;/p&gt;
&lt;ol style="color: #1f497d;"&gt;&lt;li&gt;open Visual Studio and select &lt;strong&gt;New&lt;/strong&gt;, &lt;strong&gt;Project&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;From the dialog that appears, choose &lt;strong&gt;Visual C#&lt;/strong&gt;, &lt;strong&gt;Intersoft Solutions&lt;/strong&gt;, &lt;strong&gt;Mobile&lt;/strong&gt;, then select &lt;strong&gt;Intersoft Crosslight Application (iOS, Android, Windows)&lt;/strong&gt;. Enter other necessary information such as &lt;strong&gt;Name&lt;/strong&gt;, &lt;strong&gt;Location&lt;/strong&gt; and &lt;strong&gt;Solution Name&lt;/strong&gt;.&lt;br&gt;&lt;img src="http://developer.intersoftsolutions.com/download/attachments/23045451/Screen%20Shot%202016-02-26%20at%2010.28.47%20AM.png" style="width: 519px; height: 368px;"&gt;&lt;/li&gt;&lt;li&gt;Create a Crosslight Blank solution, by choosing Blank from the drop down and hit OK.&lt;br&gt;&lt;img src="http://developer.intersoftsolutions.com/download/attachments/23045451/2016-02-27_22-26-13.png" style="width: 519px; height: 368px;"&gt;&lt;/li&gt;&lt;li&gt;Once the project is created, open SimpleViewModel.cs located inside the [Project Name].Core project.&lt;/li&gt;&lt;li&gt;Locate &lt;strong&gt;NewText&lt;/strong&gt; property inside the SimpleViewModel class and replace the entire code as follows:&lt;br&gt;&lt;pre&gt;public string NewText
{
    get { return _newText; }
    set
    {
        if (_newText != value)
        {
            _newText = value;

            const string emailRegex = @"^(?("")("".+?(?&amp;lt;!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&amp;amp;'\*\+/=\?\^`\{\}\|~\w])*)(?&amp;lt;=[0-9a-z])@))" +
                @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$";

            var IsValid = (Regex.IsMatch(_newText, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));

            if (IsValid)
                GreetingText = "Your email looks good";
            else
                GreetingText = "Enter a valid email";

            OnPropertyChanged("NewText");
        }
    }
}&lt;/pre&gt;&lt;br&gt;In the setter of NewText, email validation is added. The email validation uses emailRegex string constant and IsMatch method. When IsValid expression returns true, GreetingText property will be set to "Your email looks good". Else, it will be set set to "Enter a valid email".&lt;/li&gt;&lt;li&gt;Add a folder in the [Project Name].Core project and named it as &lt;strong&gt;Converters&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;Add a class and named it as &lt;strong&gt;TextStyleConverter.cs&lt;/strong&gt; into the Converters folder.&lt;/li&gt;&lt;li&gt;Copy and replace the entire code of TextStyleConverter class as follows:&lt;br&gt;&lt;pre&gt;using Intersoft.Crosslight;
using Intersoft.Crosslight.Drawing;
using System;
using System.Globalization;

namespace EmailValidator.Converters
{
    public class TextStyleConverter : IValueConverter
    {
        #region IValueConverter implementation

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                var styles = new StyleAttributes();

                if (value.ToString() == "Your email looks good")
                    styles.ForegroundColor = Colors.Green;
                else
                    styles.ForegroundColor = Colors.Red;

                return styles;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}&lt;/pre&gt;&lt;br&gt;This converter sets ForegroundColor to green when email is valid and sets ForegroundColor to red when email is not valid.&lt;/li&gt;&lt;li&gt;Open &lt;strong&gt;SimpleBindingProvider.cs&lt;/strong&gt; located inside the &lt;strong&gt;[ProjectName].Core&lt;/strong&gt; project.&lt;/li&gt;&lt;li&gt;Add following snippet code into the constructor of SimpleBindingProvider class.&lt;br&gt;&lt;pre&gt;this.AddBinding("GreetingLabel", BindableProperties.StyleAttributesProperty, new BindingDescription("GreetingText")
{
    Converter = new TextStyleConverter()
});&lt;/pre&gt;&lt;br&gt;The code adds a binding provider which acts as the mediator that provides binding definitions to the interested parties such as view models and views. The &lt;em&gt;GreetingLabel&lt;/em&gt; is the view target contract; the &lt;em&gt;BindableProperties.StyleAttributesProperty&lt;/em&gt; is the target property to bind; and the rest is the binding description to the converter.&lt;/li&gt;&lt;li&gt;Save the changes and run the project.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;I enclosed the simple Android project (as attachment) for your reference. Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to format textfield</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-format-textfield/</link><pubDate>Fri, 09 Sep 2016 18:47:12 GMT</pubDate><dc:creator>gabriel</dc:creator><description>&lt;p&gt;&lt;span&gt;I would like to format a text field while the User enters the information.&lt;br&gt;Using xamarin.forms , I usa behavior , as explained in &lt;a href="https://blog.xamarin.com/behaviors-in-xamarin-forms/" target="_blank"&gt;https://blog.xamarin.com/behaviors-in-xamarin-forms/&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;How can I do with Crosslight&lt;/span&gt;&lt;/p&gt;</description></item></channel></rss>