<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments for hardcodet.net</title>
	<link>http://www.hardcodet.net</link>
	<description>code for fame, not fortune</description>
	<pubDate>Tue, 07 Oct 2008 13:23:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>Comment on A WPF File Selection control by Lee Oades</title>
		<link>http://www.hardcodet.net/2008/03/wpf-file-selection-control#comment-142</link>
		<dc:creator>Lee Oades</dc:creator>
		<pubDate>Thu, 25 Sep 2008 15:43:12 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/03/wpf-file-selection-control#comment-142</guid>
		<description>I would suspect it's suffering from the symptons discussed here:
http://www.kirupa.com/net/using_open_file_dialog_pg4.htm</description>
		<content:encoded><![CDATA[<p>I would suspect it&#8217;s suffering from the symptons discussed here:<br />
<a href="http://www.kirupa.com/net/using_open_file_dialog_pg4.htm" rel="nofollow" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.kirupa.com');">http://www.kirupa.com/net/using_open_file_dialog_pg4.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Explicitly update binding sources by Gary DeReese</title>
		<link>http://www.hardcodet.net/2008/01/update-explicit-data-binding#comment-138</link>
		<dc:creator>Gary DeReese</dc:creator>
		<pubDate>Thu, 11 Sep 2008 23:41:59 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/update-explicit-data-binding#comment-138</guid>
		<description>Good post!  I was having this exact issue and your solution seems to work just fine for me.</description>
		<content:encoded><![CDATA[<p>Good post!  I was having this exact issue and your solution seems to work just fine for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loaded event of a WPF control may be fired repeatedly by andre</title>
		<link>http://www.hardcodet.net/2008/01/wpf-loaded-event-fired-repeatedly#comment-136</link>
		<dc:creator>andre</dc:creator>
		<pubDate>Wed, 03 Sep 2008 13:38:05 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/wpf-loaded-event-fired-repeatedly#comment-136</guid>
		<description>herbert, but what is about loaded content in tabs of TabControl if  you didn't click on them. They won't be loaded. Your approach don't work.</description>
		<content:encoded><![CDATA[<p>herbert, but what is about loaded content in tabs of TabControl if  you didn&#8217;t click on them. They won&#8217;t be loaded. Your approach don&#8217;t work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on A KeyedCollection for int keys by Jaimir Guerrero</title>
		<link>http://www.hardcodet.net/2008/03/numericallykeyedcollection#comment-130</link>
		<dc:creator>Jaimir Guerrero</dc:creator>
		<pubDate>Tue, 12 Aug 2008 22:39:50 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/03/numericallykeyedcollection#comment-130</guid>
		<description>Thanks!!

This is my finall version.

    /// 
    /// Clase base para las colecciones de entidades de negocio
    /// 
    /// &lt;code&gt;
    /// *-----------------------------------------------------------------------------------------*
    /// * Copyright (C) 2008 CNT Sistemas de Información S.A., Todos los Derechos Reservados
    /// * http://www.cnt.com.co - mailto:produccion_panacea@cnt.com.co
    /// *
    /// * Archivo:      EntidadesCollection.cs
    /// * Tipo:         Entidad de Negocio
    /// * Autor:        Jaimir Guerrero
    /// * Fecha:        2008 Jun 03
    /// * Propósito:    Clase base para las colecciones de entidades de negocio
    /// *-----------------------------------------------------------------------------------------*
    /// &lt;/code&gt;
    [DataContract()]
    public class EntidadesCollection : KeyedCollection, IEntidadesCollection
        where TLlave : IComparable
        where TEntidad : EntidadBase, new()
    {
        #region Variable
        private long ultimo;
        private bool asiganar;
        #endregion

        #region Constructor / Destructor
        /// 
        /// Constructor por defecto
        /// 
        public EntidadesCollection()
            : base()
        {
            VerificarUltimo();
        }
        /// 
        /// Constructor para relacionar entidades de detalle con su entidad Padre.
        /// 
        /// 
        public EntidadesCollection(EntidadBase padre)
            : base()
        {
            this.Padre = padre;
            VerificarUltimo();
        }

        /// 
        /// Destructor de la clase
        /// 
        ~EntidadesCollection()
        {
            Dispose(false);
        }
        /// 
        /// Destructor de la clase
        /// 
        public void Dispose()
        {
            Dispose(true);
        }
        /// 
        /// Destructor para la herencia
        /// 
        /// Llamado por el destructor por defecto
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
            }
        }
        #endregion

        #region Propiedades
        /// 
        /// Lista de llaves contenidad en la colección
        /// 
        public ICollection Keys
        {
            get { return base.Dictionary.Keys; }
        }
        /// 
        /// Lista de entidades contenidas en la colección
        /// 
        public ICollection Values
        {
            get { return base.Dictionary.Values; }
        }
        /// 
        /// Sí la colección es de sólo lectura
        /// 
        public bool IsReadOnly
        {
            get { return false; }
        }
        /// 
        /// Retorna una colección con las entidades que estan marcadas como: modificados, borrados ó creados
        /// 
        public EntidadesCollection EntidadesCambiadas
        {
            get
            {
                var res = from c in this
                          where c.EstadoRegistro != EstadosEntidad.Original
                          select c;

                return this.InstanciarColeccionTipo(res);
            }
        }
        /// 
        /// Retorna verdero si alguna de los elementos de la colección es diferete a "Original"
        /// 
        public bool TieneCambios
        {
            get
            {
                return (this.Count(enti =&#62; enti.EstadoRegistro != EstadosEntidad.Original) &#62; 0);
            }
        }
        /// 
        /// Retorna todas las entidades excepto las marcadas como Borrados
        /// 
        public EntidadesCollection EntidadesActuales
        {
            get
            {
                var res = from c in this
                          where c.EstadoRegistro != EstadosEntidad.Borrado
                          select c;

                return this.InstanciarColeccionTipo(res);
            }
        }
        internal EntidadBase Padre { get; set; }
        #endregion

        #region Metodos
        /// 
        /// Devuelve la cantidad de entidades que se encuentran en un estado específico
        /// 
        /// Estado de la entidad
        /// 
        public int CantidadEstado(EstadosEntidad estadosEntidad)
        {
            return this.Count(enti =&#62; enti.EstadoRegistro == estadosEntidad);
        }
        /// 
        /// Adiciona un elemento a la colección
        /// 
        /// Identificador de la nueva entidad
        /// Entidad para adicionar
        public virtual TEntidad Add(TLlave key, TEntidad item)
        {
            item.Padre = this.Padre;
            base.Add(item);
            return item;
        }
        /// 
        /// Intenta traer el valor asociado a una llave.  sí la llave no existe no se genera error
        /// 
        /// Llave para buscar
        /// Entidad donde se asignará el valor encontrado
        /// 
        public bool TryGetValue(TLlave key, out TEntidad item)
        {
            return base.Dictionary.TryGetValue(key, out item);
        }
        /// 
        /// Intenta Traer una entidad por su llave.
        /// 
        /// La llave que se utilzó para asociar la entidad
        /// The matching item, if any. Otherwise default(T) (null in case of standard objects).
        public TEntidad TryGetByKey(TLlave key)
        {
            return Contains(key) ? GetByKey(key) : default(TEntidad);
        }
        /// 
        /// Overrides the default implementation in order to provide a more sophisticated
        /// exception handling. In case of an invalid ID, an exception with a message is
        /// being thrown that is built the  method.
        /// 
        /// The item with the matching key.
        /// Thrown if no descriptor
        /// with a matching ID was found.
        public TEntidad GetByKey(TLlave key)
        {
            TEntidad retorno;
            if (TryGetValue(key, out retorno))
                return retorno;
            else
            {
                string msg = GetKeyNotFoundMessage(key);
                throw new KeyNotFoundException(GetKeyNotFoundMessage(key));
            }
        }
        /// 
        /// Overrides the default implementation in order disable usage of the indexer,
        /// as its usage is no longer clear because index and item keys are both of
        /// the same type.
        /// Invoking this indexer always results in a .
        /// 
        /// Nothing - invoking the indexer results in a .
        /// Thrown if the indexer is being invoked.
        public new virtual TEntidad this[TLlave key]
        {
            get
            {
                if (key.GetType().FullName == "System.Int32")
                {
                    string msg = "Using the indexer is disabled because both access through index and item key take the same type.";
                    msg += " Use the GetByKey or GetByIndex methods instead.";
                    throw new InvalidOperationException(msg);
                }
                else
                    return base[key];
            }
        }
        /// 
        /// Gets an exception message that is being submitted with
        /// the  which is thrown
        /// if the indexer was called with an unknown key.
        /// This template method might be overridden in order to provide
        /// a more specific message.
        /// 
        /// The submitted (and unknown) key.
        /// This default implementation returns an error
        /// message that contains the requested key.
        protected virtual string GetKeyNotFoundMessage(TLlave key)
        {
            return String.Format("No se econtró entidad para la llave‘{0}’.", key);
        }
        /// 
        /// Gets the item at the specified .
        /// 
        /// Index within the collection.
        /// The item at the specified index.
        /// 
        /// if not a valid index of the internal list.
        public virtual TEntidad GetByIndex(int index)
        {
            return Items[index];
        }
        /// 
        /// Adds an item to the end of the collection.
        /// 
        /// Item to be added to the collection.
        /// This override just provides a more sophisticated exception
        /// message.
        public new void Add(TEntidad item)
        {
            try
            {
                this.Add(item.Identificador, item);
            }
            catch (ArgumentException e)
            {
                TLlave key = item.Identificador;
                if (Contains(key))
                    throw new ArgumentException(String.Format("Una entidad con llave ‘{0}’ ya existe en la colección.", key), "item", e);
                else
                    throw;
            }
        }
        /// 
        /// Busca la llave para un Item
        /// 
        /// Item a buscar la llave
        /// 
        protected override TLlave GetKeyForItem(TEntidad item)
        {
            return item.Identificador;
        }
        /// 
        /// Colección de entidades que se encuntran en el estado especifico
        /// 
        /// Estado de la entidad
        /// 
        public EntidadesCollection ObtenerEstado(EstadosEntidad estadosEntidad)
        {
            var res = from c in this
                      where c.EstadoRegistro == estadosEntidad
                      select c;

            return this.InstanciarColeccionTipo(res);
        }
        /// 
        /// Importa un dicionario de items TEntidad a la colección
        /// 
        /// Diccionario con la información
        public void ImportarDiccionario(IDictionary diccionario)
        {
            //
            // Crear registros que no existen
            //
            var res = from dic in diccionario
                      join este in this on dic.Key equals este.Identificador into subres
                      from nuevo in subres.DefaultIfEmpty(new TEntidad() { Usuario = "xx" })
                      where nuevo.Usuario == "xx"
                      select dic;

            foreach (var item in res)
            {
                item.Value.Padre = this.Padre;
                base.Add(item.Value);
            }
            //
            // Pasar los registros existentes
            //
            res = from dic in diccionario
                  join este in this on dic.Key equals este.Identificador
                  select dic;
            //
            // Ojo  como linq me asegura que ya existe el registro no valido si el indexof
            //      Treae un numero valido.
            foreach (var item in res)
            {
                item.Value.Padre = this.Padre;
                base.Dictionary[item.Key] = item.Value;
            }

            VerificarUltimo();
        }
        /// 
        /// Adiciona los elementos de la colección de origen a la colección Actual
        /// 
        /// Colección origen de los datos
        public void Unir(EntidadesCollection coleccionOrigen)
        {
            this.ImportarDiccionario(coleccionOrigen.Dictionary);
        }
        /// 
        /// Crear un elemento de la colección relizando las validaciones de datos
        /// 
        /// Nuevo elemento para ingresar a la colección
        public void Crear(TEntidad item)
        {
            item.EstadoRegistro = EstadosEntidad.Creado;
            item.Padre = this.Padre;
            if (!item.Identificador.Equals(default(TLlave)))
                item.Identificador = this.SiguienteAsignacion();

            item.ValidarInformacion();
            this.Add(item);
        }
        /// 
        /// Modificar un elemento de la colección relizando las validaciones de datos
        /// 
        /// Elemento de la colección modificado
        public void Modificar(TEntidad item)
        {
            item.EstadoRegistro = EstadosEntidad.Modificado;
            item.ValidarInformacion();
            try
            {
                this.SetItem(IndexOf(item), item);
            }
            catch (Exception exError)
            {
                throw new ErrorException(string.Format("No se econtró el elemento [{0}] en la colección", item.Identificador), exError);
            }
        }
        /// 
        /// 
        /// 
        /// 
        public void Borrar(TLlave key)
        {
            try
            {
                if (this[key].EstadoRegistro == EstadosEntidad.Creado)
                    this.Remove(key);
                else
                    this[key].EstadoRegistro = EstadosEntidad.Borrado;
            }
            catch (Exception exError)
            {
                throw new ErrorException(string.Format("No se econtró el elemento [{0}] en la colección", key), exError);
            }
        }
        #endregion

        #region Funciones
        private void VerificarUltimo()
        {
            if (typeof(TLlave) != typeof(string) &#38;&#38; typeof(TLlave) != typeof(byte))
            {
                this.asiganar = true;
                this.ultimo = -1;

                if (this.Count &#62; 0)
                {
                    this.ultimo = this.Min(p =&#62; Convert.ToInt64(p.Identificador));
                    if (this.ultimo &#62; -1)
                        this.ultimo = -1;
                }
            }
        }
        private TLlave SiguienteAsignacion()
        {
            if (!this.asiganar) return default(TLlave);
            TLlave valor = default(TLlave);
            do
            {
                valor = (TLlave)Convert.ChangeType(this.ultimo--, typeof(TLlave));
            } while (this.Contains(valor));
            return valor;
        }
        private EntidadesCollection InstanciarColeccionTipo(IEnumerable res)
        {
            Type tipo = this.GetType();
            ConstructorInfo constructorInfo = tipo.GetConstructor(new Type[0]);
            EntidadesCollection retorno = constructorInfo.Invoke(new object[0]) as EntidadesCollection;
            if (retorno != null)
                retorno.ImportarDiccionario(res.ToDictionary(p =&#62; p.Identificador));

            return retorno;
        }
        #endregion
    }</description>
		<content:encoded><![CDATA[<p>Thanks!!</p>
<p>This is my finall version.</p>
<p>    ///<br />
    /// Clase base para las colecciones de entidades de negocio<br />
    ///<br />
    /// <code><br />
    /// *-----------------------------------------------------------------------------------------*<br />
    /// * Copyright (C) 2008 CNT Sistemas de Información S.A., Todos los Derechos Reservados<br />
    /// * <a href="http://www.cnt.com.co" rel="nofollow" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.cnt.com.co');">http://www.cnt.com.co</a> - mailto:produccion_panacea@cnt.com.co<br />
    /// *<br />
    /// * Archivo:      EntidadesCollection.cs<br />
    /// * Tipo:         Entidad de Negocio<br />
    /// * Autor:        Jaimir Guerrero<br />
    /// * Fecha:        2008 Jun 03<br />
    /// * Propósito:    Clase base para las colecciones de entidades de negocio<br />
    /// *&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;*<br />
    /// </code><br />
    [DataContract()]<br />
    public class EntidadesCollection : KeyedCollection, IEntidadesCollection<br />
        where TLlave : IComparable<br />
        where TEntidad : EntidadBase, new()<br />
    {<br />
        #region Variable<br />
        private long ultimo;<br />
        private bool asiganar;<br />
        #endregion</p>
<p>        #region Constructor / Destructor<br />
        ///<br />
        /// Constructor por defecto<br />
        ///<br />
        public EntidadesCollection()<br />
            : base()<br />
        {<br />
            VerificarUltimo();<br />
        }<br />
        ///<br />
        /// Constructor para relacionar entidades de detalle con su entidad Padre.<br />
        ///<br />
        ///<br />
        public EntidadesCollection(EntidadBase padre)<br />
            : base()<br />
        {<br />
            this.Padre = padre;<br />
            VerificarUltimo();<br />
        }</p>
<p>        ///<br />
        /// Destructor de la clase<br />
        ///<br />
        ~EntidadesCollection()<br />
        {<br />
            Dispose(false);<br />
        }<br />
        ///<br />
        /// Destructor de la clase<br />
        ///<br />
        public void Dispose()<br />
        {<br />
            Dispose(true);<br />
        }<br />
        ///<br />
        /// Destructor para la herencia<br />
        ///<br />
        /// Llamado por el destructor por defecto<br />
        protected virtual void Dispose(bool disposing)<br />
        {<br />
            if (disposing)<br />
            {<br />
            }<br />
        }<br />
        #endregion</p>
<p>        #region Propiedades<br />
        ///<br />
        /// Lista de llaves contenidad en la colección<br />
        ///<br />
        public ICollection Keys<br />
        {<br />
            get { return base.Dictionary.Keys; }<br />
        }<br />
        ///<br />
        /// Lista de entidades contenidas en la colección<br />
        ///<br />
        public ICollection Values<br />
        {<br />
            get { return base.Dictionary.Values; }<br />
        }<br />
        ///<br />
        /// Sí la colección es de sólo lectura<br />
        ///<br />
        public bool IsReadOnly<br />
        {<br />
            get { return false; }<br />
        }<br />
        ///<br />
        /// Retorna una colección con las entidades que estan marcadas como: modificados, borrados ó creados<br />
        ///<br />
        public EntidadesCollection EntidadesCambiadas<br />
        {<br />
            get<br />
            {<br />
                var res = from c in this<br />
                          where c.EstadoRegistro != EstadosEntidad.Original<br />
                          select c;</p>
<p>                return this.InstanciarColeccionTipo(res);<br />
            }<br />
        }<br />
        ///<br />
        /// Retorna verdero si alguna de los elementos de la colección es diferete a &#8220;Original&#8221;<br />
        ///<br />
        public bool TieneCambios<br />
        {<br />
            get<br />
            {<br />
                return (this.Count(enti =&gt; enti.EstadoRegistro != EstadosEntidad.Original) &gt; 0);<br />
            }<br />
        }<br />
        ///<br />
        /// Retorna todas las entidades excepto las marcadas como Borrados<br />
        ///<br />
        public EntidadesCollection EntidadesActuales<br />
        {<br />
            get<br />
            {<br />
                var res = from c in this<br />
                          where c.EstadoRegistro != EstadosEntidad.Borrado<br />
                          select c;</p>
<p>                return this.InstanciarColeccionTipo(res);<br />
            }<br />
        }<br />
        internal EntidadBase Padre { get; set; }<br />
        #endregion</p>
<p>        #region Metodos<br />
        ///<br />
        /// Devuelve la cantidad de entidades que se encuentran en un estado específico<br />
        ///<br />
        /// Estado de la entidad<br />
        ///<br />
        public int CantidadEstado(EstadosEntidad estadosEntidad)<br />
        {<br />
            return this.Count(enti =&gt; enti.EstadoRegistro == estadosEntidad);<br />
        }<br />
        ///<br />
        /// Adiciona un elemento a la colección<br />
        ///<br />
        /// Identificador de la nueva entidad<br />
        /// Entidad para adicionar<br />
        public virtual TEntidad Add(TLlave key, TEntidad item)<br />
        {<br />
            item.Padre = this.Padre;<br />
            base.Add(item);<br />
            return item;<br />
        }<br />
        ///<br />
        /// Intenta traer el valor asociado a una llave.  sí la llave no existe no se genera error<br />
        ///<br />
        /// Llave para buscar<br />
        /// Entidad donde se asignará el valor encontrado<br />
        ///<br />
        public bool TryGetValue(TLlave key, out TEntidad item)<br />
        {<br />
            return base.Dictionary.TryGetValue(key, out item);<br />
        }<br />
        ///<br />
        /// Intenta Traer una entidad por su llave.<br />
        ///<br />
        /// La llave que se utilzó para asociar la entidad<br />
        /// The matching item, if any. Otherwise default(T) (null in case of standard objects).<br />
        public TEntidad TryGetByKey(TLlave key)<br />
        {<br />
            return Contains(key) ? GetByKey(key) : default(TEntidad);<br />
        }<br />
        ///<br />
        /// Overrides the default implementation in order to provide a more sophisticated<br />
        /// exception handling. In case of an invalid ID, an exception with a message is<br />
        /// being thrown that is built the  method.<br />
        ///<br />
        /// The item with the matching key.<br />
        /// Thrown if no descriptor<br />
        /// with a matching ID was found.<br />
        public TEntidad GetByKey(TLlave key)<br />
        {<br />
            TEntidad retorno;<br />
            if (TryGetValue(key, out retorno))<br />
                return retorno;<br />
            else<br />
            {<br />
                string msg = GetKeyNotFoundMessage(key);<br />
                throw new KeyNotFoundException(GetKeyNotFoundMessage(key));<br />
            }<br />
        }<br />
        ///<br />
        /// Overrides the default implementation in order disable usage of the indexer,<br />
        /// as its usage is no longer clear because index and item keys are both of<br />
        /// the same type.<br />
        /// Invoking this indexer always results in a .<br />
        ///<br />
        /// Nothing - invoking the indexer results in a .<br />
        /// Thrown if the indexer is being invoked.<br />
        public new virtual TEntidad this[TLlave key]<br />
        {<br />
            get<br />
            {<br />
                if (key.GetType().FullName == &#8220;System.Int32&#8243;)<br />
                {<br />
                    string msg = &#8220;Using the indexer is disabled because both access through index and item key take the same type.&#8221;;<br />
                    msg += &#8221; Use the GetByKey or GetByIndex methods instead.&#8221;;<br />
                    throw new InvalidOperationException(msg);<br />
                }<br />
                else<br />
                    return base[key];<br />
            }<br />
        }<br />
        ///<br />
        /// Gets an exception message that is being submitted with<br />
        /// the  which is thrown<br />
        /// if the indexer was called with an unknown key.<br />
        /// This template method might be overridden in order to provide<br />
        /// a more specific message.<br />
        ///<br />
        /// The submitted (and unknown) key.<br />
        /// This default implementation returns an error<br />
        /// message that contains the requested key.<br />
        protected virtual string GetKeyNotFoundMessage(TLlave key)<br />
        {<br />
            return String.Format(&#8221;No se econtró entidad para la llave‘{0}’.&#8221;, key);<br />
        }<br />
        ///<br />
        /// Gets the item at the specified .<br />
        ///<br />
        /// Index within the collection.<br />
        /// The item at the specified index.<br />
        ///<br />
        /// if not a valid index of the internal list.<br />
        public virtual TEntidad GetByIndex(int index)<br />
        {<br />
            return Items[index];<br />
        }<br />
        ///<br />
        /// Adds an item to the end of the collection.<br />
        ///<br />
        /// Item to be added to the collection.<br />
        /// This override just provides a more sophisticated exception<br />
        /// message.<br />
        public new void Add(TEntidad item)<br />
        {<br />
            try<br />
            {<br />
                this.Add(item.Identificador, item);<br />
            }<br />
            catch (ArgumentException e)<br />
            {<br />
                TLlave key = item.Identificador;<br />
                if (Contains(key))<br />
                    throw new ArgumentException(String.Format(&#8221;Una entidad con llave ‘{0}’ ya existe en la colección.&#8221;, key), &#8220;item&#8221;, e);<br />
                else<br />
                    throw;<br />
            }<br />
        }<br />
        ///<br />
        /// Busca la llave para un Item<br />
        ///<br />
        /// Item a buscar la llave<br />
        ///<br />
        protected override TLlave GetKeyForItem(TEntidad item)<br />
        {<br />
            return item.Identificador;<br />
        }<br />
        ///<br />
        /// Colección de entidades que se encuntran en el estado especifico<br />
        ///<br />
        /// Estado de la entidad<br />
        ///<br />
        public EntidadesCollection ObtenerEstado(EstadosEntidad estadosEntidad)<br />
        {<br />
            var res = from c in this<br />
                      where c.EstadoRegistro == estadosEntidad<br />
                      select c;</p>
<p>            return this.InstanciarColeccionTipo(res);<br />
        }<br />
        ///<br />
        /// Importa un dicionario de items TEntidad a la colección<br />
        ///<br />
        /// Diccionario con la información<br />
        public void ImportarDiccionario(IDictionary diccionario)<br />
        {<br />
            //<br />
            // Crear registros que no existen<br />
            //<br />
            var res = from dic in diccionario<br />
                      join este in this on dic.Key equals este.Identificador into subres<br />
                      from nuevo in subres.DefaultIfEmpty(new TEntidad() { Usuario = &#8220;xx&#8221; })<br />
                      where nuevo.Usuario == &#8220;xx&#8221;<br />
                      select dic;</p>
<p>            foreach (var item in res)<br />
            {<br />
                item.Value.Padre = this.Padre;<br />
                base.Add(item.Value);<br />
            }<br />
            //<br />
            // Pasar los registros existentes<br />
            //<br />
            res = from dic in diccionario<br />
                  join este in this on dic.Key equals este.Identificador<br />
                  select dic;<br />
            //<br />
            // Ojo  como linq me asegura que ya existe el registro no valido si el indexof<br />
            //      Treae un numero valido.<br />
            foreach (var item in res)<br />
            {<br />
                item.Value.Padre = this.Padre;<br />
                base.Dictionary[item.Key] = item.Value;<br />
            }</p>
<p>            VerificarUltimo();<br />
        }<br />
        ///<br />
        /// Adiciona los elementos de la colección de origen a la colección Actual<br />
        ///<br />
        /// Colección origen de los datos<br />
        public void Unir(EntidadesCollection coleccionOrigen)<br />
        {<br />
            this.ImportarDiccionario(coleccionOrigen.Dictionary);<br />
        }<br />
        ///<br />
        /// Crear un elemento de la colección relizando las validaciones de datos<br />
        ///<br />
        /// Nuevo elemento para ingresar a la colección<br />
        public void Crear(TEntidad item)<br />
        {<br />
            item.EstadoRegistro = EstadosEntidad.Creado;<br />
            item.Padre = this.Padre;<br />
            if (!item.Identificador.Equals(default(TLlave)))<br />
                item.Identificador = this.SiguienteAsignacion();</p>
<p>            item.ValidarInformacion();<br />
            this.Add(item);<br />
        }<br />
        ///<br />
        /// Modificar un elemento de la colección relizando las validaciones de datos<br />
        ///<br />
        /// Elemento de la colección modificado<br />
        public void Modificar(TEntidad item)<br />
        {<br />
            item.EstadoRegistro = EstadosEntidad.Modificado;<br />
            item.ValidarInformacion();<br />
            try<br />
            {<br />
                this.SetItem(IndexOf(item), item);<br />
            }<br />
            catch (Exception exError)<br />
            {<br />
                throw new ErrorException(string.Format(&#8221;No se econtró el elemento [{0}] en la colección&#8221;, item.Identificador), exError);<br />
            }<br />
        }<br />
        ///<br />
        ///<br />
        ///<br />
        ///<br />
        public void Borrar(TLlave key)<br />
        {<br />
            try<br />
            {<br />
                if (this[key].EstadoRegistro == EstadosEntidad.Creado)<br />
                    this.Remove(key);<br />
                else<br />
                    this[key].EstadoRegistro = EstadosEntidad.Borrado;<br />
            }<br />
            catch (Exception exError)<br />
            {<br />
                throw new ErrorException(string.Format(&#8221;No se econtró el elemento [{0}] en la colección&#8221;, key), exError);<br />
            }<br />
        }<br />
        #endregion</p>
<p>        #region Funciones<br />
        private void VerificarUltimo()<br />
        {<br />
            if (typeof(TLlave) != typeof(string) &amp;&amp; typeof(TLlave) != typeof(byte))<br />
            {<br />
                this.asiganar = true;<br />
                this.ultimo = -1;</p>
<p>                if (this.Count &gt; 0)<br />
                {<br />
                    this.ultimo = this.Min(p =&gt; Convert.ToInt64(p.Identificador));<br />
                    if (this.ultimo &gt; -1)<br />
                        this.ultimo = -1;<br />
                }<br />
            }<br />
        }<br />
        private TLlave SiguienteAsignacion()<br />
        {<br />
            if (!this.asiganar) return default(TLlave);<br />
            TLlave valor = default(TLlave);<br />
            do<br />
            {<br />
                valor = (TLlave)Convert.ChangeType(this.ultimo&#8211;, typeof(TLlave));<br />
            } while (this.Contains(valor));<br />
            return valor;<br />
        }<br />
        private EntidadesCollection InstanciarColeccionTipo(IEnumerable res)<br />
        {<br />
            Type tipo = this.GetType();<br />
            ConstructorInfo constructorInfo = tipo.GetConstructor(new Type[0]);<br />
            EntidadesCollection retorno = constructorInfo.Invoke(new object[0]) as EntidadesCollection;<br />
            if (retorno != null)<br />
                retorno.ImportarDiccionario(res.ToDictionary(p =&gt; p.Identificador));</p>
<p>            return retorno;<br />
        }<br />
        #endregion<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loaded event of a WPF control may be fired repeatedly by herbert</title>
		<link>http://www.hardcodet.net/2008/01/wpf-loaded-event-fired-repeatedly#comment-128</link>
		<dc:creator>herbert</dc:creator>
		<pubDate>Mon, 04 Aug 2008 03:12:43 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/wpf-loaded-event-fired-repeatedly#comment-128</guid>
		<description>Hi,
I meet the same problem, and I think it was because  that the Tabcontrol will remove the content of current TabItem from the visual tree  and add the content of the selected TabItem to the visual tree when you switch Tabs. Then as the visual tree updated, there will be loaded and unloaded event fired for the newly added control and removed control respectively.
I solved this problem by write a new tab control, which added all the items to the visual tree at the very beginning, and just make it hiden when the item was unselected, make it visible when the item was selected. This accelerate the switch speed a lot, especialy when the TabItem's content is complex.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I meet the same problem, and I think it was because  that the Tabcontrol will remove the content of current TabItem from the visual tree  and add the content of the selected TabItem to the visual tree when you switch Tabs. Then as the visual tree updated, there will be loaded and unloaded event fired for the newly added control and removed control respectively.<br />
I solved this problem by write a new tab control, which added all the items to the visual tree at the very beginning, and just make it hiden when the item was unselected, make it visible when the item was selected. This accelerate the switch speed a lot, especialy when the TabItem&#8217;s content is complex.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on A versatile WPF TreeView control by Justin</title>
		<link>http://www.hardcodet.net/2008/01/wpf-treeview#comment-126</link>
		<dc:creator>Justin</dc:creator>
		<pubDate>Tue, 22 Jul 2008 17:10:01 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/wpf-treeview#comment-126</guid>
		<description>Great control.  Good work on implementing a very usable set of features.  To answer Walt's question about TreeResources.xaml breaking: I changed the Assembly Name (in project properties) to remove the space, assuming XAML doesn't like spaces.  I then rebuilt the project and re-created the "shop" namespace reference in TreeResources.xaml.  You may also be able to just remove the ";assembly=" from the end of the shop namespace declaration.

Justin</description>
		<content:encoded><![CDATA[<p>Great control.  Good work on implementing a very usable set of features.  To answer Walt&#8217;s question about TreeResources.xaml breaking: I changed the Assembly Name (in project properties) to remove the space, assuming XAML doesn&#8217;t like spaces.  I then rebuilt the project and re-created the &#8220;shop&#8221; namespace reference in TreeResources.xaml.  You may also be able to just remove the &#8220;;assembly=&#8221; from the end of the shop namespace declaration.</p>
<p>Justin</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Finding an ancestor of a WPF dependency object by Adrian</title>
		<link>http://www.hardcodet.net/2008/02/find-wpf-parent#comment-125</link>
		<dc:creator>Adrian</dc:creator>
		<pubDate>Wed, 16 Jul 2008 09:24:55 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/02/find-wpf-parent#comment-125</guid>
		<description>Thank you for this contribution.  May I suggest, though, that you name your method something other than TryFindParent?  As stated in your blog entry's title, the method is for locating an ancestor, not just for getting the parent.  Also I think "Try" is unnecessary since that would mean the name of every method that may return null should be prefixed with "Try" which is no one's standard.  So simply "FindAncestor" seems like a good name in my opinion.</description>
		<content:encoded><![CDATA[<p>Thank you for this contribution.  May I suggest, though, that you name your method something other than TryFindParent?  As stated in your blog entry&#8217;s title, the method is for locating an ancestor, not just for getting the parent.  Also I think &#8220;Try&#8221; is unnecessary since that would mean the name of every method that may return null should be prefixed with &#8220;Try&#8221; which is no one&#8217;s standard.  So simply &#8220;FindAncestor&#8221; seems like a good name in my opinion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Explicitly update binding sources by Stefan Olson</title>
		<link>http://www.hardcodet.net/2008/01/update-explicit-data-binding#comment-119</link>
		<dc:creator>Stefan Olson</dc:creator>
		<pubDate>Sat, 28 Jun 2008 07:14:55 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/update-explicit-data-binding#comment-119</guid>
		<description>I've updated your code so you don't need to pass DependencyProperty[] properties.

&lt;pre&gt;public static class DialogHelper
    {
        /// 
        /// Recursively processes a given dependency object and all its
        /// children, and updates sources of all objects that use a
        /// binding expression on a given property.
        /// 
        /// The dependency object that marks a starting
        /// point. This could be a dialog window or a panel control that
        /// hosts bound controls.
        /// The properties to be updated if
        ///  or one of its childs provide it along
        /// with a binding expression.
        public static void UpdateBindingSources( DependencyObject obj)
        {
            IEnumerable props = obj.EnumerateDependencyProperties();
            foreach (DependencyProperty p in props)
            {
                Binding b = BindingOperations.GetBinding(obj, p);
                if (b.UpdateSourceTrigger == UpdateSourceTrigger.Explicit)
                {
                    //check whether the submitted object provides a bound property
                    //that matches the property parameters
                    BindingExpression be =
                      BindingOperations.GetBindingExpression(obj, p);
                    if (be != null) be.UpdateSource();
                }
            }

            int count = VisualTreeHelper.GetChildrenCount(obj);
            for (int i = 0; i &#60; count; i++)
            {
                //process child items recursively
                DependencyObject childObject = VisualTreeHelper.GetChild(obj, i);
                UpdateBindingSources(childObject);
            }
        }

        public static void UpdateAllSources(this Control w)
        {
            UpdateBindingSources(w);
        }
}

public static class DependencyObjectExtensions
    {
       public static IEnumerable EnumerateDependencyProperties(this DependencyObject element)
        {
            LocalValueEnumerator lve = element.GetLocalValueEnumerator();

            while (lve.MoveNext())
            {
                LocalValueEntry entry = lve.Current;
                 if (BindingOperations.IsDataBound(element, entry.Property))
                {
                    yield return entry.Property;
                }
            }
        }

    }&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;ve updated your code so you don&#8217;t need to pass DependencyProperty[] properties.</p>
<pre>public static class DialogHelper
    {
        ///
        /// Recursively processes a given dependency object and all its
        /// children, and updates sources of all objects that use a
        /// binding expression on a given property.
        ///
        /// The dependency object that marks a starting
        /// point. This could be a dialog window or a panel control that
        /// hosts bound controls.
        /// The properties to be updated if
        ///  or one of its childs provide it along
        /// with a binding expression.
        public static void UpdateBindingSources( DependencyObject obj)
        {
            IEnumerable props = obj.EnumerateDependencyProperties();
            foreach (DependencyProperty p in props)
            {
                Binding b = BindingOperations.GetBinding(obj, p);
                if (b.UpdateSourceTrigger == UpdateSourceTrigger.Explicit)
                {
                    //check whether the submitted object provides a bound property
                    //that matches the property parameters
                    BindingExpression be =
                      BindingOperations.GetBindingExpression(obj, p);
                    if (be != null) be.UpdateSource();
                }
            }

            int count = VisualTreeHelper.GetChildrenCount(obj);
            for (int i = 0; i &lt; count; i++)
            {
                //process child items recursively
                DependencyObject childObject = VisualTreeHelper.GetChild(obj, i);
                UpdateBindingSources(childObject);
            }
        }

        public static void UpdateAllSources(this Control w)
        {
            UpdateBindingSources(w);
        }
}

public static class DependencyObjectExtensions
    {
       public static IEnumerable EnumerateDependencyProperties(this DependencyObject element)
        {
            LocalValueEnumerator lve = element.GetLocalValueEnumerator();

            while (lve.MoveNext())
            {
                LocalValueEntry entry = lve.Current;
                 if (BindingOperations.IsDataBound(element, entry.Property))
                {
                    yield return entry.Property;
                }
            }
        }

    }</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on A base class for custom WPF binding markup extensions by WiredPrairie - WPF Binding Expression Alternatives</title>
		<link>http://www.hardcodet.net/2008/04/wpf-custom-binding-class#comment-104</link>
		<dc:creator>WiredPrairie - WPF Binding Expression Alternatives</dc:creator>
		<pubDate>Tue, 13 May 2008 13:16:15 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/04/wpf-custom-binding-class#comment-104</guid>
		<description>[...] A base class for custom WPF binding markup extensions [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] A base class for custom WPF binding markup extensions [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multithreaded WPF Progress Dialog by Chris P</title>
		<link>http://www.hardcodet.net/2008/01/wpf-progress-dialog#comment-103</link>
		<dc:creator>Chris P</dc:creator>
		<pubDate>Sun, 11 May 2008 13:55:07 +0000</pubDate>
		<guid>http://www.hardcodet.net/2008/01/wpf-progress-dialog#comment-103</guid>
		<description>Great Stuff! I've already incorporated your ideas and its working great! Thanks a lot.</description>
		<content:encoded><![CDATA[<p>Great Stuff! I&#8217;ve already incorporated your ideas and its working great! Thanks a lot.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
