<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5339728292405481239</id><updated>2012-02-16T11:20:02.522-08:00</updated><title type='text'>Le blog de Thibaud :-)</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thibaud60.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-2037931111871651441</id><published>2011-01-02T12:41:00.001-08:00</published><updated>2011-01-15T08:16:42.870-08:00</updated><title type='text'>SOS.DLL, object Address and Visual Studio debugger</title><content type='html'>&lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;When we search leak memory in our application, we use SOS.dll in Windbg.exe or Visual studio IDE.&lt;/p&gt;  &lt;p&gt;This tool is very very usefull but it is not easy to walk accross the references tree of object.&lt;/p&gt;  &lt;p&gt;Visual Studio is more powerfull to do that. “Quick watch window” for example with its property explorator is perfect.&lt;/p&gt;  &lt;p&gt;but “sos command’s” returns only addresses of objects …&lt;/p&gt;  &lt;h3&gt;Evaluate an object in VS from GCHandle address&lt;/h3&gt;  &lt;p&gt;!GCRoot give often this type of informations : &lt;/p&gt;  &lt;p&gt;!GCRoot -nostacks 00c58918    &lt;br /&gt;DOMAIN(0015DF20):HANDLE(Strong):&lt;font color="#ff0000"&gt;&lt;strong&gt;3011f8&lt;/strong&gt;&lt;/font&gt;:Root:00c21b30(System.Threading.Thread)-&amp;gt;     &lt;br /&gt;00c272b4(System.Object[][])-&amp;gt;     &lt;br /&gt;00c272c8(System.Object[])-&amp;gt;     &lt;br /&gt;00d0b0fc(System.Object[])-&amp;gt;     &lt;br /&gt;00d0b0dc(System.EventHandler)-&amp;gt;     &lt;br /&gt;... &lt;/p&gt;  &lt;p&gt;If you evaluate this in VS debugger : &lt;/p&gt;  &lt;p&gt;&lt;em&gt;System.Runtime.InteropServices.GCHandle.FromIntPtr(new IntPtr(&lt;strong&gt;&lt;font color="#ff0000"&gt;0x3011f8&lt;/font&gt;&lt;/strong&gt;)).Target&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;You found the instance of System.Threading.Thread (address 00c21b30) !!&lt;/p&gt;  &lt;h3&gt;Find address object in Quick watch windows …&lt;/h3&gt;  &lt;p&gt;It is possible to fix the memory area of an object with System.Runtime.InteropServices.GCHandle object. When you create a GCHandle on a object with GCHandleType.&lt;b&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Runtime.InteropServices.GCHandleType/Pinned"&gt;Pinned&lt;/a&gt;&lt;/b&gt; option. GCHandle.AddrOfPinnedObject() return the memory location of it !&lt;/p&gt;  &lt;p&gt;BUT it is possible to use internal method to give the current address of object even if this object is not pinned &lt;/p&gt;  &lt;p&gt;If you evaluate this, in “Quick Watch window” of VS, or in “Immediat window” :&lt;/p&gt;  &lt;p&gt;&lt;em&gt;? string.Format(&amp;quot;{0:x}&amp;quot;,int.Parse(System.Runtime.InteropServices.GCHandle.InternalAddrOfPinnedObject(System.Runtime.InteropServices.GCHandle.Alloc(&lt;strong&gt;&lt;font color="#ff0000"&gt;myObjectSomeWhere&lt;/font&gt;&lt;/strong&gt;).GetHandleValue()).ToString())-4)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The result give the same address of &lt;strong&gt;&lt;font color="#ff0000"&gt;myObjectSomeWhere&lt;/font&gt;&lt;/strong&gt; in&amp;#160; SOS commands Like &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;!DumpObj &lt;/li&gt;    &lt;li&gt;!GCRoot &lt;/li&gt;    &lt;li&gt;!DumpHeap &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you know where the object is in your application, you can find the address of it, and compare with SOS Commands results.&lt;/p&gt;  &lt;h3&gt;Evaluate object in VS from directly address&lt;/h3&gt;  &lt;p&gt;It would be very usefull to evaluate, for example, 00d0b0dc EventHandler instance in VS debugger !&lt;/p&gt;  &lt;p&gt;BUT I did not found a tips to do this … directly, sorry … :-(&lt;/p&gt;  &lt;p&gt;This reference &lt;a title="http://stackoverflow.com/questions/3141428/conversion-from-void-to-object-in-c" href="http://stackoverflow.com/questions/3141428/conversion-from-void-to-object-in-c"&gt;http://stackoverflow.com/questions/3141428/conversion-from-void-to-object-in-c&lt;/a&gt; asks the same question without answer …&lt;/p&gt;  &lt;p&gt;If I would find it, I will be able to update this post !    &lt;br /&gt;&lt;/p&gt;  &lt;h3&gt;References&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;Memory explanations about .Net Value and reference types : &lt;a href="http://www.codeproject.com/KB/cs/net_type_internals.aspx"&gt;http://www.codeproject.com/KB/cs/net_type_internals.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Explanations about GCHandle and differences between GCHandle.AddrOfPinnedObject et GCHandle.ToIntPtr : &lt;a href="http://blogs.msdn.com/b/jmstall/archive/2006/10/09/gchandle_5f00_intptr.aspx"&gt;http://blogs.msdn.com/b/jmstall/archive/2006/10/09/gchandle_5f00_intptr.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;SOS.DLL microsoft documentation : &lt;a title="http://msdn.microsoft.com/fr-fr/library/bb190764.aspx" href="http://msdn.microsoft.com/fr-fr/library/bb190764.aspx"&gt;http://msdn.microsoft.com/fr-fr/library/bb190764.aspx&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-2037931111871651441?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/2037931111871651441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/2037931111871651441'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2011/01/sosdll-object-address-and-visual-studio.html' title='SOS.DLL, object Address and Visual Studio debugger'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-6717033204482542851</id><published>2010-10-17T03:09:00.001-07:00</published><updated>2010-10-21T13:49:12.551-07:00</updated><title type='text'>Fast Property Accessor without dynamic IL</title><content type='html'>&lt;h3&gt;Abstract&lt;/h3&gt;  &lt;p&gt;I need to access property value on a object with Reflection API. It is very useful to create for example a generic Deep Clone API on POCO object.&lt;/p&gt;  &lt;p&gt;BUT : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Sometimes, Setter method of the object is not public. &lt;/li&gt;    &lt;li&gt;I need the very very high performance to do it. &lt;/li&gt;    &lt;li&gt;It seems the better way to do is Deletage.CreateDelegate method but it is important to use Invoke() method on it. DynamicMethod is very poor performance approach. &lt;/li&gt;    &lt;li&gt;I don’t want use IL approach because it is too hard to develop and maintains. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I propose helper based PropertyInfo, which support the interface IPropertyAccessor. This interface has a method GetValue and SetValue.&lt;/p&gt;  &lt;h3&gt;A solution&lt;/h3&gt;  &lt;p&gt;I create a small helper to encapsulate a delegate in generic decorator that’s support my own IPropertyAccessor interface :&lt;/p&gt;  &lt;p&gt;IPropertyAccessor Interface is simple :&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public interface IPropertyAccessor    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PropertyInfo PropertyInfo { get; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string Name { get; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; object GetValue(object source)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; void SetValue(object source, object value);&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;An example :&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;// UneClasse : a simple class with an Int property PropertyA    &lt;br /&gt;var c = new UneClasse();     &lt;br /&gt;c.PropertyA= &lt;font color="#ff0000"&gt;12345&lt;/font&gt;;     &lt;br /&gt;PropertyInfo piA = typeof(UneClasse).GetProperty(&amp;quot;PropertyA&amp;quot;);     &lt;br /&gt;var paA = &lt;font color="#ff0000"&gt;PropertyInfoHelper&lt;/font&gt;.GetFastAccessor(piA);     &lt;br /&gt;Assert.AreEqual(c.FieldA, &lt;font color="#ff0000"&gt;12345&lt;/font&gt;); // Ok !     &lt;br /&gt;Assert.AreEqual(piA.GetValue(c, null), &lt;font color="#ff0000"&gt;12345&lt;/font&gt;); // Ok !     &lt;br /&gt;Assert.AreEqual(paA.GetValue(c), &lt;font color="#ff0000"&gt;12345&lt;/font&gt;); // Ok !     &lt;br /&gt;paA.SetValue(c, &lt;font color="#0000ff"&gt;54321&lt;/font&gt;);     &lt;br /&gt;Assert.AreEqual(c.PropertyA, &lt;font color="#0000ff"&gt;54321&lt;/font&gt;); // Ok !     &lt;br /&gt;Assert.AreEqual(piA.GetValue(c, null), &lt;font color="#0000ff"&gt;54321&lt;/font&gt;); // Ok !     &lt;br /&gt;Assert.AreEqual(paA.GetValue(c), &lt;font color="#0000ff"&gt;54321&lt;/font&gt;); // Ok ! &lt;/p&gt;  &lt;h3&gt;Performance &lt;/h3&gt;  &lt;p&gt;Some tests show importants differences between differences approachs.&lt;/p&gt;  &lt;p&gt;NB : all duration is done with 100 000 call on my computer.&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="398"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="203"&gt;Direct call :&lt;/td&gt;        &lt;td valign="top" width="193"&gt;~4 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="205"&gt;PropertyInfo.SetValue on public setter&lt;/td&gt;        &lt;td valign="top" width="192"&gt;~300 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="206"&gt;PropertyInfo.SetValue on private setter&lt;/td&gt;        &lt;td valign="top" width="191"&gt;~1400 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="207"&gt;Stronged delegate on SetValue MethodInfo (Private or public)&lt;/td&gt;        &lt;td valign="top" width="190"&gt;~5 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="208"&gt;Delegate call with DynamicInvoke (Private or public)&lt;/td&gt;        &lt;td valign="top" width="190"&gt;~1500 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="208"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;IPropertyAccessor helper&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="190"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;~9 ms.&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;ul&gt;   &lt;li&gt;the better way, of course, is direct call : &lt;strong&gt;(4 ms)&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;myInstance.PropertyA = 1234;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use SetValue method on PropertyInfo&amp;#160; &lt;strong&gt;(282 ms)&lt;/strong&gt; (Setter is public) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;PropertyInfo piA = typeof(UneClasse).GetProperty(&amp;quot;PropertyA&amp;quot;);    &lt;br /&gt;…     &lt;br /&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;piA.SetValue(myInstance, 1234, null);&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use SetValue method on PropertyInfo&amp;#160; &lt;strong&gt;(1391 ms)&lt;/strong&gt; (Setter is &lt;font color="#ff0000"&gt;private&lt;/font&gt;) &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;li&gt;Use strong typed Delegate created with Delegate.CreateDelegate() : 4 ms !! (same of direct call and even if Setter is private) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;var setMethodA = piA.GetSetMethod(true);    &lt;br /&gt;var _setHandlerATyped = (SetValueHandler&amp;lt;UneClasse,int&amp;gt;)Delegate.CreateDelegate(typeof(SetValueHandler&amp;lt;UneClasse,int&amp;gt;),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; setMethodA);     &lt;br /&gt;…     &lt;br /&gt;&lt;font color="#0000ff"&gt;&lt;em&gt;_setHandlerATyped.Invoke(myInstance, 1234)&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use my helper : 9 ms !! &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;IPropertyAccessor paA = PropertyInfoHelper.GetFastAccessor(piA);    &lt;br /&gt;…     &lt;br /&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;paA.SetValue(myInstance, 1234)&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Compare “CreateDelegate” versus “dynamic IL”&amp;#160; during intialisation process&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;in System.Web.dll, you can find an internal class “System.Web.Util.FastPropertyAccessor”.This class use Emit functions to generate dynamic assembly and dynamic code.&lt;/p&gt;  &lt;p&gt;I compare this approach (with little reflection to acces internal members) with CreateDelegate approach in console application and 5000 Test class with One property.&lt;/p&gt;  &lt;p&gt;The result is :&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="400"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="115"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="143"&gt;IL Approach (System.Web.Util          &lt;br /&gt;.FastPropertyAccessor)&lt;/td&gt;        &lt;td valign="top" width="140"&gt;CreateDelegate Approach          &lt;br /&gt;(IPropertyAccessor)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="99"&gt;Duration&lt;/td&gt;        &lt;td valign="top" width="156"&gt;11920 ms.&lt;/td&gt;        &lt;td valign="top" width="143"&gt;1337 ms.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="96"&gt;Memory delta&lt;/td&gt;        &lt;td valign="top" width="159"&gt;~32300 Ko&lt;/td&gt;        &lt;td valign="top" width="145"&gt;~6000 Ko&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;The code of the helper&lt;/strong&gt;&lt;/h3&gt;  &lt;pre class="csharp:nogutter:collapse" name="code"&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Reflection;&lt;br /&gt;&lt;br /&gt;namespace Tools.Reflection&lt;br /&gt;{&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Représentation d'une propriété pour accélerer de maniére considérable les écritures/lectures par reflection&lt;br /&gt;    /// sur les propriétés d'un object&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    public interface IPropertyAccessor&lt;br /&gt;    {&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// La propriété concernée&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        PropertyInfo PropertyInfo { get; }&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Le nom de cette propriété&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        string Name { get; }&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Récupération de la valeur de la propriété&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="source" /&gt;l'object concerné&lt;/param&gt;&lt;br /&gt;        /// &lt;returns&gt;valeur de la propriété&lt;/returns&gt;&lt;br /&gt;        object GetValue(object source);&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Mise en place d'une nouvelle valeur dans la propriété&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="source" /&gt;l'object concerné&lt;/param&gt;&lt;br /&gt;        /// &lt;param name="value" /&gt;la nouvelle valeur pour la propriété&lt;/param&gt;&lt;br /&gt;        void SetValue(object source, object value);&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Classe helper pour obtenir l'accesseur sur une propriété donnée&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    public static class PropertyInfoHelper&lt;br /&gt;    {&lt;br /&gt;        private static Dictionary&lt;propertyinfo ipropertyaccessor ,&gt; _cache = new Dictionary&lt;propertyinfo ipropertyaccessor ,&gt;();&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Obtention du helper pour acceder au getter/setter de la propriété&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="propertyInfo" /&gt;&lt;/param&gt;&lt;br /&gt;        /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;        public static IPropertyAccessor GetFastAccessor(PropertyInfo propertyInfo)&lt;br /&gt;        {&lt;br /&gt;            IPropertyAccessor result;&lt;br /&gt;            lock (_cache)&lt;br /&gt;            {&lt;br /&gt;                if (!_cache.TryGetValue(propertyInfo, out result))&lt;br /&gt;                {&lt;br /&gt;                    result = CreateAccessor(propertyInfo);&lt;br /&gt;                    _cache.Add(propertyInfo, result); ;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            return result;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// public pour les tests de performances&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="propertyInfo" /&gt;&lt;/param&gt;&lt;br /&gt;        /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;        public static IPropertyAccessor CreateAccessor(PropertyInfo propertyInfo)&lt;br /&gt;        {&lt;br /&gt;            return (IPropertyAccessor)Activator.CreateInstance(&lt;br /&gt;                        typeof(PropertyWrapper&amp;lt;,&amp;gt;).MakeGenericType&lt;br /&gt;                           (propertyInfo.DeclaringType, propertyInfo.PropertyType), propertyInfo);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Classe concrete implémentant IPropertyAccessor&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;typeparam name="TObject"&gt;&lt;/typeparam&gt;&lt;br /&gt;    /// &lt;typeparam name="TProperty"&gt;&lt;/typeparam&gt;&lt;br /&gt;    internal class PropertyWrapper&lt;tobject  , tvalue&gt; : IPropertyAccessor&lt;br /&gt;    {&lt;br /&gt;        private PropertyInfo _propertyInfo;&lt;br /&gt;&lt;br /&gt;        private Func&lt;tobject  , tvalue&gt; _getMethod;&lt;br /&gt;        private Action&lt;tobject  , tvalue&gt; _setMethod;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Constructeur public&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="propertyInfo" /&gt;la propriété à encapsulé&lt;/param&gt;&lt;br /&gt;        public PropertyWrapper(PropertyInfo propertyInfo)&lt;br /&gt;        {&lt;br /&gt;            _propertyInfo = propertyInfo;&lt;br /&gt;&lt;br /&gt;            MethodInfo mGet = propertyInfo.GetGetMethod(true);&lt;br /&gt;            MethodInfo mSet = propertyInfo.GetSetMethod(true);&lt;br /&gt;&lt;br /&gt;             // Rq : on peut par se biais acceder aussi aux accesseur privé&lt;br /&gt;            //      tous les aspects liés à la sécurité est donc pris en charge par CreateDelegate&lt;br /&gt;            //      et non à chaque appel à GetMethod/SetMethod&lt;br /&gt;&lt;br /&gt;            _getMethod = (Func&lt;tobject  , tvalue&gt;)Delegate.CreateDelegate&lt;br /&gt;                    (typeof(Func&lt;tobject  , tvalue&gt;), mGet);&lt;br /&gt;            _setMethod = (Action&lt;tobject  , tvalue&gt;)Delegate.CreateDelegate&lt;br /&gt;                    (typeof(Action&lt;tobject  , tvalue&gt;), mSet);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        object IPropertyAccessor.GetValue(object source)&lt;br /&gt;        {&lt;br /&gt;            return _getMethod((TObject)source);&lt;br /&gt;        }&lt;br /&gt;        void IPropertyAccessor.SetValue(object source, object value)&lt;br /&gt;        {&lt;br /&gt;            _setMethod((TObject)source, (TValue)value);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Voir &lt;see cref="IPropertyAccessor.Name" /&gt;&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public string Name&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return _propertyInfo.Name;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Voir &lt;see cref="IPropertyAccessor.PropertyInfo" /&gt;&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public PropertyInfo PropertyInfo&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return _propertyInfo;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;TODO List&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;test on real application : It is just a prototype ! &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;improve with this[] property &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;References&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;Discussion : &lt;a title="http://stackoverflow.com/questions/724143/how-do-i-create-a-delegate-for-a-net-property" href="http://stackoverflow.com/questions/724143/how-do-i-create-a-delegate-for-a-net-property"&gt;http://stackoverflow.com/questions/724143/how-do-i-create-a-delegate-for-a-net-property&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Discussion : &lt;a title="http://stackoverflow.com/questions/1308642/delegate-createdelegate-without-prototype" href="http://stackoverflow.com/questions/1308642/delegate-createdelegate-without-prototype"&gt;http://stackoverflow.com/questions/1308642/delegate-createdelegate-without-prototype&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Reference : &lt;a title="http://msmvps.com/blogs/jon_skeet/archive/2008/08/09/making-reflection-fly-and-exploring-delegates.aspx" href="http://msmvps.com/blogs/jon_skeet/archive/2008/08/09/making-reflection-fly-and-exploring-delegates.aspx"&gt;http://msmvps.com/blogs/jon_skeet/archive/2008/08/09/making-reflection-fly-and-exploring-delegates.aspx&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-6717033204482542851?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/6717033204482542851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/6717033204482542851'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2010/10/fast-property-accessor-without-dynamic.html' title='Fast Property Accessor without dynamic IL'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-5888583255660670063</id><published>2010-02-21T03:43:00.001-08:00</published><updated>2010-02-21T05:04:06.007-08:00</updated><title type='text'>Footer on WPF DataGrid: by use several synchronized datagrid</title><content type='html'>&lt;h4&gt;Introduction&lt;/h4&gt;  &lt;p&gt;Last year, I &lt;a href="http://thibaud60.blogspot.com/2008/11/new-version-of-datagrid-with-footer.html"&gt;proposed a version of WPF DataGrid with Footer&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;But this version can not apply on new WPF 4.0 Datagrid (because i was make too much changes in source code of the component) &lt;/p&gt;  &lt;p&gt;With this new approach, I use several DataGrid in the same Window, and I synchronizes each one on : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Scrolling event (horizontal and vertical)&lt;/li&gt;    &lt;li&gt;Drag and drop column header&lt;/li&gt;    &lt;li&gt;Change width of column on main DataGrid&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Even if it is more complex to apply for each Data window (It is necessary to instanciate several DataGrid, set relatation between each one, etc.) , It seems pretty good because : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It can apply on new version WPF 4.0 Datagrid&lt;/li&gt;    &lt;li&gt;It can manage too the merge header of multiple column (cf demo)&lt;/li&gt;    &lt;li&gt;It can use to do something like “Microsoft Excel&amp;quot; to freeze some column or row in a global Data grid ! &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Screenshot of the demo :&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_dDsO1He2FKk/S4EcRoNUgFI/AAAAAAAAADc/uuBIK3-s2u0/s1600-h/ScreenShot2%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ScreenShot2" border="0" alt="ScreenShot2" src="http://lh5.ggpht.com/_dDsO1He2FKk/S4EcSSOOVSI/AAAAAAAAADg/alzwHe5bZas/ScreenShot2_thumb%5B4%5D.jpg?imgmax=800" width="445" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h4&gt;Download&lt;/h4&gt;  &lt;p&gt;Download v1.00 &lt;a href="http://cid-7a1aaa8f8ef48b01.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2010/WpfDataGridSynchronized%5E_V1.00.zip"&gt;here&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;WPF 3.5 version (on Visual Studio 2008) &lt;/li&gt;    &lt;li&gt;WPF 4.0 version (on Visual Studio 2010 Beta) &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;API :&lt;/h4&gt;  &lt;p&gt;To do this, It is necessary to : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Have the same number of column in each DataGrid (except if you merge header column with specific attached property) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;lt;tk:DataGrid.Columns&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;tk:DataGridTextColumn local:&lt;strong&gt;&lt;font color="#ff0000"&gt;AssociatedDataGrid.ColumnSpan&lt;/font&gt;&lt;/strong&gt;=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Binding=&amp;quot;{Binding A}&amp;quot;/&amp;gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I use attached Dependency Property to set the link between main grid and another grid &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;lt;tk:DataGrid    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name=&amp;quot;xMain&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Row=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ItemsSource=&amp;quot;{Binding DataSource}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#ff0000"&gt;local:&lt;strong&gt;AssociatedDataGrid.Bottom&lt;/strong&gt;&lt;/font&gt;=&amp;quot;{Binding ElementName=xBottom}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#ff0000"&gt;local:&lt;strong&gt;AssociatedDataGrid.Top&lt;/strong&gt;&lt;/font&gt;=&amp;quot;{Binding ElementName=xTop}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#ff0000"&gt;local:&lt;strong&gt;AssociatedDataGrid.Right&lt;/strong&gt;&lt;/font&gt;=&amp;quot;{Binding ElementName=xRight}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#ff0000"&gt;local:&lt;strong&gt;AssociatedDataGrid.Left&lt;/strong&gt;&lt;/font&gt;=&amp;quot;{Binding ElementName=xLeft}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AutoGenerateColumns=&amp;quot;False&amp;quot;&amp;gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;and it’s all ! &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;My demo is a demo … I think lot of thing is not finished by main idea is in it !&lt;/p&gt;  &lt;p&gt;Best regards&lt;/p&gt;  &lt;p&gt;Thibaud&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-5888583255660670063?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/5888583255660670063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/5888583255660670063'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html' title='Footer on WPF DataGrid: by use several synchronized datagrid'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_dDsO1He2FKk/S4EcSSOOVSI/AAAAAAAAADg/alzwHe5bZas/s72-c/ScreenShot2_thumb%5B4%5D.jpg?imgmax=800' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-1039843007610427201</id><published>2009-11-29T06:26:00.001-08:00</published><updated>2009-11-29T06:26:47.342-08:00</updated><title type='text'>CollectionView.GetItemProperties : Great and good differences between WPF 3.5 and 4.0</title><content type='html'>&lt;h5&gt;WPF 3.5 algorithm&lt;/h5&gt; &lt;p&gt;In WPF 3.5, when you bind your own Collection to a wpf control, "WPF framework" needs define the list of all allowed properties of the items of the collection.  &lt;p&gt;To do this, "WPF Framework" tests if collection is a generic type, AND if the generic type contains only one sub-type : it is use to define the item type of collection, in other case, "WPF Framework" try to use the first item of the collection (if collection is not empty) &lt;p&gt;With Reflector, you can find a part of this algorithm in CollectionView.GetItemType() :&lt;/p&gt;&lt;pre&gt;internal &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type"&gt;Type&lt;/a&gt; &lt;b&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:3.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/GetItemType(Boolean):System.Type"&gt;GetItemType&lt;/a&gt;&lt;/b&gt;(&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Boolean"&gt;bool&lt;/a&gt; useRepresentativeItem)&lt;br /&gt;{&lt;br /&gt;    &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type"&gt;Type&lt;/a&gt; &lt;b&gt;type&lt;/b&gt; = this.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:3.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/property:SourceCollection:System.Collections.IEnumerable"&gt;SourceCollection&lt;/a&gt;.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type"&gt;GetType&lt;/a&gt;();&lt;br /&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;    if (&lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;type&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type/property:IsGenericType:Boolean"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;IsGenericType&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;[] genericArguments = &lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;type&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type/GetGenericArguments():System.Type%5b%5d"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GetGenericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;();&lt;br /&gt;        if (&lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;genericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Array/property:Length:Int32"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Length&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt; == 1)&lt;br /&gt;        {&lt;br /&gt;            return &lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;genericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;[0];&lt;br /&gt;        }&lt;br /&gt;    }&lt;/strong&gt;&lt;/font&gt;&lt;br /&gt;    else if (&lt;a&gt;useRepresentativeItem&lt;/a&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object"&gt;object&lt;/a&gt; &lt;b&gt;representativeItem&lt;/b&gt; = this.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:3.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/GetRepresentativeItem():Object"&gt;GetRepresentativeItem&lt;/a&gt;();&lt;br /&gt;        if (&lt;a&gt;representativeItem&lt;/a&gt; != null)&lt;br /&gt;        {&lt;br /&gt;            return &lt;a&gt;representativeItem&lt;/a&gt;.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type"&gt;GetType&lt;/a&gt;();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;in WPF 4.0 beta 2, Algorithm is different !!!!&lt;/p&gt;&lt;br /&gt;&lt;h5&gt;WPF 4.0 beta 2 algorithm&lt;/h5&gt;&lt;br /&gt;&lt;p&gt;in WPF 4.0, framework test if original collection source support a generic IEnumerable type and If test is True, the type of this subtype of Generic IEnumerable !&lt;/p&gt;&lt;br /&gt;&lt;p&gt;the code of this version is :&lt;/p&gt;&lt;pre&gt;internal &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type"&gt;Type&lt;/a&gt; &lt;b&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:4.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/GetItemType(Boolean):System.Type"&gt;GetItemType&lt;/a&gt;&lt;/b&gt;(&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Boolean"&gt;bool&lt;/a&gt; useRepresentativeItem)&lt;br /&gt;{&lt;br /&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;    foreach (&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt; type2 in this.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:4.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/property:SourceCollection:System.Collections.IEnumerable"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;SourceCollection&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GetType&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;().&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type/GetInterfaces():System.Type%5b%5d"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GetInterfaces&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;())&lt;br /&gt;    {&lt;br /&gt;        if (&lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;type2&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Reflection.MemberInfo/property:Name:String"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt; == &lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:4.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/IEnumerableT:String"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;IEnumerableT&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;)&lt;br /&gt;        {&lt;br /&gt;            &lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;[] genericArguments = &lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;type2&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type/GetGenericArguments():System.Type%5b%5d"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GetGenericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;();&lt;br /&gt;            if (&lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;genericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Array/property:Length:Int32"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Length&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt; == 1)&lt;br /&gt;            {&lt;br /&gt;                return &lt;/strong&gt;&lt;/font&gt;&lt;a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;genericArguments&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;[0];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;/strong&gt;&lt;/font&gt;&lt;br /&gt;    if (&lt;a&gt;useRepresentativeItem&lt;/a&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object"&gt;object&lt;/a&gt; &lt;b&gt;representativeItem&lt;/b&gt; = this.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://PresentationFramework:4.0.0.0:31bf3856ad364e35/System.Windows.Data.CollectionView/GetRepresentativeItem():Object"&gt;GetRepresentativeItem&lt;/a&gt;();&lt;br /&gt;        if (&lt;a&gt;representativeItem&lt;/a&gt; != null)&lt;br /&gt;        {&lt;br /&gt;            return &lt;a&gt;representativeItem&lt;/a&gt;.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type"&gt;GetType&lt;/a&gt;();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h5&gt;Consequences :&lt;/h5&gt;&lt;br /&gt;&lt;p&gt;It is a very important change if you develop your own collection. With the new approach, It is possible now to create generic collection with more than one sub type ! &lt;/p&gt;&lt;br /&gt;&lt;p&gt;for example, in MVVM architecture, it would be very nice to create a ViewModel of collection to enumerate ViewModel of item with a specific contraint&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;public class&amp;nbsp; ViewModelCollectionBase&amp;lt;TViewModel, TModel&amp;gt; : IEnumerable&amp;lt;TViewModel&amp;gt;&lt;br&gt;where TViewModel : ViewModelBase&amp;lt;TModel&amp;gt;&lt;br&gt;{&lt;br&gt;…&amp;nbsp;&amp;nbsp; &lt;br&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p&gt;public class ViewModelBase&amp;lt;TModel&amp;gt; where TModel : class&lt;br&gt;{&lt;br&gt;…&lt;br&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-1039843007610427201?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/1039843007610427201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/1039843007610427201'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2009/11/collectionviewgetitemproperties-great.html' title='CollectionView.GetItemProperties : Great and good differences between WPF 3.5 and 4.0'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-3403065822965090205</id><published>2009-03-30T14:57:00.001-07:00</published><updated>2009-07-22T11:38:47.180-07:00</updated><title type='text'>Static event on ViewModel in MVVM : Helper that prevents Leak errors memory, and so more …</title><content type='html'>&lt;h3&gt;Abstract&lt;/h3&gt;  &lt;p&gt;Use static public event properties on &lt;strong&gt;ViewModel&lt;/strong&gt; class for :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;High level of API to mask the technical complexity of the problem &lt;/li&gt;    &lt;li&gt;ensure communication between &lt;strong&gt;ViewModel&lt;/strong&gt; and &lt;strong&gt;View part&lt;/strong&gt; without leak memory AND with only one wired process on View part even if ViewModel contains lot of entities. &lt;/li&gt;    &lt;li&gt;ensure communication between entities of &lt;strong&gt;ViewModel&lt;/strong&gt; and ensure it in a graph of entities. &lt;/li&gt;    &lt;li&gt;accept lot of quantity of &lt;strong&gt;ViewModel&lt;/strong&gt; entities without overhead (memory or/and performance) &lt;/li&gt;    &lt;li&gt;controls target’s type which is allowed to use on these events &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;In MVVM architecture, I need create a graph of entities in ViewModel part with POCO objects. these entities must communicate with …&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;another instances of ViewModem &lt;/li&gt;    &lt;li&gt;View part of the MVVM architecture &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;… without direct dependency between Sender to the targets : ViewModel has not dependency on &amp;quot;View Part&amp;quot; AND sometimes, entities of ViewModel&amp;#160; do not link directly all another entities of the model&lt;/p&gt;  &lt;p&gt;A good technical approach to do this is used a static CLR Event on ViewModel class, static events are always accessibles even if ViewModel instance not yet exists&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;from another ViewModel class &lt;/li&gt;    &lt;li&gt;from “View part“ of MVVM like a Window or UserControl. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;BUT we need integrate these contraints :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;a Simple static CLR Event keeps a reference on target’s instance : Garbage collector will never free target’s instance if this target will not remove its handler in the static CLR event. &lt;/li&gt;    &lt;li&gt;If static CLR event is used by a lot of quantity of ViewModel instance. The performance must stay high. &lt;/li&gt;    &lt;li&gt;If we create more than one instance of the ViewModel graph and use only static CLR Event : Each Invoke of static event must reach only the &lt;font color="#ff0000"&gt;“good” instances&lt;/font&gt; of ViewModel (or View part) and not all referenced target. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;“Good” instances&lt;/font&gt; seems only ViewModel entity that have relations with the invoker ViewModel OR View part that bind with ViewModel entity.&lt;/p&gt;  &lt;p&gt;I proposed a main class : StaticEvent&amp;lt;&amp;gt; that can help us to do this !&lt;/p&gt;  &lt;h3&gt;How can I use it ?&lt;/h3&gt;  &lt;p&gt;Example of code to declare a new Event :&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;private static&lt;/font&gt; StaticEvent&amp;lt;MyEventArgs&amp;gt; _myEvent =&amp;#160; &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;new&lt;/font&gt;&amp;#160; StaticEvent();     &lt;br /&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static event&lt;/font&gt; EventHandler&amp;lt;MyEventArgs&amp;gt; &lt;strong&gt;MyEvent&lt;/strong&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;add&lt;/font&gt;     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _myEvent.Add(value);&amp;#160; &lt;br /&gt;&amp;#160; }     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;remove&lt;/font&gt;     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _myEvent.Remove(value);     &lt;br /&gt;&amp;#160; }     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public static void&lt;/font&gt; OnMyEvent(MyEventArgs e)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; _myEvent.Invoke(e);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;When developper uses the event : he works with it like a classic event with += / –= operator. The internal implementation is masked.&lt;/p&gt;  &lt;h3&gt;What can I wired on this type of Event ?&lt;/h3&gt;  &lt;p&gt;StaticEvent&amp;lt;&amp;gt; generic class is a base class to implement another type of it. In Diagram class below, and the prototype, I used a ModelViewEvent&amp;lt;&amp;gt;.&lt;/p&gt;  &lt;p&gt;This event accepts 3 types of EventHandler :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;EventHandler on a static method &lt;/li&gt;    &lt;li&gt;EventHandler on an instance entity of ViewModel &lt;/li&gt;    &lt;li&gt;EventHandler on an instance of FrameworkElement. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Entities of ViewModel must derivated from ViewModelBase&amp;lt;&amp;gt; class that implements required interface (IHandlersRepository)&lt;/p&gt;  &lt;h3&gt;The sequence of calls during “Invoke process”&lt;/h3&gt;  &lt;p&gt;The main concept is base on &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.aspx"&gt;RoutedEvent of WPF framework&lt;/a&gt;. In the RoutedEvent design pattern : the “route” of calls is build BY the invoker ! &lt;/p&gt;  &lt;p&gt;I was reproduce the same approach in StaticEvent class !&lt;/p&gt;  &lt;p&gt;If the invoker is a ViewModel Entity (supports IHandlersRepository), StaticEvent asks the invoker (by IHandlersRepository.GetHandlers) and invoker must give zero, one or more EventHandlers which will be called by StaticEvent.&lt;/p&gt;  &lt;p&gt;So, ViewModelBase class visits each its owners and combines all handlers found during this visit.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="400"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;p&gt;&amp;#160;&lt;/p&gt;          &lt;p&gt;&amp;#160;&lt;/p&gt;          &lt;p&gt;For example, Demo application realize this sequence on an example graph &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="200"&gt;&lt;a href="http://lh5.ggpht.com/_dDsO1He2FKk/SdJ6PWoBMGI/AAAAAAAAADU/Enade22WZDc/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_dDsO1He2FKk/SdJ6P1TDiAI/AAAAAAAAADY/_Om0ldxgy9M/image_thumb.png?imgmax=800" width="125" height="244" /&gt;&lt;/a&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;Using the approach of the RoutedEvent model of WPF FrameworkElement solves …&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;Communicate between ViewModel instances &lt;/li&gt;    &lt;li&gt;have good performance event with a huge quantity of entities &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I will use this approach in a MVVM Framework to send message between ViewModel instances : Example : When an ViewModel entity will be validated, and if this ViewModel is owned by another : It would be very useful that the owner ViewModel instance can stop or not the validation process of its own Son ViewModel instances !&lt;/p&gt;  &lt;p&gt;I use it for Filter event of my own ICollectionView instance, very useful in this case !&lt;/p&gt;  &lt;p&gt;With this approach, each instance of ViewModel (that supports IHandlerRepository) keeps references of its own EventHandler. So even if you have 1 000 000 instances of ViewModel object and just ONE static event that uses by this instances : Each instance keep one and only one EventHandler ! and moreover, StaticEvent is not a strong reference (by EventHandler) on these 1 000 000 ViewModel objects :&amp;#160; of course : it does not know these objects !!&lt;/p&gt;  &lt;h3&gt;Prevent against Leak memory issues : Using Life event cycle of FrameworkElement &lt;/h3&gt;  &lt;p&gt;Each FrameworkElement have Loaded, Unloaded and Initialize event. If you look inside the Demo, ViewEvent class creates an adapter on each FrameworkElement target. This adapter supports IHandlerRepository interface. This adapter is memorized by FrameworkElement instance (with an attached dependency property) and It uses these 3 events for accept or not a call process !&lt;/p&gt;  &lt;p&gt;NB : WPF RoutedEvent mechanism used a roughly same approach to memorize EventHandlers (see System.Windows.UncommonField&amp;lt;T&amp;gt; internal class in WindowBase.dll and System.Windows.UIElement.AddHandler method :-)&lt;/p&gt;  &lt;h3&gt;TODO List …&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;Invoke’s strategy like Bubble, Direct, Tunnel strategy of RoutedEvent. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Class diagrams&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;StaticEvent&lt;/strong&gt; class hierarchy : &lt;strong&gt;StaticEvent&lt;/strong&gt;&amp;lt;&amp;gt; is the most important class : It have a dependancy on &lt;strong&gt;IHandlersRepository&lt;/strong&gt;       &lt;ul&gt;       &lt;ul&gt;         &lt;li&gt;by &lt;strong&gt;ProvideHandlersRepository&lt;/strong&gt; method &lt;/li&gt;          &lt;li&gt;if a handler’s target implements or not this interface (in Add(EventHandler) calls) &lt;/li&gt;          &lt;li&gt;if a sender implements or not this interface (in Invoke calls) &lt;/li&gt;       &lt;/ul&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_dDsO1He2FKk/SdFATR8_waI/AAAAAAAAADE/M1oZxE_48Ds/s1600-h/Framework%5B2%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Framework" border="0" alt="Framework" src="http://lh5.ggpht.com/_dDsO1He2FKk/SdFAT0pAyVI/AAAAAAAAADI/qP-T28wqYwE/Framework_thumb.png?imgmax=800" width="230" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;ViewModel&lt;/strong&gt; entity class hierarchy : Just a demo to use &lt;strong&gt;StaticEvent&lt;/strong&gt; in &lt;strong&gt;ViewModel&lt;/strong&gt; part of MVVM architecture : ViewModelEvent allows to wired a &lt;strong&gt;FrameworkElement&lt;/strong&gt; instance without leak memory errors. It uses Loaded/UnLoaded event of FrameworkElement &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_dDsO1He2FKk/SdFAUUOcZAI/AAAAAAAAADM/HTKrOTjYXkY/s1600-h/Framework.Window%5B2%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Framework.Window" border="0" alt="Framework.Window" src="http://lh4.ggpht.com/_dDsO1He2FKk/SdFAUz_DPCI/AAAAAAAAADQ/rFGMCKHMgnY/Framework.Window_thumb.png?imgmax=800" width="212" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Download&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2009/StaticEvent%7C_v2.20.zip"&gt;Download v2.20&lt;/a&gt; 03/29/2009&lt;/p&gt;  &lt;h3&gt;References&lt;/h3&gt;  &lt;p&gt;previous article : &lt;a title="http://thibaud60.blogspot.com/2009/03/helper-to-create-weak-event-with-strong.html" href="http://thibaud60.blogspot.com/2009/03/helper-to-create-weak-event-with-strong.html"&gt;http://thibaud60.blogspot.com/2009/03/helper-to-create-weak-event-with-strong.html&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-3403065822965090205?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/3403065822965090205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/3403065822965090205'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2009/03/event-static-on-viewmodel-in-mvvm.html' title='Static event on ViewModel in MVVM : Helper that prevents Leak errors memory, and so more …'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_dDsO1He2FKk/SdJ6P1TDiAI/AAAAAAAAADY/_Om0ldxgy9M/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-8547924598760187292</id><published>2009-03-14T11:06:00.001-07:00</published><updated>2009-07-22T11:40:15.274-07:00</updated><title type='text'>Helper to create a weak event with strong typed signature</title><content type='html'>&lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;When you create an event like this&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family: courier new"&gt;public event EventHandler&amp;lt;MyEventArgs&amp;gt; MyEvent;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;and you use it like this :&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family: courier new"&gt;{      &lt;br /&gt;var receiver = new MyReceiverClass();       &lt;br /&gt;this.MyEvent += receiver.ReceiveMethod;&lt;/span&gt;&lt;span style="font-family: courier new"&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new"&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;Receiver instance will be never cleaned in memory by Garbage Collector while “this” is referenced by any another object and, if &amp;quot;this&amp;quot; is Singleton object … receiver will be never free !!!! Even if receiver is not referenced somewhere … simply because it is referenced by the event of the Singleton :-( &lt;/p&gt;  &lt;p&gt;.Net Framework provides us with some tools to avoid this problem. You can see e.g. this &lt;a href="http://msdn.microsoft.com/en-us/library/aa970850.aspx"&gt;reference&lt;/a&gt;. It is the WeakEvent patterns.&lt;/p&gt;  &lt;p&gt;This pattern works fine but it is a little hard and complex to create an object which receives an event with out strong reference : we need to implement IWeakEventListener interface or/and use a WeakEventManager.&lt;/p&gt;  &lt;p&gt;My helper approaches the problem in a different way:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It is easy to use += / –= operator to wire/unwire event with &lt;strong&gt;exactly&lt;/strong&gt; the same approach of that of a classical event &lt;/li&gt;    &lt;li&gt;helper does not give a strong reference on receiver event &lt;/li&gt;    &lt;li&gt;helper allows additionnal functions on FrameworkElement receivers:      &lt;br /&gt;-&amp;gt; an unloaded instance will not received event!       &lt;br /&gt;-&amp;gt; capacity to filter Execute calls when the event is wired on different receiver (not tested …) &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Example of usage&lt;/h3&gt;  &lt;h5&gt;To declare an event, you need just this code :&lt;/h5&gt;  &lt;p&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; UIWeakEventHandler&amp;lt;MyEventArgs&amp;gt; _myEvent;       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler&amp;lt;MyEventArgs&amp;gt; &lt;span style="color: #ff0000"&gt;&lt;strong&gt;MyEvent&lt;/strong&gt;&lt;/span&gt;       &lt;br /&gt;{       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;add&lt;/span&gt;       &lt;br /&gt;{       &lt;br /&gt;_myEvent += value; // UIWeakEventHandler is created by += operator if necessary       &lt;br /&gt;}       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;remove&lt;/span&gt;       &lt;br /&gt;{       &lt;br /&gt;_myEvent –= value;       &lt;br /&gt;}       &lt;br /&gt;} &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMyEvent(MyEventArgs e)       &lt;br /&gt;{       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_myEvent != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)       &lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new"&gt;_myEvent.Invoke(e);      &lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;and It”s All Folks :-)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="color: #ff0000"&gt;MyEvent&lt;/span&gt;&lt;/strong&gt; is a public event and supports classic += / –= operator so Visual Studio offers the traditionnal helper like auto-created-code when the developper press &amp;quot;+=&amp;quot; key sequence.&lt;/p&gt;  &lt;h3&gt;Why do I want to use this?&lt;/h3&gt;  &lt;p&gt;I need to create some events in my application on singleton instance and sometimes these events could be wired on WPF Window. When using a simple event, it is always necessary to wire on Loaded event of my Window and not forget to unwire event in Unloaded event of the same Window: when forgetting them will lead to some Leak memory error and it could take ages to find the origin of the problem. I hope this type of technical approach helps me!&lt;/p&gt;  &lt;h3&gt;Download&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://thibaud60.site.voila.fr/Archives/2009/ModelRoutedEvent_V2.10.zip"&gt;Download v2.10&lt;/a&gt; (29/03/2009)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_dDsO1He2FKk/Sc9dDtXjWGI/AAAAAAAAAC0/lw32CoMqe9E/s1600-h/image%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_dDsO1He2FKk/Sc9dET1PBRI/AAAAAAAAAC4/ZXCep2VyNcc/image_thumb%5B1%5D.png?imgmax=800" width="184" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Complete refactoring ! I will create another post in fews days to explain all news functionnalities      &lt;ul&gt;       &lt;li&gt;&lt;strong&gt;IHandlersRepository&lt;/strong&gt; interface : new name of IModelViewEventSupports &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public interface&lt;/font&gt; IHandlersRepository     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;void&lt;/font&gt; AddHandler(ModelRoutedEvent modelRoutedEvent, Delegate handler);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;void&lt;/font&gt; RemoveHandler(ModelRoutedEvent modelRoutedEvent, Delegate handler);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;void&lt;/font&gt; GetHandlers(ModelRoutedEvent modelRoutedEvent, object sender, EventArgs e, &lt;font color="#0000ff"&gt;ref&lt;/font&gt; List&amp;lt;Delegate&amp;gt; result);     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;new &lt;strong&gt;RoutedPropertyChangedEvent&lt;/strong&gt; and &lt;strong&gt;RoutedPropertyChangingEvent&lt;/strong&gt; &lt;/li&gt;      &lt;li&gt;Create &lt;strong&gt;FrameworkElementHandlersRepository&lt;/strong&gt; class to optimize memory perfomance on FrameworkElement target (Same internal approach of RoutedEvent of .Net WPF framework) &lt;/li&gt;      &lt;li&gt;Example with TreeView and Recursive ModelView entity &lt;/li&gt;      &lt;li&gt;Include {&lt;a href="http://thibaud60.blogspot.com/2009/02/convert-clr-method-to-icommand-with.html"&gt;MethodBinding&lt;/a&gt;} approach in TreeView Example&lt;a href="http://lh3.ggpht.com/_dDsO1He2FKk/Sc9dFIzrXLI/AAAAAAAAAC8/_pks9-j-gs8/s1600-h/image%5B6%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_dDsO1He2FKk/Sc9dFuucfvI/AAAAAAAAADA/MlbC2wr4hCY/image_thumb%5B2%5D.png?imgmax=800" width="234" height="244" /&gt;&lt;/a&gt; &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2009/WeakEventHandler%7C_v1.20.zip"&gt;Download v1.20&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;new interface &lt;strong&gt;IStorableEventsObject&lt;/strong&gt; / &lt;strong&gt;IModelViewEventSupports&lt;/strong&gt; to implements a “routed event pattern”&amp;#160; on ModelView object &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2009/WeakEventHandler%7C_v1.10.zip"&gt;Download v1.10&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_dDsO1He2FKk/SbvyDWWgbBI/AAAAAAAAAB0/2ntfbOkkyAY/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_dDsO1He2FKk/SbvyD2J439I/AAAAAAAAACA/OPiChonknzE/image_thumb.png?imgmax=800" width="187" height="147" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;the main window can open secondary window via “New Windows” button &lt;/li&gt;    &lt;li&gt;“Fire static event” calls a static event and changes a Label in secondary Windows &lt;/li&gt;    &lt;li&gt;“Show counter” gives you the quantity of Window2 class instance &lt;/li&gt;    &lt;li&gt;“GC.Collect” executes a memory collection &amp;gt;&amp;gt; Clic on “Show counter” to see the consequences of this collection &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I never used this prototype in real application and so comments will be very welcomed :-)&lt;/p&gt;  &lt;p&gt;Best regards&lt;/p&gt;  &lt;h3&gt;Class Diagram&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_dDsO1He2FKk/Sb0PkHYnN4I/AAAAAAAAACM/HqdzbiKNjbA/s1600-h/WeakEventHandler%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WeakEventHandler" border="0" alt="WeakEventHandler" src="http://lh5.ggpht.com/_dDsO1He2FKk/Sb0PlHRfVhI/AAAAAAAAACQ/YiJttWMFRVs/WeakEventHandler_thumb%5B1%5D.png?imgmax=800" width="461" height="372" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Todo list&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;I started to retro-analysis Routed event of WPF framework in order to understand the way is has been designed. For example, very good performances are certainly obtained by saving Event handler of a UIElement in the same UIElement (like Dependency proprerty mechanism): the static routed event instance is only an identifier of the event and does not memorises anything else.      &lt;br /&gt;My own approach is different. I have a Weak-list of Event handler: when quantity of receiver instances is important (e.g. more than 10 000) &amp;gt;&amp;gt; will possibly result in having some performance problems during the invoking process.       &lt;br /&gt;Routed approach will be possible only when invoker has a link with receiver. This link will be the Logical graph of user interface in &amp;quot;Routed Event and UIElement invoker&amp;quot;. &lt;strong&gt;&amp;gt;&amp;gt; you can find a prototype of this approach in v1.20 version of download        &lt;br /&gt;&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;I wish to interact between these static events and a graph of data object (ModelView part of Model - ModelView - View approach ) and when an instance of data object invokes a static event, My goal is that every ancestor (and only them) of this instance (in the graph) receives the event! &lt;strong&gt;&amp;gt;&amp;gt; you can find a prototype of this approach in v1.20 version of download&lt;/strong&gt;       &lt;br /&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;References&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;WeakEvent pattern of microsoft framework : &lt;a title="http://msdn.microsoft.com/en-us/library/aa970850.aspx" href="http://msdn.microsoft.com/en-us/library/aa970850.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa970850.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Explanation of Event strong reference in this good article : &lt;a title="http://blogs.msdn.com/greg_schechter/archive/2004/05/27/143605.aspx" href="http://blogs.msdn.com/greg_schechter/archive/2004/05/27/143605.aspx"&gt;http://blogs.msdn.com/greg_schechter/archive/2004/05/27/143605.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Roughly the same approach : &lt;a title="http://pabich.eu/blog/archive/2008/05/29/weakevent---you-wish-it-was-here.aspx" href="http://pabich.eu/blog/archive/2008/05/29/weakevent---you-wish-it-was-here.aspx"&gt;http://pabich.eu/blog/archive/2008/05/29/weakevent---you-wish-it-was-here.aspx&lt;/a&gt; and It’s contains very good ideas like : Multithreading aspects, Semantic (Add, Remove, Invoke better than my Add(Remove)WeakRefenceHandler/Execute) : theses ideas are integrated in v1.10 of download :-) &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-8547924598760187292?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/8547924598760187292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/8547924598760187292'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2009/03/helper-to-create-weak-event-with-strong.html' title='Helper to create a weak event with strong typed signature'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_dDsO1He2FKk/Sc9dET1PBRI/AAAAAAAAAC4/ZXCep2VyNcc/s72-c/image_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-5964007476396116684</id><published>2009-02-01T09:04:00.000-08:00</published><updated>2009-07-22T11:41:09.920-07:00</updated><title type='text'>Convert "CLR method" to "ICommand" with just a XAML declaration</title><content type='html'>&lt;strong&gt;&lt;span style="font-size: 130%"&gt;Introduction&lt;/span&gt;&lt;/strong&gt;   &lt;p&gt;When we develop an application in WPF, we want to separate&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;UI in XAML stream &lt;/li&gt;    &lt;li&gt;Data (in POCO object for example) &lt;/li&gt;    &lt;li&gt;Links between UI and Data, interaction logic, etc. ... &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;for example, The &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;Model/ModelView/View&lt;/a&gt; approach try do this.&lt;/p&gt;  &lt;p&gt;One of the technical problem of this type of architecture is &amp;quot;How can i launch code from UI on ModelView ?&amp;quot;&lt;/p&gt;  &lt;p&gt;If I want to launch a simple public method on underneath ModelView by XAML Declaration. It is not very easy.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;MethodBinding&lt;/em&gt;&lt;/strong&gt; approach illustrated in this application help you to do this just with declaration syntax, no more code is necessary&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="font-size: 78%"&gt;Thibaud Bouquely, France, February 2009.&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 130%"&gt;Demo&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Demo application is &lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2009/MethodCommand%7C_V1.00.zip"&gt;Downloaded here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;in Demo tabItem, you can launch this window. It's illustrate different usage of MethodBinding XAML declaration.&lt;/p&gt;  &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dDsO1He2FKk/SYXVSIjFMjI/AAAAAAAAAAs/YRt9THyvJ7Y/s1600-h/Code.PNG"&gt;&lt;img style="width: 320px; height: 266px; cursor: pointer" id="BLOGGER_PHOTO_ID_5297875044180242994" border="0" alt="" src="http://1.bp.blogspot.com/_dDsO1He2FKk/SYXVSIjFMjI/AAAAAAAAAAs/YRt9THyvJ7Y/s320/Code.PNG" /&gt;&lt;/a&gt; =&amp;gt; &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dDsO1He2FKk/SYXRtRll55I/AAAAAAAAAAk/copfOFRRkl0/s1600-h/ScreenShot.PNG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; width: 290px; height: 320px; cursor: pointer" id="BLOGGER_PHOTO_ID_5297871112416651154" border="0" alt="" src="http://2.bp.blogspot.com/_dDsO1He2FKk/SYXRtRll55I/AAAAAAAAAAk/copfOFRRkl0/s320/ScreenShot.PNG" /&gt;&lt;/a&gt;     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 130%"&gt;Tutorial&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create an object with a public method : the method must has no parameter or just one only      &lt;br /&gt;      &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Example :&lt;/em&gt;&lt;/strong&gt;public void MyMethod(); on MyObject class       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Push this object in DataContext of yours WPF controls      &lt;br /&gt;      &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Example :&lt;/em&gt;&lt;/strong&gt;in Window's constructor : this.DataContext = new MyObject();       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Declare link between a button and the previous public Method      &lt;br /&gt;      &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Example :&amp;lt;&lt;/em&gt;&lt;/strong&gt;Button Command=&amp;quot;{f:MethodBinding MyMethod}&amp;quot; &amp;gt;Clic on me       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;No more code :-)      &lt;br /&gt;if you clic on the button, MyMethod() is launch on MyObject instance in DataContext of the button &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 130%"&gt;Other functionality&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If public target method has one parameter, CommandParameter on Button (or ICommandSource control) is too transfered &lt;/li&gt;    &lt;li&gt;If Target object has a Read-only property named MyMethodCanExecute. It's return a boolean value, It used by MethodCommand to manage CanExecute aspect of ICommand system. (rq : target object must be a INotifyPropertyChanged or a DependencyObject/DependancyProperty to use correctly this fonctionnality) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 130%"&gt;TODO list :&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Like BindingOperations static class of WPF, add Static method somewhere to create a MethodBinding by code &lt;/li&gt;    &lt;li&gt;Improve the component ! I just try in this demos, not in real application &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-5964007476396116684?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/5964007476396116684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/5964007476396116684'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2009/02/convert-clr-method-to-icommand-with.html' title='Convert &amp;quot;CLR method&amp;quot; to &amp;quot;ICommand&amp;quot; with just a XAML declaration'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_dDsO1He2FKk/SYXVSIjFMjI/AAAAAAAAAAs/YRt9THyvJ7Y/s72-c/Code.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-3000274622575400819</id><published>2008-11-01T08:40:00.000-07:00</published><updated>2010-02-21T04:45:01.946-08:00</updated><title type='text'>New version of Datagrid with Footer</title><content type='html'>&lt;ul&gt;   &lt;li&gt;News ! : Another approach on WPF 4.0 datagrid : &lt;a href="http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html"&gt;http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;During the PDC 2008, microsoft updates WPF ToolKit with a new version of Datagrid    &lt;br /&gt;    &lt;br /&gt;I just refresh my Footer's version today !     &lt;br /&gt;    &lt;br /&gt;It seems work fine, the zip file is &lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2008/WpfToolKit%7C_WithFooter%7C_v1.00.zip"&gt;dowloaded here&lt;/a&gt; ...     &lt;br /&gt;    &lt;br /&gt;Best Regards     &lt;br /&gt;    &lt;br /&gt;Thibaud     &lt;br /&gt;    &lt;br /&gt;PS : Vincent Sibal give another experimental prototype with Frozen top Row : &lt;a href="http://blogs.msdn.com/vinsibal/archive/2008/10/31/wpf-datagrid-frozen-row-sample.aspx"&gt;http://blogs.msdn.com/vinsibal/archive/2008/10/31/wpf-datagrid-frozen-row-sample.aspx&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;Original source of Datagrid is not modified in this approach ! great !! I don't know if It is possible to do the same thing for Footer column .... not sure ....     &lt;br /&gt;    &lt;br /&gt;&amp;gt;&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Introduction&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;This Datagrid control is experimental. I just try to know If I could add a Footer quickly. It seems is possible but I think a lot of bug exists in this prototype. It was a way for me to look inside the Datagrid and learn new concept and Design pattern for me. I advice to you to launch a Diff Process between original source of WPFToolKit and new version to understand all modification. Best Regards :-) Thibaud Bouquely, France, November 2008.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;History :&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;• 2008/11/2 : new version on v1.0 of WPFToolKit (2008/10/27) without     &lt;br /&gt;CurrentRowIndicator     &lt;br /&gt;I must as some ancestor class for DataGridColumnHeader-Footer and Presenter : I am sure lot of code Header/Footer (presenter or not) should be move in these ancestors, I just do the strict necessary for the prototype.     &lt;br /&gt;The previous version contained CurrentRow indicator In DataGrid control, With new property Datagrid.RowHeaderTemplate, I realize this indicator with special Template in my UserControl ! It is not necessary to change Datagrid Code source to do this ! Great :-)     &lt;br /&gt;• 2008/09/28 : First version on beta WPFToolKit (2008/08/10) with CurrentRowIndicator     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;References :&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;Original version of Datagrid is download here :     &lt;br /&gt;&lt;a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598"&gt;http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;Realease of Oct 27, 2008     &lt;br /&gt;First Post here : &lt;a href="http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=36686"&gt;http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=36686&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;To use this application, click on &amp;quot;Load&amp;quot; button     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Structure of Zip File&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;• License.txt : http://www.codeplex.com/wpf/license Associated license of WPFToolKit     &lt;br /&gt;• Application : This application     &lt;br /&gt;• Test.WpfToolKit : UserControl to Test Datagrid     &lt;br /&gt;• WPFToolKit : Datagrid with changes to include Footer     &lt;br /&gt;• WPFToolKit_2008_10_27 : Original Source of DataGrid     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;TODO list :&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;• Semantic of HeaderVisibility (include FooterVisibility : not perfect ! ;-)     &lt;br /&gt;• Improve the component ! I did not test Style of Footer, template, UIAutomation, etc ...     &lt;br /&gt;• Move some code in DatagridColumnHeaderFooterBase and PresenterBase&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-3000274622575400819?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/3000274622575400819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/3000274622575400819'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2008/11/new-version-of-datagrid-with-footer.html' title='New version of Datagrid with Footer'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-5339728292405481239.post-7138874086354211633</id><published>2008-10-16T10:09:00.000-07:00</published><updated>2010-02-21T04:43:49.303-08:00</updated><title type='text'>WPFToolkit DataGrid with Footer and Current row indicator</title><content type='html'>&lt;h5&gt;News !!&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;New version on WPFToolKit v1.00 : &lt;a href="http://thibaud60.blogspot.com/2008/11/new-version-of-datagrid-with-footer.html"&gt;http://thibaud60.blogspot.com/2008/11/new-version-of-datagrid-with-footer.html&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Another approach on WPF 4.0 datagrid : &lt;a title="http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html" href="http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html"&gt;http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hello    &lt;br /&gt;WPF is great technology and the future of the Windows IHM. But to construct a business application, some advanded controls not exists in .Net 3.50 official framework     &lt;br /&gt;    &lt;br /&gt;Datagrid is one of them.     &lt;br /&gt;    &lt;br /&gt;But recently, Microsoft published on Codeplex web Site &lt;a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14963"&gt;a preview of interrested Datagrid &lt;/a&gt;(WPFToolKit) (and I hope it is the next official datagrid)     &lt;br /&gt;    &lt;br /&gt;To try understand more the inside source code, I realized a small prototype to add in current version a Footer row and Current Row Indicator.     &lt;br /&gt;    &lt;br /&gt;My original post in CodePlex web Site is &lt;a href="http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=36686"&gt;here&lt;/a&gt;.     &lt;br /&gt;    &lt;br /&gt;If you want to read this prototype and play with it, you can find &lt;a href="http://cid-53ab3f68fbc307c8.skydrive.live.com/self.aspx/.Public/Blogspot/Archives/2008/WpfToolKit%7C_WithFooter.zip"&gt;the source zip file here&lt;/a&gt;.     &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;Best regards     &lt;br /&gt;    &lt;br /&gt;Thibaud     &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_dDsO1He2FKk/SPd64anjChI/AAAAAAAAAAM/As2poaIolGo/s1600-h/ScreenShot1.JPG"&gt;&lt;img style="margin: 0px 10px 10px 0px; float: left; cursor: hand" id="BLOGGER_PHOTO_ID_5257806199614802450" border="0" alt="" src="http://2.bp.blogspot.com/_dDsO1He2FKk/SPd64anjChI/AAAAAAAAAAM/As2poaIolGo/s320/ScreenShot1.JPG" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5339728292405481239-7138874086354211633?l=thibaud60.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/7138874086354211633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5339728292405481239/posts/default/7138874086354211633'/><link rel='alternate' type='text/html' href='http://thibaud60.blogspot.com/2008/10/wpftoolkit-datagrid-with-footer-and.html' title='WPFToolkit DataGrid with Footer and Current row indicator'/><author><name>Thibaud</name><uri>http://www.blogger.com/profile/03063839278956085177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_dDsO1He2FKk/SPd64anjChI/AAAAAAAAAAM/As2poaIolGo/s72-c/ScreenShot1.JPG' height='72' width='72'/></entry></feed>
