<?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-38601416</id><updated>2012-01-26T15:10:45.624+02:00</updated><category term='disassemble'/><category term='CheckListBox'/><category term='Cryptography'/><category term='LINQ'/><category term='obfuscation'/><category term='Binding'/><category term='RadioButton'/><category term='PEM'/><category term='Password TextBox'/><category term='VS 2010'/><category term='MaskedText'/><category term='XML'/><category term='.NET Framework'/><category term='Security'/><category term='.NET Framework 3.5'/><category term='RSA'/><category term='XAML'/><category term='Reporting'/><category term='.NET Framework 2.0'/><category term='Custom User Controls'/><category term='RadMaksedTextBox'/><category term='MS SQL Server 2000'/><category term='Telerik'/><category term='WCF'/><category term='DataSet'/><category term='Close TabPage'/><category term='PasswordBox'/><category term='Xceed'/><category term='Grid'/><category term='T-SQL'/><category term='WPF'/><category term='middle click'/><category term='first step'/><category term='Silverlight'/><title type='text'>Peter's Tips &amp; Tricks</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-38601416.post-653127475916558190</id><published>2010-08-27T18:44:00.000+03:00</published><updated>2010-08-27T18:44:30.252+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RSA'/><category scheme='http://www.blogger.com/atom/ns#' term='Cryptography'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='PEM'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>Convert RSA public/private key from XML to PEM format (.NET) (Part 2)</title><content type='html'>In my previous post I've shown how to convert the public key of an XML formatted RSA key to the more widely used PEM format. The only limitation of the solution was that since it utilizes the Cryptographic Next Generation (CNG) algorithms it is usable only on Windows 7 and Windows Server 2008 R2. &lt;br /&gt;&lt;br /&gt;So bellow I'll demonstrate a solution that works under all operating systems. Also as an extra the solution bellow can convert the private key as well ;) Both the public and the private keys exported by the functions bellow are parsed by OpenSSL!&lt;br /&gt;&lt;br /&gt;You can find the compiled source &lt;a href="http://cid-2d4f58bb946b6cd0.office.live.com/self.aspx/Public/RsaXML2PEM^_v2.rar"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;C#:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] RSA_OID = &lt;br /&gt;{ 0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0 }; &lt;span class="rem"&gt;// Object ID for RSA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="rem"&gt;// Corresponding ASN identification bytes&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt; INTEGER = 0x2;&lt;br /&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt; SEQUENCE = 0x30;&lt;br /&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt; BIT_STRING = 0x3;&lt;br /&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt; OCTET_STRING = 0x4;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ConvertPublicKey(RSAParameters param)&lt;br /&gt;{&lt;br /&gt;    List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; arrBinaryPublicKey = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;    arrBinaryPublicKey.InsertRange(0, param.Exponent);&lt;br /&gt;    arrBinaryPublicKey.Insert(0, (&lt;span class="kwrd"&gt;byte&lt;/span&gt;)arrBinaryPublicKey.Count);&lt;br /&gt;    arrBinaryPublicKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPublicKey.InsertRange(0, param.Modulus);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey, param.Modulus.Length);&lt;br /&gt;    arrBinaryPublicKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey, arrBinaryPublicKey.Count);&lt;br /&gt;    arrBinaryPublicKey.Insert(0, SEQUENCE);&lt;br /&gt;&lt;br /&gt;    arrBinaryPublicKey.Insert(0, 0x0); &lt;span class="rem"&gt;// Add NULL value&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey, arrBinaryPublicKey.Count);&lt;br /&gt;&lt;br /&gt;    arrBinaryPublicKey.Insert(0, BIT_STRING);&lt;br /&gt;    arrBinaryPublicKey.InsertRange(0, RSA_OID);&lt;br /&gt;&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey, arrBinaryPublicKey.Count);&lt;br /&gt;&lt;br /&gt;    arrBinaryPublicKey.Insert(0, SEQUENCE);&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; System.Convert.ToBase64String(arrBinaryPublicKey.ToArray());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ConvertPrivateKey(RSAParameters param)&lt;br /&gt;{&lt;br /&gt;    List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; arrBinaryPrivateKey = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.InverseQ);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.InverseQ.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.DQ);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.DQ.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.DP);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.DP.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.Q);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.Q.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.P);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.P.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.D);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.D.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.Exponent);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.Exponent.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.InsertRange(0, param.Modulus);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, param.Modulus.Length);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, 0x00);&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, 1);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, INTEGER);&lt;br /&gt;&lt;br /&gt;    AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPrivateKey, arrBinaryPrivateKey.Count);&lt;br /&gt;    arrBinaryPrivateKey.Insert(0, SEQUENCE);&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; System.Convert.ToBase64String(arrBinaryPrivateKey.ToArray());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; arrBinaryData, &lt;span class="kwrd"&gt;int&lt;/span&gt; nLen)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (nLen &amp;lt;= &lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue)&lt;br /&gt;    {&lt;br /&gt;        arrBinaryData.Insert(0, Convert.ToByte(nLen));&lt;br /&gt;        arrBinaryData.Insert(0, 0x81); &lt;span class="rem"&gt;//This byte means that the length fits in one byte&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        arrBinaryData.Insert(0, Convert.ToByte(nLen % (&lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue + 1)));&lt;br /&gt;        arrBinaryData.Insert(0, Convert.ToByte(nLen / (&lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue + 1)));&lt;br /&gt;        arrBinaryData.Insert(0, 0x82); &lt;span class="rem"&gt;//This byte means that the length fits in two byte&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-653127475916558190?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/653127475916558190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=653127475916558190' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/653127475916558190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/653127475916558190'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2010/08/convert-rsa-publicprivate-key-from-xml.html' title='Convert RSA public/private key from XML to PEM format (.NET) (Part 2)'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-663042619892388231</id><published>2010-08-06T17:54:00.006+03:00</published><updated>2010-08-27T18:29:55.978+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RSA'/><category scheme='http://www.blogger.com/atom/ns#' term='Cryptography'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='PEM'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>Convert RSA public key from XML to PEM format (.NET) (Part 1)</title><content type='html'>Probably the people working with asymmetric cryptography have struggled for a way to convert the XML format of the RSA public key to the more widely used PEM format. Although there is a solution for the reverse transformation (from PEM to XML) on the following address &lt;a href="http://www.jensign.com/opensslkey/opensslkey.cs"&gt;http://www.jensign.com/opensslkey/opensslkey.cs&lt;/a&gt; I have not found anywhere a solution to this problem. &lt;br /&gt;&lt;br /&gt;So after a bit of reading and examining the code in the above mentioned link I've come up with a small code that does the conversion and the resulting key is parsed OK from OpenSSL.&lt;br /&gt;&lt;br /&gt;NOTE: you will need to download and use the assemblies from &lt;a href="http://clrsecurity.codeplex.com/"&gt;http://clrsecurity.codeplex.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;NOTE2: The code bellow only works under Windows 7 and Windows Server 2008 R2, because it uses the Cryptographic Next Generation (CNG) that were added only to those operating systems.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;C#:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Security.Cryptography;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Cryptography.X509Certificates;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication1&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            RSACng rsa = &lt;span class="kwrd"&gt;new&lt;/span&gt; RSACng();&lt;br /&gt;            X509Certificate2 cert;&lt;br /&gt;            List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; arrBinaryPublicKey = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] oid = &lt;br /&gt;            { 0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0 }; &lt;span class="rem"&gt;// Object ID for RSA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//rsa.FromXmlString(xmlFormatedRSAKey);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            cert = rsa.Key.CreateSelfSignedCertificate(&lt;span class="kwrd"&gt;new&lt;/span&gt; X500DistinguishedName(&lt;span class="str"&gt;"CN=something"&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//Transform the public key to PEM Base64 Format&lt;/span&gt;&lt;br /&gt;            arrBinaryPublicKey = cert.PublicKey.EncodedKeyValue.RawData.ToList();&lt;br /&gt;            arrBinaryPublicKey.Insert(0, 0x0); &lt;span class="rem"&gt;// Add NULL value&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            CalculateAndAppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey);&lt;br /&gt;&lt;br /&gt;            arrBinaryPublicKey.Insert(0, 0x3);&lt;br /&gt;            arrBinaryPublicKey.InsertRange(0, oid);&lt;br /&gt;&lt;br /&gt;            CalculateAndAppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; arrBinaryPublicKey);&lt;br /&gt;&lt;br /&gt;            arrBinaryPublicKey.Insert(0, 0x30);&lt;br /&gt;            &lt;span class="rem"&gt;//End Transformation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            Console.WriteLine();&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"-----BEGIN PUBLIC KEY-----"&lt;/span&gt;);&lt;br /&gt;            Console.WriteLine(System.Convert.ToBase64String(arrBinaryPublicKey.ToArray()));&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"-----END PUBLIC KEY-----"&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CalculateAndAppendLength(&lt;span class="kwrd"&gt;ref&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; arrBinaryData)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;int&lt;/span&gt; nLen;&lt;br /&gt;            nLen = arrBinaryData.Count;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (nLen &amp;lt;= &lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue)&lt;br /&gt;            {&lt;br /&gt;                arrBinaryData.Insert(0, Convert.ToByte(nLen));&lt;br /&gt;                arrBinaryData.Insert(0, 0x81); &lt;span class="rem"&gt;//This byte means that the length fits in one byte&lt;/span&gt;&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                arrBinaryData.Insert(0, Convert.ToByte(nLen % (&lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue + 1)));&lt;br /&gt;                arrBinaryData.Insert(0, Convert.ToByte(nLen / (&lt;span class="kwrd"&gt;byte&lt;/span&gt;.MaxValue + 1)));&lt;br /&gt;                arrBinaryData.Insert(0, 0x82); &lt;span class="rem"&gt;//This byte means that the length fits in two byte&lt;/span&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Compiled source available &lt;a href="http://cid-2d4f58bb946b6cd0.office.live.com/self.aspx/Public/RSAxml2pem.rar"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-663042619892388231?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/663042619892388231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=663042619892388231' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/663042619892388231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/663042619892388231'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2010/08/convert-rsa-public-key-from-xml-to-pem.html' title='Convert RSA public key from XML to PEM format (.NET) (Part 1)'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-8772444506497257323</id><published>2010-01-19T18:57:00.000+02:00</published><updated>2010-01-20T19:50:28.645+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RadMaksedTextBox'/><category scheme='http://www.blogger.com/atom/ns#' term='MaskedText'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='Telerik'/><category scheme='http://www.blogger.com/atom/ns#' term='Binding'/><title type='text'>Binding MaskedText property of Telerik Silverlight RadMaskedTextBox</title><content type='html'>If you have used Telerik's RadMaskedTextBox for Silverlight most probably in some cases you have needed to bind in TwoWay mode the MaskedText property of the control (for example for Phones, SSNs, etc. that need to be saved with the punctuation). And most probably you were surprised that you cannot do this because the MaskedText property is readonly. We've asked Telerik whether they are considering to implement such a functionality, but currently there is no definite answer to this. &lt;br /&gt;&lt;br /&gt;So here is how to extend they RadMaskedTextBox so you can do your work:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;VB:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Windows.Data&lt;br /&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; Telerik.Windows&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; RadMaskedTextBoxExtended&lt;br /&gt;    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Telerik.Windows.Controls.RadMaskedTextBox&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Private&lt;/span&gt; m_bIsValueChangingIn &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt; = &lt;span class="kwrd"&gt;False&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span class="preproc"&gt;#Region&lt;/span&gt; &lt;span class="str"&gt;" Dependency Property "&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; ValueMaskProperty &lt;span class="kwrd"&gt;As&lt;/span&gt; DependencyProperty = _&lt;br /&gt;    DependencyProperty.Register(&lt;span class="str"&gt;"ValueMask"&lt;/span&gt; _&lt;br /&gt;                                , &lt;span class="kwrd"&gt;GetType&lt;/span&gt;(&lt;span class="kwrd"&gt;String&lt;/span&gt;) _&lt;br /&gt;                                , &lt;span class="kwrd"&gt;GetType&lt;/span&gt;(RadMaskedTextBoxExtended) _&lt;br /&gt;                                , &lt;span class="kwrd"&gt;New&lt;/span&gt; PropertyMetadata(&lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; ValueMaskChanged) _&lt;br /&gt;                                )&lt;br /&gt;&lt;span class="preproc"&gt;#End Region&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#Region&lt;/span&gt; &lt;span class="str"&gt;" Constructor "&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()&lt;br /&gt;        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;()&lt;br /&gt;        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; &lt;span class="kwrd"&gt;Me&lt;/span&gt;.ValueChanged, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; OnValueChanged&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#End Region&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#Region&lt;/span&gt; &lt;span class="str"&gt;" Properties "&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; ValueMask() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;CStr&lt;/span&gt;(&lt;span class="kwrd"&gt;Me&lt;/span&gt;.GetValue(ValueMaskProperty))&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;)&lt;br /&gt;            &lt;span class="kwrd"&gt;Me&lt;/span&gt;.SetValue(ValueMaskProperty, value)&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; IsValueChangingIn() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;Return&lt;/span&gt; m_bIsValueChangingIn&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;)&lt;br /&gt;            m_bIsValueChangingIn = value&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#End Region&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#Region&lt;/span&gt; &lt;span class="str"&gt;" Change Tracking Events "&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; OnValueChanged(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; RadRoutedEventArgs)&lt;br /&gt;        m_bIsValueChangingIn = &lt;span class="kwrd"&gt;True&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;Me&lt;/span&gt;.ValueMask = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.MaskedText&lt;br /&gt;        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; oBindingExpression &lt;span class="kwrd"&gt;As&lt;/span&gt; BindingExpression = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.GetBindingExpression(ValueMaskProperty)&lt;br /&gt;        &lt;br /&gt;        &lt;span class="kwrd"&gt;If&lt;/span&gt; oBindingExpression IsNot &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;&lt;br /&gt;            oBindingExpression.UpdateSource()&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;&lt;br /&gt;        m_bIsValueChangingIn = &lt;span class="kwrd"&gt;False&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ValueMaskChanged(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; d &lt;span class="kwrd"&gt;As&lt;/span&gt; DependencyObject, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; DependencyPropertyChangedEventArgs)&lt;br /&gt;        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; txtRadMaskedTextBoxExtended &lt;span class="kwrd"&gt;As&lt;/span&gt; RadMaskedTextBoxExtended = &lt;span class="kwrd"&gt;CType&lt;/span&gt;(d, RadMaskedTextBoxExtended)&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; Equals(e.OldValue, e.NewValue) _&lt;br /&gt;        &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; txtRadMaskedTextBoxExtended.IsValueChangingIn _&lt;br /&gt;        &lt;span class="kwrd"&gt;Then&lt;/span&gt;&lt;br /&gt;            txtRadMaskedTextBoxExtended.Value = e.NewValue&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;span class="preproc"&gt;#End Region&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Then instead of using their control, just use RadMaskedTextBoxExtended and use the ValueMask property to bind the business object property that must contain the masked text. &lt;br /&gt;&lt;br /&gt;This worked quite well in my case :)&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-8772444506497257323?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/8772444506497257323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=8772444506497257323' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8772444506497257323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8772444506497257323'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2010/01/binding-maskedtext-property-of-telerik.html' title='Binding MaskedText property of Telerik Silverlight RadMaskedTextBox'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-1044331129672654025</id><published>2009-12-05T20:57:00.003+02:00</published><updated>2009-12-08T14:15:59.058+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Reporting'/><category scheme='http://www.blogger.com/atom/ns#' term='VS 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Telerik'/><title type='text'>How to hack Telerik Reporting Q3 to be supported under Visual Studio 2010 Beta 2</title><content type='html'>Several weeks after Visual Studio 2010 Beta 2 has become public Telerik released their Q3 release. And despite the fact that their Silverlight Controls setup fully supports VS 2010 B2, their reporting setup has no support at all! On community questions whether they will support VS 2010, their answer is that their Reporting will not support Beta IDEs and they will announce their support once VS 2010 goes official (&lt;a href="http://www.telerik.com/community/forums/reporting/telerik-reporting/a-problem-instaling-telerik-reporting-in-vs-2010-beta-2.aspx"&gt;Link&lt;/a&gt;). This means that there will be no support for VS 2010 for another 3 months in the best case (rumors say that VS 2010 will be released at the end or March 2010). &lt;br /&gt;&lt;br /&gt;And seeing more people (including myself) move on VS 2010 B2 for their main environment for development (especially for Silverlight) having at least some support of Telerik Reporting for VS 2010 is a must. Here are some steps that can almost fully integrate Telerik Reporting in VS 2010 (NOTE: All the steps bellow are valid if you have VS 2008 installed and you have already installed the Telerik Reporting setup):&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Registering Telerik Reporting Report File Template&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Copy &lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Telerik_Reporting_Q3.zip"&lt;/i&gt; to the following locations&lt;br /&gt;&lt;br /&gt;&lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\VisualBasic\Reporting"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\VisualBasic"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Copy &lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Telerik_Reporting_Q3.zip"&lt;/i&gt; to the following locations&lt;br /&gt;&lt;br /&gt;&lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Reporting"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Run the following from an administrative command prompt: &lt;i&gt;"%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /installvstemplates&lt;/i&gt; and wait for the command to complete&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;b&gt;Adding Telerik Reporting controls to VS Toolbox&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;While viewing a report in design mode, open the toolbox and add a new tab naming it &lt;i&gt;Telerik Reporting&lt;/i&gt;. &lt;/li&gt;&lt;li&gt;Right click the newly created tab and select "Choose Items..."&lt;/li&gt;&lt;li&gt;Wait for the window to show up (it takes some time) and then click "Browse..."&lt;/li&gt;&lt;li&gt;Navigate to &lt;i&gt;"%ProgramFiles\Telerik\Reporting Q3 2009\Bin"&lt;/i&gt;, select &lt;i&gt;Telerik.Reporting.dll&lt;/i&gt; and press "Open"&lt;/li&gt;&lt;li&gt;On the "Choose Toolbox Items" window press OK&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Following the above two procedures will enable you to add new reports and drag items from the toolbox to a report in VS 2010. &lt;br /&gt;&lt;br /&gt;The things that I have not managed to enable (YET! :)) under VS 2010 B2 is the Data Explorer window. So you will not be able to directly Drag'n'Drop fields from your data source to the report. Instead of that just add a TextBox control and use the Expression function. &lt;br /&gt;&lt;br /&gt;Other than that Telerik Reporting works fine under Visual Studio 2010. &lt;br /&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;UPDATE (12/08/2009): &lt;/i&gt;&lt;/b&gt; In order to have the Table and Crosstab Wizards you have to add also the following assembly from GAC to the Toolbox Items:&lt;br /&gt;&lt;i&gt;%SystemDirve%\Windows\assembly\GAC_MSIL\Telerik.Reporting.Design.Components\&amp;lt;ReportingVersion&amp;gt;_a9d7983dfcc261be\Telerik.Reporting.Design.Components.dll&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-1044331129672654025?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/1044331129672654025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=1044331129672654025' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1044331129672654025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1044331129672654025'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2009/12/how-to-hack-telerik-reporting-q3-to-be.html' title='How to hack Telerik Reporting Q3 to be supported under Visual Studio 2010 Beta 2'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-1260711355165974240</id><published>2008-11-23T12:31:00.010+02:00</published><updated>2009-02-03T11:12:28.380+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><category scheme='http://www.blogger.com/atom/ns#' term='MS SQL Server 2000'/><title type='text'>How to extract IDENTITY_SEED and IDENTITY_INCREMENT from autoval column in syscolumns</title><content type='html'>There are many hints on the internet that in the autoval column in the system table syscolumns in MS SQL Server 2000 it is stored the identity seed and identity increment values for columns that have been set as identity. Problem is there are little clues on how to extract those values from that column, because the data is stored as a binary value. &lt;br /&gt;&lt;br /&gt;After some testing on my side I found that the autoval column can split in four parts, two of which represent IDENTITY_SEED and IDENTITY_INCREMENT  values. But there is a catch - those binary data of each segment must be first reversed and then the values can be extracted. Here is the script:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;T-SQL:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; tCol.[name]&lt;br /&gt;        , IDENTITY_INCREMENT = &lt;span class="kwrd"&gt;CAST&lt;/span&gt;(&lt;span class="kwrd"&gt;CAST&lt;/span&gt;(REVERSE(&lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(autoval, 5, 4)) &lt;span class="kwrd"&gt;AS&lt;/span&gt; VARBINARY(8)) &lt;span class="kwrd"&gt;AS&lt;/span&gt; BIGINT)&lt;br /&gt;        , IDENTITY_SEED = &lt;span class="kwrd"&gt;CAST&lt;/span&gt;(&lt;span class="kwrd"&gt;CAST&lt;/span&gt;(REVERSE(&lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(autoval, 9, 4)) &lt;span class="kwrd"&gt;AS&lt;/span&gt; VARBINARY(8)) &lt;span class="kwrd"&gt;AS&lt;/span&gt; BIGINT)&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt; [syscolumns] tCol&lt;br /&gt;&lt;span class="kwrd"&gt;WHERE&lt;/span&gt; tCol.autoval &lt;span class="kwrd"&gt;IS&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;  &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;You would ask: "Why the heck to we need such complex query when there are built in function like OBJECTPROPERTY and COLUMNPRPERTY that retrieve those values?". Well if you are working with linked servers, and you want to retrieve the values from the remote server and you are connected to the local one, those functions do not work ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-1260711355165974240?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/1260711355165974240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=1260711355165974240' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1260711355165974240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1260711355165974240'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/11/how-to-extract-identityseed-and.html' title='How to extract IDENTITY_SEED and IDENTITY_INCREMENT from autoval column in syscolumns'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-8503429608225747190</id><published>2008-11-23T12:07:00.003+02:00</published><updated>2008-11-26T13:43:44.659+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework 3.5'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><title type='text'>Simple Tile Horizontally / Tile Vertically functionality in WPF</title><content type='html'>Here is the main idea: We will have a grid with three rows and three columns. The middle column/row will be used to store the GridSplitter that will allow us to resize columns/rows once we are in one of the tile modes. So basically when we are in Tile Horizontally we will span the textboxes (the same can be doen with any other control) to take all the three columns. And if we are in Tile Vertically mode we will change the columns of the controls and will Span the controls so they take all the rows. &lt;br /&gt;&lt;br /&gt;But enough talking, lets get to work:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;XAML:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBoxTop"&lt;/span&gt;&lt;br /&gt;             &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;                &lt;br /&gt;             &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt;&lt;br /&gt;             &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GridSplitter&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="split"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="attr"&gt;ResizeDirection&lt;/span&gt;&lt;span class="kwrd"&gt;="Rows"&lt;/span&gt;&lt;br /&gt;                  &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBoxBottom"&lt;/span&gt;&lt;br /&gt;             &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;                &lt;br /&gt;             &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt;&lt;br /&gt;             &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;And here is the code that will change to one of the modes:&lt;br /&gt;&lt;div class="code"&gt;VB Code Behind:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; cmdTileHorizontally_Click(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; System.&lt;span class="kwrd"&gt;Object&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.RoutedEventArgs)&lt;br /&gt;    Grid.SetColumn(txtTextBoxTop, 0)&lt;br /&gt;    Grid.SetRow(txtTextBoxTop, 0)&lt;br /&gt;    Grid.SetColumnSpan(txtTextBoxTop, 3)&lt;br /&gt;    Grid.SetRowSpan(txtTextBoxTop, 1)&lt;br /&gt;&lt;br /&gt;    Grid.SetColumn(split, 0)&lt;br /&gt;    Grid.SetRow(split, 1)&lt;br /&gt;    Grid.SetColumnSpan(split, 3)&lt;br /&gt;    Grid.SetRowSpan(split, 1)&lt;br /&gt;    split.ResizeDirection = GridResizeDirection.Rows&lt;br /&gt;&lt;br /&gt;    Grid.SetColumn(txtTextBoxBottom, 0)&lt;br /&gt;    Grid.SetRow(txtTextBoxBottom, 2)&lt;br /&gt;    Grid.SetColumnSpan(txtTextBoxBottom, 3)&lt;br /&gt;    Grid.SetRowSpan(txtTextBoxBottom, 1)&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; cmdTileVerically_Click(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; System.&lt;span class="kwrd"&gt;Object&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.RoutedEventArgs)&lt;br /&gt;    Grid.SetColumn(txtTextBoxTop, 0)&lt;br /&gt;    Grid.SetRow(txtTextBoxTop, 0)&lt;br /&gt;    Grid.SetColumnSpan(txtTextBoxTop, 1)&lt;br /&gt;    Grid.SetRowSpan(txtTextBoxTop, 3)&lt;br /&gt;&lt;br /&gt;    Grid.SetColumn(split, 1)&lt;br /&gt;    Grid.SetRow(split, 0)&lt;br /&gt;    Grid.SetColumnSpan(split, 1)&lt;br /&gt;    Grid.SetRowSpan(split, 3)&lt;br /&gt;    split.ResizeDirection = GridResizeDirection.Columns&lt;br /&gt;&lt;br /&gt;    Grid.SetColumn(txtTextBoxBottom, 2)&lt;br /&gt;    Grid.SetRow(txtTextBoxBottom, 0)&lt;br /&gt;    Grid.SetColumnSpan(txtTextBoxBottom, 1)&lt;br /&gt;    Grid.SetRowSpan(txtTextBoxBottom, 3)&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;It is simple as that! And as a bonus you even get resizing :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-8503429608225747190?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/8503429608225747190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=8503429608225747190' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8503429608225747190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8503429608225747190'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/11/simple-tile-horizontallytile-vertically.html' title='Simple Tile Horizontally / Tile Vertically functionality in WPF'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-6030072424896101458</id><published>2008-10-11T16:58:00.004+03:00</published><updated>2010-10-11T10:11:42.920+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RadioButton'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework 3.5'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='Binding'/><title type='text'>Binding IsChecked property of RadioButton in WPF</title><content type='html'>If you have tried to bind the RadioButton's IsChecked property in WPF to an object, you have most likely experienced the following problem: In OneWay bindings it works great. But if you have more than one RadioButtons binded TwoWay and you click on an unchecked one, you were expecting that the object to which the previously checked RadioButton was binded to receive the  value of False. But you were wrong in your expectations. That's because for some reasons Microsoft does not obey bindings and does not pass the False value to the DependencyProperty and instead of that they just assign the value False directly to the property, which ruins the binding. &lt;br /&gt;&lt;br /&gt;There are many proposed solutions to this around the internet, problem with all those is that they do not work with dynamically generated controls. So since I had to find a way to make this working with dynamic controls, decided to make a wrapper of the real RadioButton which will correctly Bind in two ways. Here is the code for the wrapper: &lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Printing;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Controls;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Controls.Primitives;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Documents;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Input;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Interop;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Media;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.Win32;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Controls&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RadioButtonExtended : RadioButton&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; m_bIsChanging = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; RadioButtonExtended()&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Checked += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(RadioButtonExtended_Checked);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Unchecked += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(RadioButtonExtended_Unchecked);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; RadioButtonExtended_Unchecked(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!m_bIsChanging)&lt;br /&gt;                &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsCheckedReal = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; RadioButtonExtended_Checked(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!m_bIsChanging)&lt;br /&gt;                &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsCheckedReal = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt;? IsCheckedReal&lt;br /&gt;        {&lt;br /&gt;            get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;?)GetValue(IsCheckedRealProperty); }&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                SetValue(IsCheckedRealProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="rem"&gt;// Using a DependencyProperty as the backing store for IsCheckedReal. This enables animation, styling, binding, etc...&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty IsCheckedRealProperty =&lt;br /&gt;        DependencyProperty.Register(&lt;span class="str"&gt;"IsCheckedReal"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;bool&lt;/span&gt;?), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RadioButtonExtended),&lt;br /&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; FrameworkPropertyMetadata(&lt;span class="kwrd"&gt;false&lt;/span&gt;, FrameworkPropertyMetadataOptions.Journal |&lt;br /&gt;        FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,&lt;br /&gt;        IsCheckedRealChanged));&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; IsCheckedRealChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            m_bIsChanging = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;            ((RadioButtonExtended)d).IsChecked = (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)e.NewValue;&lt;br /&gt;            m_bIsChanging = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;So now all you have to do is to use the ExtendedRadioButton instead of the built-in one and bind to the IsCheckedReal property instead of the IsChecked one. &lt;br /&gt;Enjoy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-6030072424896101458?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/6030072424896101458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=6030072424896101458' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/6030072424896101458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/6030072424896101458'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/10/binding-ischecked-property-of.html' title='Binding IsChecked property of RadioButton in WPF'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-6110315559213111310</id><published>2008-08-27T21:55:00.002+03:00</published><updated>2008-11-16T17:45:27.948+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework 3.5'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Mysteries: The Distinct Function</title><content type='html'>Recently I had to use the Distinct function introduced in LINQ. My surprise was that depending on where you put the Distinct clause you will receive different results. &lt;br /&gt;&lt;br /&gt;Let us take the following example: Let &lt;i&gt;dtAnswers&lt;/i&gt; be a DataTable that has two columns, named &lt;i&gt;answer_value&lt;/i&gt; and &lt;i&gt;answer_comment&lt;/i&gt;. What I was seeking as a result was to return the count of the different answer_value values from all the rows. So knowing how it is done in SQL, I've wrote the following LINQ query in code:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; nDifferentValues &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = _&lt;br /&gt;(From answer &lt;span class="kwrd"&gt;in&lt;/span&gt; dtAnswers.Rows _&lt;br /&gt;Distinct &lt;span class="kwrd"&gt;Select&lt;/span&gt; answer(&lt;span class="str"&gt;"answer_value"&lt;/span&gt;).ToString()).Count()&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;My surprise was that this will return always the same thing, no matter what rows I have and what values i have in the &lt;i&gt;answer_value&lt;/i&gt; column. So after struggling several hours I've decided to try the Function syntax of LINQ:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; nDifferentValues &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = _&lt;br /&gt;(From answer &lt;span class="kwrd"&gt;in&lt;/span&gt; dtAnswers.Rows _&lt;br /&gt;&lt;span class="kwrd"&gt;Select&lt;/span&gt; answer(&lt;span class="str"&gt;"answer_value"&lt;/span&gt;).ToString()).Distinct.Count()&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Now this returns results correctly. &lt;br /&gt;My guess is that the first query computes distinct on the rows first (by reference) and after that from the result selects &lt;i&gt;answer("answer_value").ToString()&lt;/i&gt;. While the second query first selects &lt;i&gt;answer("answer_value").ToString()&lt;/i&gt; and after that computes distinct.  &lt;br /&gt;&lt;br /&gt;So be careful where you put you LINQ functions ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-6110315559213111310?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/6110315559213111310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=6110315559213111310' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/6110315559213111310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/6110315559213111310'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/08/linq-mysteries-distinct-function.html' title='LINQ Mysteries: The Distinct Function'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-3940211199033203593</id><published>2008-06-14T18:35:00.009+03:00</published><updated>2008-11-16T17:48:49.393+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='Xceed'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>Having different CellEditor for different rows (Xceed WPF Grid)</title><content type='html'>Currently I needed to make an Xceed WPF Grid to have different CellEditors for one column for different rows based on a condition (in my case the condition was the content of the cell). I've found no info for a similar situation on Xceed's Forums. I've tried using the CellContentTemplateSelector for that column but after some tests I've noticed that when user types in the cell for that column the template disappears. And this was unacceptable. After some brainstorming and with a small hint from Xceed Support I was able to make a solution. I'll present it to you in this article.&lt;br /&gt;&lt;br /&gt;This solution utilizes WPF DataTriggers. So if you are not very familiar with them please read &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx"&gt;the related articles on MSDN&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;CellEditor.xaml&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xcdg:CellEditor&lt;/span&gt; &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;="CellEditorSelector"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xcdg:CellEditor.EditTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt; &lt;span class="attr"&gt;Orientation&lt;/span&gt;&lt;span class="kwrd"&gt;="Vertical"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBox"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="lstCombo"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CheckBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="chkCheckBox"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt; &lt;span class="attr"&gt;Binding&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}&lt;br /&gt;                                                , Path=Content&lt;br /&gt;                                                , Mode=OneWay}"&lt;/span&gt;&lt;br /&gt;                                                &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="txt"&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="lstCombo"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="chkCheckBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt; &lt;span class="attr"&gt;Binding&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}&lt;br /&gt;                                                , Path=Content&lt;br /&gt;                                                , Mode=OneWay}"&lt;/span&gt;&lt;br /&gt;                                                &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="lst"&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="lstCombo"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="chkCheckBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt; &lt;span class="attr"&gt;Binding&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}&lt;br /&gt;                                                , Path=Content&lt;br /&gt;                                                , Mode=OneWay}"&lt;/span&gt;&lt;br /&gt;                                                &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="chk"&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="txtTextBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="lstCombo"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Collapsed"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="chkCheckBox"&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Visibility"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTrigger&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;xcdg:CellEditor.EditTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;xcdg:CellEditor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;By assigning the above given CellEditor to a column of and Xceed WPF Grid it will change the editor of the cell to a TextBox if the text in the cell is "txt", to a ComboBox if the text in the cell is "lst" and to a CheckBox if the text in the cell is "chk". By default the TextBox will be displayed. &lt;br /&gt;&lt;br /&gt;This is a very simple example. I'll leave to your imagination what else you can do with a similar CellEditor. You can have very complex conditions to choose which template to show. All you have to do is encapsulate the logic in a method and bind to the method in the DataTrigger.Binding property. &lt;br /&gt;&lt;br /&gt;Enjoy the Power WPF!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-3940211199033203593?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/3940211199033203593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=3940211199033203593' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3940211199033203593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3940211199033203593'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/06/having-different-celleditor-for.html' title='Having different CellEditor for different rows (Xceed WPF Grid)'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-7288738913011095124</id><published>2008-04-26T22:06:00.011+03:00</published><updated>2008-04-26T23:16:30.579+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework 3.5'/><category scheme='http://www.blogger.com/atom/ns#' term='DataSet'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Passing DataSet to a WCF Method</title><content type='html'>Recently I've made a simple WCF service that had a method that takes a MemoryStream parameter. After some time I had to add another method that should take a whole DataSet as parameter. And then my problems begun!&lt;br /&gt;&lt;br /&gt;After I've added the method and refreshed the service reference of my client the proxy class generator decided to create his own MemoryStream class in the namespace of my WCF service! Then I knew that the true evil of DataSets is back (for more informations see &lt;a href="http://www.hanselman.com/blog/CommentView.aspx?guid=d88f7539-10d8-4697-8c6e-1badb08bb3f5#commentstart"&gt;Scott Hanselmann's post about using DataSets in web services&lt;/a&gt;). The solution - use the DataSet's methods to get the data in XML format and pass the XML string instead of the DataSet itself to the service. Here is a sample code:&lt;br /&gt;&lt;div class="code"&gt;IService.vb:&lt;div class="innercode"&gt;&amp;lt;ServiceContract()&amp;gt; _&lt;br /&gt;&lt;span style="color:blue;"&gt;Public Interface&lt;/span&gt; IService&lt;br /&gt;  &amp;lt;OperationContract()&amp;gt; _&lt;br /&gt;&lt;span style="color:blue;"&gt;        Function &lt;/span&gt;PassDataSet(&lt;span style="color:blue;"&gt; _&lt;br /&gt;             ByVal &lt;/span&gt;sXMLSchema &lt;span style="color:blue;"&gt;As String &lt;span style="color: rgb(0, 0, 0);"&gt;_&lt;/span&gt;&lt;br /&gt;         &lt;/span&gt;    , &lt;span style="color:blue;"&gt;ByVal &lt;/span&gt;sXML &lt;span style="color:blue;"&gt;As String&lt;/span&gt;) &lt;span style="color:blue;"&gt;As Boolean&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;br /&gt;End Interface&lt;/span&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Note that because we do not know the schema of the DataSet in the service we also pass the XML schema of the DataSet.&lt;br /&gt;&lt;div class="code"&gt;Service.vb:&lt;div class="innercode"&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;Public Class&lt;/span&gt; Service&lt;br /&gt;&lt;span style="color:blue;"&gt;Implements &lt;/span&gt;IService&lt;br /&gt;&lt;span style="color:blue;"&gt;Public Function &lt;/span&gt;PassDataSet( _&lt;br /&gt;  &lt;span style="color:blue;"&gt;ByVal &lt;/span&gt;sXMLSchema &lt;span style="color:blue;"&gt;As String&lt;/span&gt; _&lt;br /&gt;  , &lt;span style="color:blue;"&gt;ByVal &lt;/span&gt;sXML &lt;span style="color:blue;"&gt;As String&lt;/span&gt;) &lt;span style="color:blue;"&gt;As Boolean Implements&lt;/span&gt; IService.PassDataSet&lt;br /&gt;  &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;dsObjects &lt;span style="color:blue;"&gt;As New&lt;/span&gt; Data.DataSet&lt;br /&gt;  &lt;span style="color: rgb(0, 153, 0);"&gt;'First read the schema of the DataSet&lt;/span&gt;&lt;br /&gt;  dsObjects.ReadXmlSchema _&lt;br /&gt; (&lt;span style="color:blue;"&gt;New &lt;/span&gt;MemoryStream(Text.Encoding.Unicode.GetBytes(sXMLSchema)))&lt;br /&gt;  &lt;span style="color: rgb(0, 153, 0);"&gt;'Then read the data itself&lt;/span&gt;&lt;br /&gt;  dsObjects.ReadXml _&lt;br /&gt; (&lt;span style="color:blue;"&gt;New &lt;/span&gt;MemoryStream(Text.Encoding.Unicode.GetBytes(sXML)))&lt;br /&gt;  &lt;span style="color: rgb(0, 153, 0);"&gt;'Here do what ever you like with your DataSet&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    'Finally return a value to the client&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;Return True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;  End Function&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="color:blue;"&gt;End Class&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;And finally here is how you call the method:&lt;br /&gt;&lt;div class="code"&gt;Client:&lt;div class="innercode"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;'Create and instance of the client proxy for the service.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;Dim &lt;/span&gt;proxy &lt;span style="color:blue;"&gt;As New&lt;/span&gt; ServiceClient()&lt;br /&gt;&lt;span style="color:blue;"&gt;Dim &lt;/span&gt;dsDataSet &lt;span style="color:blue;"&gt;As New&lt;/span&gt; DataSet()&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;'Here load your data in your DataSet&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;'Finally call the service&lt;/span&gt;&lt;br /&gt;proxy.PassDataSet(dsDataSet.GetXmlSchema(), dsDataSet.GetXml())&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Now you can enjoy your WCF service that accepts a DataSet :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-7288738913011095124?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/7288738913011095124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=7288738913011095124' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/7288738913011095124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/7288738913011095124'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2008/04/passing-dataset-to-wcf-method.html' title='Passing DataSet to a WCF Method'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-3832713136790639319</id><published>2007-03-28T15:50:00.001+03:00</published><updated>2008-11-16T17:50:46.656+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CheckListBox'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><title type='text'>Creating a simple CheckListBox control in WPF</title><content type='html'>With .NET Framework 3.0 Microsoft has removed one control that I've liked and used a lot - the CheckListBox. But on the other hand with WPF the developer can easily create his own check list control. Here is how to create one yourself.&lt;br /&gt;Put a simple ListBox in your window:&lt;br /&gt;&lt;div class="code"&gt;XAML:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="winCustomPKChooser"&lt;/span&gt;&lt;br /&gt;        &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;br /&gt;        &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;br /&gt;        &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="CheckListBox Demo"&lt;/span&gt; &lt;br /&gt;        &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ListBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="lstCheckListBox"&lt;/span&gt;&lt;br /&gt;             &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="185"&lt;/span&gt;&lt;br /&gt;               &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;The trick is that we will not add simple items to the list box, but instead of that we will add check boxes. Here is a simple function which adds items to our ListBox and hoocks the corresponding events for when items get checked or unchecked:&lt;br /&gt;&lt;div class="code"&gt;VB:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; AddItemsToListBox()&lt;br /&gt;     &lt;span class="kwrd"&gt;Dim&lt;/span&gt; chkCheckBoxToAdd &lt;span class="kwrd"&gt;as&lt;/span&gt; CheckBox&lt;br /&gt;     &lt;span class="kwrd"&gt;For&lt;/span&gt; nLoop &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = 1 &lt;span class="kwrd"&gt;to&lt;/span&gt; 10&lt;br /&gt;       chkCheckBoxToAdd = &lt;span class="kwrd"&gt;New&lt;/span&gt; CheckBox()&lt;br /&gt;       chkCheckBoxToAdd.IsChecked = &lt;span class="kwrd"&gt;False&lt;/span&gt;&lt;br /&gt;       chkCheckBoxToAdd.Content = &lt;span class="str"&gt;"Item "&lt;/span&gt; &amp;amp; nLoop.ToString() &lt;br /&gt;&lt;br /&gt;       &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; chkCheckBoxToAdd.Checked _&lt;br /&gt;             , &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; lstColumnName_ItemCheck&lt;br /&gt;       &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; chkCheckBoxToAdd.Unchecked _&lt;br /&gt;             , &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; lstColumnName_ItemUncheck&lt;br /&gt;&lt;br /&gt;       lstColumnName.Items.Add(chkCheckBoxToAdd)&lt;br /&gt;     &lt;span class="kwrd"&gt;Next&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; lstColumnName_ItemCheck(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt; _&lt;br /&gt;    , &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.RoutedEventArgs _ &lt;br /&gt;                        )&lt;br /&gt;     &lt;span class="rem"&gt;'Do something when an item gets checked. &lt;/span&gt;&lt;br /&gt;     &lt;span class="rem"&gt;'If you need for something the checkbox &lt;/span&gt;&lt;br /&gt;     &lt;span class="rem"&gt;'which was checked use the CType(e.OriginalSource, CheckBox).&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; lstColumnName_ItemUncheck(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt; _&lt;br /&gt;    , &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.RoutedEventArgs _&lt;br /&gt;   )&lt;br /&gt;      &lt;span class="rem"&gt;'Do something when an item gets unchecked. &lt;/span&gt;&lt;br /&gt;      &lt;span class="rem"&gt;'If you need for something the checkbox &lt;/span&gt;&lt;br /&gt;      &lt;span class="rem"&gt;'which was unchecked use the CType(e.OriginalSource, CheckBox).&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Enjoy your own CheckListBox!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-3832713136790639319?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/3832713136790639319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=3832713136790639319' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3832713136790639319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3832713136790639319'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/03/creating-simple-checklistbox-control-in.html' title='Creating a simple CheckListBox control in WPF'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-7015093324327516829</id><published>2007-03-13T20:48:00.000+02:00</published><updated>2007-03-13T22:02:09.480+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='obfuscation'/><category scheme='http://www.blogger.com/atom/ns#' term='disassemble'/><title type='text'>How to obfuscate WPF assemblies using obfuscation software for .NET Framework 2.0</title><content type='html'>I've read many posts over the Internet which are stating that it is currently impossible to obfuscate WPF assemblies. Well this is partially true. &lt;br /&gt;&lt;br /&gt;Here is what you can do to partially protect your .NET Framework 3.0 code:&lt;br /&gt;In order your code to continue to work properly you must exclude from the obfuscation at least the names of your WPF window and user control classes. You can leave in the obfuscation the variables, methods, events, etc. declared in the codebehind unless you use some of them in your markup. If this is the case you must exclude those  too.&lt;br /&gt;&lt;br /&gt;Note that by doing this you will not obfuscate the XAML code itself, but only the codebehind. Your markup can still be viewed with some disassembly tools (for example &lt;a href="http://www.aisto.com/roeder/dotnet/" target="_blank"&gt;Lutz Roeder's .NET reflector&lt;/a&gt; and the &lt;a href="http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=BamlViewer&amp;referringTitle=Home" target="_blank"&gt;BamlViewer add-in&lt;/a&gt;).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-7015093324327516829?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/7015093324327516829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=7015093324327516829' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/7015093324327516829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/7015093324327516829'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/03/how-to-obfuscate-wpf-assemblies-using.html' title='How to obfuscate WPF assemblies using obfuscation software for .NET Framework 2.0'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-3237260051498904420</id><published>2007-01-25T19:47:00.001+02:00</published><updated>2008-11-16T17:53:36.689+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='Custom User Controls'/><title type='text'>Developing &amp; deploying custom user controls in WPF</title><content type='html'>In WPF the development and deployment of custom user controls is similar to the development and deployment of user controls in ASP.NET. Let say that you have made a user control named &lt;span style="font-style:italic;"&gt;MyUserCtrl1&lt;/span&gt; in your main application project. In order to use this control in a Window you must first declare a namespace for it. The easy way to do this in the Window tag. After that the use of the control is as easy as writing a tag with the namespace that you have declared in the window tag and name - the name of the control:&lt;br /&gt;&lt;div class="code"&gt;XAML:&lt;br /&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns:uc&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:MyApplication"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;uc:MyUserCtrl1&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Where &lt;span style="font-style:italic;"&gt;MyApplication&lt;/span&gt; is the namespace of your application.&lt;br /&gt;Now if the user control is in another assembly (for example &lt;span style="font-style:italic;"&gt;MyApplication.GUI.dll&lt;/span&gt;) you must also type the assembly name in the XML namespace declaration:&lt;br /&gt;&lt;div class="code"&gt;XAML:&lt;br /&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;xmlns:uc&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:MyApplication.GUI;assembly=MyApplication.GUI"&lt;/span&gt;&lt;br /&gt;   &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt; &lt;br /&gt;        &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;uc:MyUserCtrl1&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Note that the assembly name may be different from the namespace!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-3237260051498904420?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/3237260051498904420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=3237260051498904420' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3237260051498904420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3237260051498904420'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/01/developing-deploying-custom-user.html' title='Developing &amp; deploying custom user controls in WPF'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-1969647340900292533</id><published>2007-01-20T23:08:00.001+02:00</published><updated>2008-11-16T17:54:58.469+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='middle click'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework 2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Close TabPage'/><title type='text'>How to close a tab with mouse middle click?</title><content type='html'>When I had to do this I've searched all over the Internet for some information on how to implement such a feature, but I have found nothing. &lt;br /&gt;The main problem was how to detect on which tab exactly has the user clicked on. I haven't found any method or property of the &lt;span style="font-style:italic;"&gt;TabControl&lt;/span&gt; or &lt;span style="font-style:italic;"&gt;TabPage&lt;/span&gt; controls in .NET Framework 2.0 that will be at some help. But after some experimenting I've found a very easy and effective way to do this. Here is the code:&lt;div class="code"&gt;VB:&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TabControl1_MouseUp(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt; _&lt;br /&gt;                      , &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.Forms.MouseEventArgs _&lt;br /&gt;                      ) &lt;span class="kwrd"&gt;Handles&lt;/span&gt; TabControl1.MouseUp&lt;br /&gt;    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; nTabIndexAs &lt;span class="kwrd"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;'Detect on which tab the user has clicked&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;For&lt;/span&gt; nTabIndex= 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; TabControl1.TabPages.Count - 1&lt;br /&gt;        &lt;span class="kwrd"&gt;If&lt;/span&gt; e.X &amp;gt;= TabControl1.GetTabRect(nTabIndex).X _&lt;br /&gt;            &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; e.X &amp;lt;= TabControl1.GetTabRect(nTabIndex).Width  _&lt;br /&gt;                            + TabControl1.GetTabRect(nTabIndex).X  _&lt;br /&gt;            &lt;span class="kwrd"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;For&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;Next&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;If&lt;/span&gt; e.Button = Windows.Forms.MouseButtons.Middle &lt;span class="kwrd"&gt;Then&lt;/span&gt;&lt;br /&gt;        TabControl1.TabPages.RemoveAt(nTabIndex)&lt;br /&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-1969647340900292533?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/1969647340900292533/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=1969647340900292533' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1969647340900292533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/1969647340900292533'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/01/how-to-close-tab-with-mouse-middle_20.html' title='How to close a tab with mouse middle click?'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-3344678269556016960</id><published>2007-01-17T23:24:00.001+02:00</published><updated>2008-11-16T17:57:30.912+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='PasswordBox'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='Password TextBox'/><title type='text'>Password TextBox in WPF</title><content type='html'>In .NET Framework 3.0 (WPF) Microsoft have removed the property of a TextBox, which specifies whether the textbox is Password or Normal type. But in replacement they've introduced a new control named &lt;span style="font-style: italic;"&gt;PasswordBox &lt;/span&gt;which is very simple and intuitive to use. Here is a simple example:&lt;div class="code"&gt;XAML:&lt;br /&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PasswordBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtPassword"&lt;/span&gt;&lt;br /&gt;         &lt;span class="attr"&gt;ToolTip&lt;/span&gt;&lt;span class="kwrd"&gt;="Password"&lt;/span&gt;&lt;br /&gt;         &lt;span class="attr"&gt;PasswordChar&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;By default the &lt;span style="font-style: italic;"&gt;PasswordChar&lt;/span&gt; is set to the big black dot from Windows XP style logon and.&lt;br /&gt;In order to detect changes in the password you must handle the &lt;span style="font-style: italic;"&gt;PasswordChanged&lt;/span&gt; event:&lt;div class="code"&gt;&lt;br /&gt;VB Codebehind:&lt;br /&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; txtPassword_PasswordChanged(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; System.&lt;span class="kwrd"&gt;Object&lt;/span&gt; _&lt;br /&gt;                  , &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.Windows.RoutedEventArgs _&lt;br /&gt;                 ) &lt;span class="kwrd"&gt;Handles&lt;/span&gt; txtPassword.PasswordChanged&lt;br /&gt;      &lt;span class="rem"&gt;'Validate input&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;An in order to retrieve the typed password you just use the &lt;span style="font-style: italic;"&gt;Password&lt;/span&gt; property of the &lt;span style="font-style: italic;"&gt;PasswordBox&lt;/span&gt; control:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;VB Codebehind:&lt;br /&gt;&lt;div class="innercode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; IsAuthenticated() &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;Return&lt;/span&gt; txtPassword.Password &amp;lt;&amp;gt; &lt;span class="str"&gt;""&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-3344678269556016960?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/3344678269556016960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=3344678269556016960' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3344678269556016960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/3344678269556016960'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/01/password-textbox-in-wpf.html' title='Password TextBox in WPF'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-38601416.post-8910589921623952429</id><published>2007-01-16T22:55:00.000+02:00</published><updated>2007-01-19T00:02:40.198+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='first step'/><title type='text'>The first step is always the hardest one to make :)</title><content type='html'>This blog will be dedicated mostly to Tips &amp;amp; Tricks and best practices that I have experienced at my work as a .NET Framework and SQL Server developer. Most of those are nowhere to find around the Internet and it took me many hours to research these. I hope with this blog I'll make it easier for you to find the answers and solutions you are looking for.&lt;br /&gt;&lt;br /&gt;So lets get this one started :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/38601416-8910589921623952429?l=pstaev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pstaev.blogspot.com/feeds/8910589921623952429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=38601416&amp;postID=8910589921623952429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8910589921623952429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/38601416/posts/default/8910589921623952429'/><link rel='alternate' type='text/html' href='http://pstaev.blogspot.com/2007/01/first-step-is-always-hardest.html' title='The first step is always the hardest one to make :)'/><author><name>Peter Staev</name><uri>http://www.blogger.com/profile/08426983122006097730</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://timeros.googlepages.com/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
