﻿<?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 - ClientUI - Problem with validation</title><link>http://www.intersoftsolutions.com/Community/ClientUI/Problem-with-validation/</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>Problem with validation</title><link>http://www.intersoftsolutions.com/Community/ClientUI/Problem-with-validation/</link><pubDate>Wed, 05 Oct 2011 21:18:58 GMT</pubDate><dc:creator>yudi</dc:creator><category>clientui silverlight validation</category><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;Glad to hear the good news.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;Should you need further assistance or run into any problems regarding our controls, feel free to post it into our forum. We would be happy to assist you again.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Problem with validation</title><link>http://www.intersoftsolutions.com/Community/ClientUI/Problem-with-validation/</link><pubDate>Wed, 05 Oct 2011 07:16:42 GMT</pubDate><dc:creator>georgiosd</dc:creator><category>clientui silverlight validation</category><description>&lt;p&gt;Yudi,&lt;/p&gt;&lt;p&gt;I have seen the code you're referring to in one of your samples.&lt;/p&gt;
&lt;p&gt;However, it's largely irrelevant - I am using the Entity Framework for persistence as I've indiciated in my original post. &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;The true example of how to do validation is in the ClientUI SL Business App with RIA SP1 template.&lt;/p&gt;
&lt;p&gt;I finally figured out that it wasn't working because I hadn't assigned an error string in my validation attribute - it should have a default one but well, it doesn't.&lt;/p&gt;
&lt;p&gt;Georgios&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Problem with validation</title><link>http://www.intersoftsolutions.com/Community/ClientUI/Problem-with-validation/</link><pubDate>Wed, 05 Oct 2011 03:18:15 GMT</pubDate><dc:creator>yudi</dc:creator><category>clientui silverlight validation</category><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Following is the list that needs to be added in order to perform validation:&lt;/span&gt;&lt;/p&gt;
&lt;ol style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;&lt;li&gt;After create model class, for example: SomeModel.cs, add EnableValidation property to SomeModel model.&lt;br /&gt;Example:&lt;pre&gt;public bool EnableValidation { get; set; }&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Add the validation condition for the properties of SomeModel model.&lt;br /&gt;Example:&lt;pre&gt;public double Price
{
    get
    {
        return _price;
    }
    set
    {
        if (_price != value)
        {
            _price = value;
            ClearError("Price");

            if (EnableValidation &amp;amp;&amp;amp; double.IsNaN(this.Price) || this.Price == 0.0)
                SetError("Price", "Price is required");

            OnPropertyChanged("Price");
        }
    }
}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;After create the view, for example: SomeView.xaml, create ValidationViewModelBase class that inherits from ViewModelBase and implements IDataErrorInfo interface.&lt;pre&gt;using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ValidationOnTextInput.ViewModels
{
    public class ValidationViewModelBase : ViewModelBase, IDataErrorInfo
    {
        #region Properties

        private Dictionary&amp;lt;string, string&amp;gt; _errors = new Dictionary&amp;lt;string, string&amp;gt;();

        public virtual bool HasErrors
        {
            get
            {
                return _errors.Count &amp;gt; 0;
            }
        }

        #endregion

        #region Public

        public void SetError(string propertyName, string errorMessage)
        {
            _errors[propertyName] = errorMessage;
            this.OnPropertyChanged(propertyName);
        }

        #endregion

        #region Protected

        protected void ClearError(string propertyName)
        {
            this._errors.Remove(propertyName);
        }

        protected void ClearAllErrors()
        {
            List&amp;lt;string&amp;gt; properties = new List&amp;lt;string&amp;gt;();

            foreach (KeyValuePair&amp;lt;string, string&amp;gt; error in this._errors)
                properties.Add(error.Key);

            this._errors.Clear();

            foreach (string property in properties)
                this.OnPropertyChanged(property);
        }

        #endregion

        #region IDataErrorInfo Members

        public string Error
        {
            get
            {
                if (this.HasErrors)
                    return this._errors.First().Value;

                return null;
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (this._errors.ContainsKey(columnName))
                {
                    return this._errors[columnName];
                }
                return string.Empty;
            }
        }

        #endregion
    }
}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Create view model, for example: SomeViewModel.cs, which inherits from ValidationViewModelBase class.&lt;br /&gt;Example:&lt;pre&gt;using [ProjectName].Models;

namespace [ProjectName].ViewModels
{
    public class SomeViewModel : ValidationViewModelBase
    {
        // Constructor
        public SomeViewModel()
        {
            
        }
    }
}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Binding the View to ViewModel, in this case is SomeView to SomeViewModel. This step includes: set ValidationOnDataErrors to True in the binding definition; set Intersoft:DataBinding.ClearErrorOnTextInput to True in order to have the error alert to disappear directly when user type into the textbox.&lt;br /&gt;Example:&lt;pre&gt;&amp;lt;Intersoft:UXTextBox HorizontalAlignment="Center" Width="60"
                        Text="{Binding Book.Price, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, StringFormat=\{0:c\}}"
                        Intersoft:DataBinding.ClearErrorOnTextInput="True"/&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;I enclosed a working simple sample of Model; ViewModel; and View for reference as attachment.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Problem with validation</title><link>http://www.intersoftsolutions.com/Community/ClientUI/Problem-with-validation/</link><pubDate>Tue, 04 Oct 2011 05:41:45 GMT</pubDate><dc:creator>georgiosd</dc:creator><category>clientui silverlight validation</category><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;I’m having trouble getting a UXTextBox to show validation errors with the red outline and default call out&lt;br /&gt;&lt;br /&gt;I have an entity on the server side (using EF 4.1 Code First)&lt;br /&gt;&lt;br /&gt;class WebAccess&lt;br /&gt;{&lt;br /&gt;[Email]&lt;br /&gt; public string Email { get; set; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class User&lt;br /&gt;{&lt;br /&gt;// this one is required by default because it’s a complex type&lt;br /&gt;public WebAccess WebAccess { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;EmailAttribute is a custom validation attribute. I’ve validated it works and that it gets copied over to the server.&lt;br /&gt;&lt;br /&gt;In the view, I set the DataContext:&lt;br /&gt;&lt;br /&gt;&amp;lt;ui:UXPage.DataContext&amp;gt;&lt;br /&gt; &amp;lt;ViewModels:SuperAdministratorViewModel /&amp;gt;&lt;br /&gt; &amp;lt;/ui:UXPage.DataContext&amp;gt;&lt;br /&gt;&lt;br /&gt;And then:&lt;br /&gt;&lt;br /&gt;&amp;lt;ui:UXItemsControl DataContext="{Binding NewAdministrator}" ItemContainerStyle="{StaticResource FieldLabelStyle}"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;ui:FieldLabel Header="Email" Style="{StaticResource RequiredFieldLabelStyle}"&amp;gt;&lt;br /&gt; &amp;lt;ui:UXTextBox Style="{StaticResource SimpleTextBoxStyle}" &lt;br /&gt; Text="{Binding Path=WebAccess.Email, Mode=TwoWay, ValidatesOnDataErrors=True}" &lt;br /&gt; ui:DataBinding.ClearErrorOnTextInput="True" /&amp;gt;&lt;br /&gt; &amp;lt;/ui:FieldLabel&amp;gt; &lt;br /&gt;&amp;lt;/ui:UXItemsControl&amp;gt;&lt;br /&gt;&lt;br /&gt;However, when I type and move the focus to another control, the validation won’t show at all&lt;br /&gt;&lt;br /&gt;What am I missing here?&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;Georgios&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>