tag:blogger.com,1999:blog-81071534325459069592024-02-19T22:24:00.167+05:30Developer's hub [C#, WPF, HTML5 & JavaScript]Love technology.PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-8107153432545906959.post-52861930902327466762021-08-03T10:33:00.000+05:302021-08-03T10:33:55.828+05:30What are Windows' In-built service accounts available and why do we need them?<div><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">In Windows system's, there are some built-in user accounts without passwords and you can use them directly and each built-in account has a different purpose. See the below image,</span></div><div><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"><br /></span></div><div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiMGUEEY1twM57txR9BeL0p7vHz0vJt4JXHhP9YOJxQ0Ogem7UNRCC9zXYmV4e0gVZpAnNtHBMNPuZm8uJUbzJB9ZRq1dhNH7mh2oYIjkX2MbwCuv52OMFTpqh3CNh3IjG2a8ynGoLQyap/s755/local-system-vs-network-service-vs-local-service-5.jpg" imageanchor="1"><img border="0" data-original-height="207" data-original-width="755" height="110" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiMGUEEY1twM57txR9BeL0p7vHz0vJt4JXHhP9YOJxQ0Ogem7UNRCC9zXYmV4e0gVZpAnNtHBMNPuZm8uJUbzJB9ZRq1dhNH7mh2oYIjkX2MbwCuv52OMFTpqh3CNh3IjG2a8ynGoLQyap/w400-h110/local-system-vs-network-service-vs-local-service-5.jpg" width="400" /></a></div><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"><br /></span></div><ul style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px;"><li><h5 id="Implementationapproach-CoreserviceshouldnotrunasSYSTEM-LocalService(preferred)→(User+NoNetwork)" style="color: #5e6c84; font-size: 14px; letter-spacing: 0px; line-height: 1.66667; margin: 0px; padding: 0px;"><a class="external-link" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684188%28v=vs.85%29.aspx" rel="nofollow" style="color: #006990; text-decoration-line: none;"><strong>LocalService</strong> </a><em>(preferred)</em> → <strong><em>(User + No Network)</em> </strong></h5><p style="margin: 10px 0px 0px; padding: 0px;">A limited service account that is very similar to Network Service and meant to run standard least-privileged services. However, unlike Network Service it accesses the network as an <em style="letter-spacing: 0px;">Anonymous</em><span style="letter-spacing: 0px;"> user.</span></p></li></ul><ol style="text-align: left;"><ul><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">Name : </span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"><code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">NT AUTHORITY\LocalService</code></strong></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">The account has no password (any password information you provide is ignored)</span></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">HKCU represents the </span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">LocalService</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> user account. It has </span><em style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; letter-spacing: 0px;">minimal</em><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> privileges on the local computer & presents </span><em style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; letter-spacing: 0px;">anonymous</em><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> credentials on the network</span></li><li><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">SID</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">: S-1-5-19</span></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">Has its own profile under the </span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">HKEY_USERS</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> registry key (</span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"><code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">HKEY_USERS\S-1-5-19</code></strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">)</span></li></ul></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ul style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px;"><li><h5 id="Implementationapproach-CoreserviceshouldnotrunasSYSTEM-NetworkService→(User+Network)" style="color: #5e6c84; font-size: 14px; letter-spacing: 0px; line-height: 1.66667; margin: 0px; padding: 0px;"><a class="external-link" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684272%28v=vs.85%29.aspx" rel="nofollow" style="color: #006990; text-decoration-line: none;">NetworkService → </a><em>(User + Network)</em><em><br /></em></h5><p style="margin: 10px 0px 0px; padding: 0px;">The limited-service account is meant to run standard privileged services. This account is far more limited than the Local System (or even Administrator) but still has the right to access the network as the machine (see caveat above).</p></li></ul><ol style="text-align: left;"><ul><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">Name : </span><strong style="background-color: white; color: #172b4d; font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace; font-size: 14px; letter-spacing: 0px;">NT AUTHORITY\NetworkService</strong></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">the account has no password (any password information you provide is ignored)</span></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">HKCU represents the </span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">NetworkService</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> user account. It has </span><em style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; letter-spacing: 0px;">minimal</em><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> privileges on the local computer & presents the computer's credentials to remote servers.</span></li><li><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">SID</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">: S-1-5-20</span></li><li><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">Has its own profile under the </span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">HKEY_USERS</strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"> registry key (</span><strong style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;"><code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">HKEY_USERS\S-1-5-20</code></strong><span style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px;">)</span></li></ul></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"></ol><ul style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px;"><li><h5 id="Implementationapproach-CoreserviceshouldnotrunasSYSTEM-LocalSystem(dangerous,don'tuse!)→(Admin+Network)" style="color: #5e6c84; font-size: 14px; letter-spacing: 0px; line-height: 1.66667; margin: 0px; padding: 0px;"><a class="external-link" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684190%28v=vs.85%29.aspx" rel="nofollow" style="color: #006990; text-decoration-line: none;"><strong>LocalSystem</strong> </a><em>(dangerous, don't use!) → <strong>(Admin + Network)</strong></em></h5><p style="margin: 10px 0px 0px; padding: 0px;">Completely trusted account, more so than the administrator account. There is nothing on a single box that this account cannot do, and it has the right to access the network as the machine (this requires Active Directory and granting the machine account permissions to something)</p></li></ul><ol style="background-color: white; color: #172b4d; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 10px 0px 0px; text-align: left;"><li style="background-image: none; list-style-type: none;"><ul><li>Name : <strong style="letter-spacing: 0px;"><code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">.\LocalSystem</code> (can also use <code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">LocalSystem</code> or <code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">ComputerName\LocalSystem</code>)</strong></li><li>The account has no password (any password information you provide is ignored)</li><li><strong>SID</strong>: S-1-5-18</li><li>Does not have any profile of its own (<strong><code style="font-family: SFMono-Medium, "SF Mono", "Segoe UI Mono", "Roboto Mono", "Ubuntu Mono", Menlo, Courier, monospace;">HKCU</code></strong> represents the <strong>default</strong> user)</li><li>Has <em>extensive</em> privileges on the local computer & presents the computer's credentials to remote servers.</li></ul></li></ol>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-68228194964966047662019-04-20T21:29:00.002+05:302019-04-20T21:29:40.850+05:30TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8867.<div dir="ltr" style="text-align: left;" trbidi="on">
I am using WCF service in my application and it was good until yesterday. Suddenly it stops to work after recent windows (I am using Windows 10) update. It throws following error.<br />
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><i><span style="color: #cc0000;">TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8867.</span><o:p></o:p></i></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I couldn’t find much help from Internet and after a long struggle I managed to resolve it. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
After my windows update, the <span style="color: red;"><b>Net.Tcp Listener Adapter</b> </span>(NetTcpActivator) service got turned OFF. After I turn it ON, then my application started to work without any issue. <o:p></o:p><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpyK0-MolgbUHj-3yyeCFSXe9NxY1UL3yhoQ50ebknrooIRoCCdzO1TzMt8JFCU4ZWtdFCmo95qu5oDMRiZOTyq7PX6NrZclH6hK7fpcoBb-udyBVybBZgw9wmWcTSzbC7dvaWcNOQPyXw/s1600/Annotation+2019-04-20+212643.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="240" data-original-width="1410" height="108" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpyK0-MolgbUHj-3yyeCFSXe9NxY1UL3yhoQ50ebknrooIRoCCdzO1TzMt8JFCU4ZWtdFCmo95qu5oDMRiZOTyq7PX6NrZclH6hK7fpcoBb-udyBVybBZgw9wmWcTSzbC7dvaWcNOQPyXw/s640/Annotation+2019-04-20+212643.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<br /></div>
<div class="MsoNormal">
<o:p>I hope this post will help to someone who really struggle about this issue. </o:p></div>
<br /></div>
PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-89975284317865981242013-09-20T15:45:00.000+05:302013-09-20T18:06:22.551+05:30Globalize WPF application using Localization<div dir="ltr" style="text-align: left;" trbidi="on"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script><style type="text/css">.csharpcode, .csharpcode pre
{
font-size: 12px;
font-width: 400;
color: black;
font-family: "Courier New";
}
.csharpcode pre { margin: 0px; }
.csharpcode .comment { color: #008000; }
.csharpcode .comment2 { color: #808080; }
.csharpcode .type { color: #2B91AF; }
.csharpcode .keyword { color: #0000FF; }
.csharpcode .string { color: #A31515; }
.csharpcode .preproc { color: #0000FF; }
</style><div style="font-family: "Calibri","sans-serif"; font-weight: normal;">When you create a new product, it should be available to all people in worldwide and they could understand by his own language. When you limit your product's availability to only one language (Say in English), you limit your potential customer base. If you want your applications to reach a global audience, cost-effective localization of your product is one of the best and most economical ways to reach more customers.</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal;"></div><div class="WordSection1"><div style="font-family: "Calibri","sans-serif"; font-weight: normal;"><br />
Here I am going to apply globalization and localization in my <b>Windows Presentation Foundation (WPF)</b> application. <b>Globalization</b> is the design and development of applications that perform in multiple locations. <b>Localization</b> is the translation of application resources into localized versions for the specific cultures that the application supports.</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal;">A simple and effective way to localize application resources is to write a custom <b>MarkupExtension</b> that provides a localized value. The extension takes a parameter in the constructor that is the unique resource key. When the <b>DepdendencyProperty</b> asks for the value, the markup extension looks up the value from a generic resource provider. This gives you the flexibility to reuse the resource management and translation process that is already established within your company.</div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><br />
</div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;">The localization module consists of the following parts.</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">Localization manager</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;">The localization manager is a static class which manages the current language and notifies to all markup extensions which are specified in <b>RESX</b> file, to update their values when the language changes. It also provides access to localized resources. The resources itself are provided by a generic translation provider.</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div class="csharpcode"><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .5in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 95%;"><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">LocalizationManager</span>
{
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">event</span> <span class="type">EventHandler</span> CultureChanged;
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">ILocalizedResourceProvider</span> LocalizationProvider { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">IList</span><<span class="type">CultureInfo</span>> SupportedCultures { <span class="keyword">get</span>; <span class="keyword">private</span> <span class="keyword">set</span>; }
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">CultureInfo</span> CurrentCulture
{
<span class="keyword">get</span> { <span class="keyword">return</span> CultureInfo.CurrentUICulture; }
<span class="keyword">set</span>
{
<span class="type">Thread</span>.CurrentThread.CurrentUICulture = <span class="keyword">value</span>;
<span class="keyword">if</span> (CultureChanged != <span class="keyword">null</span>)
{
CultureChanged(<span class="keyword">null</span>, <span class="type">EventArgs</span>.<span class="type">Empty</span>);
}
}
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">object</span> GetValue(<span class="keyword">string</span> key)
{
<span class="keyword">if</span> (LocalizationProvider != <span class="keyword">null</span>)
{
<span class="keyword">return</span> LocalizationProvider.GetValue(key);
}
<span class="keyword">return</span> <span class="keyword">null</span>;
}
<span class="keyword">static</span> LocalizationManager()
{
SupportedCultures = <span class="keyword">new</span> <span class="type">List</span><<span class="type">CultureInfo</span>>();
}
}<!--[if IE]>
<![endif]--></pre></div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">Localize markup extension</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;">The localize markup extension knows the resource key and provides the localized value. It listens to the <b>CultureChanged</b> event of the localization manager and update its value. </div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div class="csharpcode"><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .5in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 95%;">[<span class="type">MarkupExtensionReturnType</span>(<span class="keyword">typeof</span>(<span class="keyword">string</span>)), Localizability(LocalizationCategory.NeverLocalize)]
<span class="keyword">public</span> <span class="keyword">class</span> <span class="type">LocalizeExtension</span> : <span class="type">MarkupExtension</span>
{
<span class="keyword">private</span> <span class="type">DependencyObject</span> _targetObject;
<span class="keyword">private</span> <span class="type">DependencyProperty</span> _targetProperty;
<span class="keyword">private</span> <span class="type">TypeConverter</span> _typeConverter;
<span class="keyword">public</span> LocalizeExtension()
{
LocalizationManager.CultureChanged += LocalizationManager_CultureChanged;
}
~<span class="type">LocalizeExtension</span>()
{
LocalizationManager.CultureChanged -= LocalizationManager_CultureChanged;
}
<span class="keyword">private</span> <span class="keyword">void</span> LocalizationManager_CultureChanged(<span class="keyword">object</span> sender, <span class="type">EventArgs</span> e)
{
UpdateTarget();
}
<span class="keyword">public</span> LocalizeExtension(<span class="keyword">string</span> key) : <span class="keyword">this</span>()
{
Key = key;
}
[<span class="type">ConstructorArgument</span>(<span class="string">"key"</span>)]
<span class="keyword">public</span> <span class="keyword">string</span> Key { <span class="keyword">get</span>; <span class="keyword">set</span>; }
[<span class="type">ConstructorArgument</span>(<span class="string">"format"</span>)]
<span class="keyword">public</span> <span class="keyword">string</span> Format { <span class="keyword">get</span>; <span class="keyword">set</span>; }
[<span class="type">ConstructorArgument</span>(<span class="string">"DefaultValue"</span>)]
<span class="keyword">public</span> <span class="keyword">object</span> DefaultValue { <span class="keyword">get</span>; <span class="keyword">set</span>; }
[<span class="type">ConstructorArgument</span>(<span class="string">"Converter"</span>)]
<span class="keyword">public</span> <span class="type">IValueConverter</span> Converter { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<span class="keyword">internal</span> <span class="keyword">void</span> UpdateTarget()
{
<span class="keyword">if</span> (_targetObject != <span class="keyword">null</span> && _targetProperty != <span class="keyword">null</span>)
{
_targetObject.SetValue(_targetProperty, ProvideValueInternal());
}
}
<span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">object</span> ProvideValue(<span class="type">IServiceProvider</span> serviceProvider)
{
<span class="comment">// Resolve the depending object and property</span>
<span class="keyword">if</span> (_targetObject == <span class="keyword">null</span>)
{
<span class="type">var</span> targetHelper = (<span class="type">IProvideValueTarget</span>)serviceProvider.GetService(<span class="keyword">typeof</span>(<span class="type">IProvideValueTarget</span>));
_targetObject = targetHelper.TargetObject <span class="keyword">as</span> <span class="type">DependencyObject</span>;
_targetProperty = targetHelper.TargetProperty <span class="keyword">as</span> <span class="type">DependencyProperty</span>;
_typeConverter = <span class="type">TypeDescriptor</span>.GetConverter(_targetProperty.PropertyType);
}
<span class="keyword">return</span> ProvideValueInternal();
}
<span class="keyword">private</span> <span class="keyword">object</span> ProvideValueInternal()
{
<span class="comment">// Get the localized value</span>
<span class="keyword">object</span> <span class="keyword">value</span> = LocalizationManager.GetValue(Key);
<span class="comment">// Automatically convert the type if a matching type converter is available</span>
<span class="keyword">if</span> (<span class="keyword">value</span> != <span class="keyword">null</span> && _typeConverter != <span class="keyword">null</span> && _typeConverter.CanConvertFrom(<span class="keyword">value</span>.GetType()))
{
<span class="keyword">value</span> = _typeConverter.ConvertFrom(<span class="keyword">value</span>);
}
<span class="comment">// If the value is null, use the fallback value if available</span>
<span class="keyword">if</span> ((<span class="keyword">value</span> == <span class="keyword">null</span> && <span class="type">DefaultValue</span> != <span class="keyword">null</span>) || <span class="type">Convert</span>.ToString(<span class="keyword">value</span>) == <span class="string">""</span>)
{
<span class="keyword">value</span> = <span class="type">DefaultValue</span>;
}
<span class="comment">// If no fallback value is available, return the key</span>
<span class="keyword">if</span> (<span class="keyword">value</span> == <span class="keyword">null</span>)
{
<span class="keyword">if</span> (_targetProperty != <span class="keyword">null</span> && _targetProperty.PropertyType == <span class="keyword">typeof</span>(<span class="keyword">string</span>))
{
<span class="comment">// Return the key surrounded by question marks for string type properties</span>
<span class="keyword">value</span> = <span class="keyword">string</span>.Concat(<span class="string">"?"</span>, Key, <span class="string">"?"</span>);
}
<span class="keyword">else</span>
{
<span class="comment">// Return the UnsetValue for all other types of dependency properties</span>
<span class="keyword">return</span> DependencyProperty.UnsetValue;
}
}
<span class="keyword">if</span> (<span class="type">Converter</span> != <span class="keyword">null</span>)
{
<span class="keyword">value</span> = <span class="type">Converter</span>.<span class="type">Convert</span>(<span class="keyword">value</span>, _targetProperty.PropertyType, <span class="keyword">null</span>, <span class="type">CultureInfo</span>.CurrentCulture);
}
<span class="comment">// Format the value if a format string is provided and the type implements IFormattable</span>
<span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> IFormattable && <span class="type">Format</span> != <span class="keyword">null</span>)
{
((<span class="type">IFormattable</span>)<span class="keyword">value</span>).ToString(<span class="type">Format</span>, <span class="type">CultureInfo</span>.CurrentCulture);
}
<span class="keyword">return</span> <span class="keyword">value</span>;
}
}<!--[if IE]>
<![endif]--></pre></div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">Resource provider</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;">The resource provider is a class that provides the localized resources. It has to implement the <b>ILocalizedResourceProvider</b> and can access any kind of resources you like RESX files.</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div class="csharpcode"><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .5in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 95%;"><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">ResourceFileProvider</span> : <span class="type">ResourceManager</span>, <span class="type">ILocalizedResourceProvider</span>
{
<span class="keyword">private</span> <span class="type">ResourceSet</span> _resourceSet;
<span class="keyword">public</span> <span class="keyword">object</span> GetValue(<span class="keyword">string</span> key)
{
<span class="keyword">try</span>
{
<span class="keyword">if</span> (_resourceSet != <span class="keyword">null</span>)
{
<span class="keyword">return</span> _resourceSet.GetObject(key);
}
<span class="keyword">return</span> <span class="keyword">null</span>;
}
<span class="keyword">catch</span>
{
<span class="keyword">return</span> <span class="keyword">null</span>;
}
}
<span class="keyword">private</span> <span class="keyword">void</span> LoadResources()
{
ReleaseAllResources();
_resourceSet = GetResourceSet(<span class="type">CultureInfo</span>.CurrentUICulture, <span class="keyword">true</span>, <span class="keyword">true</span>);
}
<span class="keyword">public</span> ResourceFileProvider(<span class="keyword">string</span> baseName, <span class="type">Assembly</span> assembly) : <span class="keyword">base</span>(baseName, assembly)
{
LoadResources();
LocalizationManager.CultureChanged += (sender, e) => { LoadResources(); };
}
}<!--[if IE]>
<![endif]--></pre></div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><br />
</div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;">How to use it</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;">The usage of the markup extension is very simple. Just replace the string you want to localize by <b><span style="color: #a31515; font-family: "Courier New"; line-height: 150%; mso-bidi-font-size: 10.0pt; mso-no-proof: yes;">{Localize resourceKey}</span></b>. Where resource key is the ID which is defined in <b>.resx</b> file.</div><div style="font-family: "Calibri","sans-serif"; font-weight: normal; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">In XAML :-<br />
</div><br />
<div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"></div><div style="background: #F2F2F2; border: 1px dashed rgb(204, 204, 204); color: black; margin-left: .5in; margin-right: 0in; mso-element: para-border-div; width: 95%;"><div style="text-align: left;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; margin-left: .5in; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">TextBlock</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> Text</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">="{</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">Localize</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> Txt_Language</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">,</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> DefaultValue</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">=Language}" /></span></div><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; margin-left: .5in; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">TextBlock</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> Text</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">="{</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">Localize</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> Txt_Welcome</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">,</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> DefaultValue</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">='Welcome</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> <span style="color: blue;">to WPF Applicaiton</span></span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">'}"</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">/><o:p></o:p></span></div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">CodeBehind :-</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="background: #F2F2F2; border: 1px dashed rgb(204, 204, 204); color: black; margin-left: .5in; margin-right: 0in; mso-element: para-border-div; width: 95%;"><span style="color: #2b91af; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; margin-left: .5in; mso-no-proof: yes;">LocalizationManager</span><span style="font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">.GetValue(<span style="color: #a31515;">"Txt_Language"</span>)<o:p></o:p></span><br />
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; margin-left: .5in; mso-no-proof: yes;">LocalizationManager</span><span style="font-family: "Courier New"; font-size: 10.0pt; line-height: 150%; mso-no-proof: yes;">.GetValue(<span style="color: #a31515;">"Txt_Welcome"</span>)</span></div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><br />
</div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;">Sample Output</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">In English :-</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ1siXI3ba92DB2eJfi6Oeazn8z5YyzaNTGFTMRhxpqfZjXuINrvDInieLmPrdl0KuUmstHUAoaRCFFUw3_8-XguzxM4X6L5sUfiTPYTdlynlLSVTrDonaIegn3hcqsA8NX3CBEilz_Jfz/s1600/In_English.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ1siXI3ba92DB2eJfi6Oeazn8z5YyzaNTGFTMRhxpqfZjXuINrvDInieLmPrdl0KuUmstHUAoaRCFFUw3_8-XguzxM4X6L5sUfiTPYTdlynlLSVTrDonaIegn3hcqsA8NX3CBEilz_Jfz/s400/In_English.png" width="400" /></a></div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;">In German :-</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .5in; margin-right: 0in;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFtyfBxGdzOSP5JyUawRvmDMgE1kcArj47Enb-xmU0StdvMebcykhGO1wLjIIFWN2Y_-4XWrx9V9osTeWj01mR69LuGI6knDEwe4Fqtlh30-T4H4f2e4rq4QP0Du_oOzaSDO36JH-7qaAU/s1600/In_German.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFtyfBxGdzOSP5JyUawRvmDMgE1kcArj47Enb-xmU0StdvMebcykhGO1wLjIIFWN2Y_-4XWrx9V9osTeWj01mR69LuGI6knDEwe4Fqtlh30-T4H4f2e4rq4QP0Du_oOzaSDO36JH-7qaAU/s400/In_German.png" /></a></div></div><br />
<div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><a href="https://skydrive.live.com/redir?resid=644359989761C04E!165">Sample Link</a></div><br />
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-56707180123972087532011-05-16T16:27:00.003+05:302011-05-16T16:36:54.679+05:30Saving WPF Framework element as Image (In different formats)<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
In WPF, we have an option to set the object of <strong><em>DrawingBrush, RadialGradientBrush, LinearGradientBrush,</em></strong> etc., to the Background of <strong><em>FrameworkElements</em></strong>. We can save the element as an <strong><em>Image</em></strong> using the following code snippet.<br />
<br />
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="WordSection1">
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: rgb(242, 242, 242); border-collapse: collapse; border: currentColor;"><tbody>
<tr style="height: 642.35pt;"><td style="border: 1pt solid black; height: 642.35pt; padding: 0cm 5.4pt; width: 615.95pt;" valign="top" width="821"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> SaveImage(<span style="color: blue;">string</span> fileName, <span style="color: #2b91af;">FrameworkElement</span> element)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">string</span> imageExtension = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imageExtension = <span style="color: blue;">new</span> <span style="color: #2b91af;">FileInfo</span>(fileName).Extension.ToLower(<span style="color: #2b91af;">CultureInfo</span>.InvariantCulture);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">BitmapEncoder</span> imgEncoder = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">switch</span> (imageExtension)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".bmp"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">BmpBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".jpg"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".jpeg"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">JpegBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".png"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">PngBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".gif"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">GifBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".tif"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".tiff"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">TiffBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">case</span> <span style="color: #a31515;">".wdp"</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">WmpBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">default</span>:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder = <span style="color: blue;">new</span> <span style="color: #2b91af;">BmpBitmapEncoder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (element != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">RenderTargetBitmap</span> bmpSource = <span style="color: blue;">new</span> <span style="color: #2b91af;">RenderTargetBitmap</span>((<span style="color: blue;">int</span>)element.ActualWidth, (<span style="color: blue;">int</span>)element.ActualHeight, 96, 96, <span style="color: #2b91af;">PixelFormats</span>.Pbgra32);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> bmpSource.Render(element);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder.Frames.Add(<span style="color: #2b91af;">BitmapFrame</span>.Create(bmpSource));<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">using</span> (<span style="color: #2b91af;">Stream</span> stream = <span style="color: #2b91af;">File</span>.Create(fileName))<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> imgEncoder.Save(stream);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> stream.Close();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Hope it will help you. Leave your comments about it. Happy coding. <o:p></o:p></div>
</div>
</div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com1tag:blogger.com,1999:blog-8107153432545906959.post-76516045120854205862010-10-20T16:03:00.002+05:302013-09-23T18:41:09.684+05:30Creating and Showing Smart Tooltip in WPF XBAP application<div dir="ltr" style="text-align: left;" trbidi="on"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script><div dir="ltr" style="text-align: left;" trbidi="on"><div class="WordSection1"><div class="MsoNormal"><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">The Smart Tooltips are displayed when user hovers the cursor over an item, without clicking it, and a tooltip may appear. It may take a second or two to display the tooltip, but when it does appear, it usually is a small box with a yellow background explaining what the icon represents. <b><i>For example</i></b>, in Microsoft Word, when you mouse over the Paste icon, the “<b>Paste</b>” tooltip appears with its description. It helps us to know about the icon as well as its functionality. </span></div><div class="MsoNormal"><br />
</div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3fcPU-qYRzTussFIjD5sW03c1fJSrDYy76WO3ICbMcLz7AvGckYLX_jnSmAfMnslQXL701R-BaAvgQ2PzqN0qND5OFAhETUrFIBrJzZVm03S0c9lSdCjg2puzIN-1KmiZi_lfUm5PxTlO/s1600/Paste.png" style="margin-left: auto; margin-right: auto;" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: #999999; font-family: "Trebuchet MS",sans-serif; font-size: x-small;">MS Word 2010 Smart Tool-tip appearance</span></td></tr>
</tbody></table><div class="MsoNormal"><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">In my project application, I thought of to show the Smart tooltip in my Enrolment module. My application is WPF XBAP application; hence I am not able to customize the Tooltip with my own style using shapes. Because internally Tooltips are showing using Popup, the customized tooltip are showing with black coloured shadow in smart tooltip. Then I have search through the internet about this issue and come to know about Adorners and its feature from this <a href="http://www.nbdtech.com/Blog/archive/2010/07/12/wpf-adorners-part-4-ndash-simple-and-powerful-system-for.aspx" target="_blank">link</a> then decided to use Adorner for Smart Tooltip. Here is the adorner control source. </span></div><div class="MsoNormal"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .2in; margin-right: 0in;">ControlAdorner Class:-</div><style type="text/css">.csharpcode, .csharpcode pre
{
font-size: 13.3333px;
font-width: 400;
color: black;
font-family: "Courier New";
}
.csharpcode pre { margin: 0px; }
.csharpcode .comment { color: #008000; }
.csharpcode .comment2 { color: #808080; }
.csharpcode .type { color: #2B91AF; }
.csharpcode .keyword { color: #0000FF; }
.csharpcode .string { color: #A31515; }
.csharpcode .preproc { color: #0000FF; }
</style><br />
<div class="csharpcode"><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .2in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 98%;"><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">ControlAdorner</span> : <span class="type">Adorner</span>
{
<span class="keyword">private</span> <span class="type">Control</span> _child;
<span class="keyword">public</span> ControlAdorner(<span class="type">UIElement</span> adornedElement)
: <span class="keyword">base</span>(adornedElement) { }
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="keyword">int</span> VisualChildrenCount
{
<span class="keyword">get</span>
{
<span class="keyword">return</span> 1;
}
}
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="type">Visual</span> GetVisualChild(<span class="keyword">int</span> index)
{
<span class="keyword">if</span> (index != 0) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="type">ArgumentOutOfRangeException</span>();
<span class="keyword">return</span> _child;
}
<span class="keyword">public</span> <span class="type">Control</span> Child
{
<span class="keyword">get</span> { <span class="keyword">return</span> _child; }
<span class="keyword">set</span>
{
<span class="keyword">if</span> (_child != <span class="keyword">null</span>)
{
RemoveVisualChild(_child);
}
_child = <span class="keyword">value</span>;
<span class="keyword">if</span> (_child != <span class="keyword">null</span>)
{
AddVisualChild(_child);
}
}
}
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="type">Size</span> MeasureOverride(<span class="type">Size</span> constraint)
{
<span class="type">Size</span> max = <span class="keyword">new</span> <span class="type">Size</span>(<span class="keyword">double</span>.PositiveInfinity, <span class="keyword">double</span>.PositiveInfinity);
<span class="keyword">this</span>._child.Measure(max);
<span class="keyword">this</span>.InvalidateArrange();
<span class="keyword">return</span> this._child.DesiredSize;
}
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="type">Size</span> ArrangeOverride(<span class="type">Size</span> finalSize)
{
<span class="type">FrameworkElement</span> target = AdornedElement <span class="keyword">as</span> <span class="type">FrameworkElement</span>;
<span class="type">Point</span> location = <span class="keyword">new</span> <span class="type">Point</span>(target.ActualWidth + 2, -((_child.ActualHeight - target.ActualHeight) / 2));
<span class="type">Rect</span> rect = <span class="keyword">new</span> <span class="type">Rect</span>(location, finalSize);
<span class="keyword">this</span>._child.Arrange(rect);
<span class="keyword">return</span> this._child.RenderSize;
}
}
<span class="keyword">public</span> <span class="keyword">class</span> <span class="type">Adorners</span> : <span class="type">ContentControl</span>
{
<span class="preproc">#region</span> Attached Properties
<span class="comment">// Template attached property</span>
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> TemplateProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"Template"</span>, <span class="keyword">typeof</span>(<span class="type">ControlTemplate</span>), <span class="keyword">typeof</span>(<span class="type">Adorners</span>), <span class="keyword">new</span> <span class="type">PropertyMetadata</span>(TemplateChanged));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">ControlTemplate</span> GetTemplate(<span class="type">UIElement</span> target)
{
<span class="keyword">return</span> (<span class="type">ControlTemplate</span>)target.GetValue(TemplateProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetTemplate(<span class="type">UIElement</span> target, ControlTemplate <span class="keyword">value</span>)
{
target.SetValue(TemplateProperty, <span class="keyword">value</span>);
}
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> TemplateChanged(<span class="type">DependencyObject</span> d, <span class="type">DependencyPropertyChangedEventArgs</span> e)
{
UpdateAdroner((<span class="type">UIElement</span>)d, GetIsVisible((<span class="type">UIElement</span>)d), (<span class="type">ControlTemplate</span>)e.NewValue);
}
<span class="comment">// IsVisible attached property</span>
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> IsVisibleProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"IsVisible"</span>, <span class="keyword">typeof</span>(<span class="keyword">bool</span>), <span class="keyword">typeof</span>(<span class="type">Adorners</span>), <span class="keyword">new</span> <span class="type">PropertyMetadata</span>(IsVisibleChanged));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">bool</span> GetIsVisible(<span class="type">UIElement</span> target)
{
<span class="keyword">return</span> (<span class="keyword">bool</span>)target.GetValue(IsVisibleProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetIsVisible(<span class="type">UIElement</span> target, <span class="keyword">bool</span> <span class="keyword">value</span>)
{
target.SetValue(IsVisibleProperty, <span class="keyword">value</span>);
}
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> IsVisibleChanged(<span class="type">DependencyObject</span> d, <span class="type">DependencyPropertyChangedEventArgs</span> e)
{
<span class="type">UserControl</span> rootPage = FindVisualParent<<span class="type">UserControl</span>>((<span class="type">UIElement</span>)d);
<span class="type">Control</span> ctrl = GetChildWindow(rootPage) <span class="keyword">as</span> <span class="type">Control</span>;
<span class="keyword">if</span> (ctrl != <span class="keyword">null</span>)
UpdateAdroner((<span class="type">UIElement</span>)d, (<span class="keyword">bool</span>)e.NewValue, ctrl);
<span class="keyword">else</span>
UpdateAdroner((<span class="type">UIElement</span>)d, (<span class="keyword">bool</span>)e.NewValue, GetTemplate((<span class="type">UIElement</span>)d));
}
<span class="comment">// ChildWindow attached property</span>
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> ChildWindowProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"ChildWindow"</span>, <span class="keyword">typeof</span>(<span class="type">DependencyObject</span>), <span class="keyword">typeof</span>(<span class="type">Adorners</span>));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">DependencyObject</span> GetChildWindow(<span class="type">DependencyObject</span> target)
{
<span class="keyword">return</span> (<span class="type">DependencyObject</span>)target.GetValue(ChildWindowProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetChildWindow(<span class="type">UIElement</span> target, DependencyObject <span class="keyword">value</span>)
{
target.SetValue(ChildWindowProperty, <span class="keyword">value</span>);
}
<span class="comment">// InternalAdorner attached property</span>
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> InternalAdornerProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"InternalAdorner"</span>, <span class="keyword">typeof</span>(<span class="type">ControlAdorner</span>), <span class="keyword">typeof</span>(<span class="type">Adorners</span>));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">ControlAdorner</span> GetInteranlAdorner(<span class="type">DependencyObject</span> target)
{
<span class="keyword">return</span> (<span class="type">ControlAdorner</span>)target.GetValue(InternalAdornerProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetInternalAdorner(<span class="type">DependencyObject</span> target, ControlAdorner <span class="keyword">value</span>)
{
target.SetValue(InternalAdornerProperty, <span class="keyword">value</span>);
}
<span class="preproc">#endregion</span>
<span class="preproc">#region</span> Implementation
<span class="comment">// Actually do all the work:</span>
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> UpdateAdroner(<span class="type">UIElement</span> adorned)
{
UpdateAdroner(adorned, GetIsVisible(adorned), GetTemplate(adorned));
}
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> UpdateAdroner(<span class="type">UIElement</span> adorned, <span class="keyword">bool</span> isVisible, <span class="type">ControlTemplate</span> controlTemplate)
{
<span class="type">var</span> layer = AdornerLayer.GetAdornerLayer(adorned);
<span class="keyword">if</span> (layer == <span class="keyword">null</span>)
{
<span class="comment">// if we don't have an adorner layer it's probably because it's too early in the window's construction.</span>
Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Loaded,
<span class="keyword">new</span> <span class="type">Action</span>(() => { UpdateAdroner(adorned); }));
<span class="keyword">return</span>;
}
<span class="type">var</span> existingAdorner = GetInteranlAdorner(adorned);
<span class="keyword">if</span> (existingAdorner == <span class="keyword">null</span>)
{
<span class="keyword">if</span> (controlTemplate != <span class="keyword">null</span> && isVisible)
{
<span class="comment">// show</span>
<span class="type">var</span> newAdorner = <span class="keyword">new</span> <span class="type">ControlAdorner</span>(adorned);
newAdorner.Child = <span class="keyword">new</span> <span class="type">Control</span>() { Template = controlTemplate, Focusable = <span class="keyword">false</span>, };
layer.Add(newAdorner);
SetInternalAdorner(adorned, newAdorner);
}
}
<span class="keyword">else</span>
{
<span class="keyword">if</span> (controlTemplate != <span class="keyword">null</span> && isVisible)
{
<span class="comment">// switch template</span>
<span class="type">Control</span> ctrl = existingAdorner.Child;
ctrl.Template = controlTemplate;
}
<span class="keyword">else</span>
{
<span class="comment">// hide</span>
existingAdorner.Child = <span class="keyword">null</span>;
layer.Remove(existingAdorner);
SetInternalAdorner(adorned, <span class="keyword">null</span>);
}
}
}
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> UpdateAdroner(<span class="type">UIElement</span> adorned, <span class="keyword">bool</span> isVisible, <span class="type">Control</span> childControl)
{
<span class="type">var</span> layer = AdornerLayer.GetAdornerLayer(adorned);
<span class="keyword">if</span> (layer == <span class="keyword">null</span>)
{
<span class="comment">// if we don't have an adorner layer it's probably because it's too early in the window's construction.</span>
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded,
<span class="keyword">new</span> <span class="type">Action</span>(() => { UpdateAdroner(adorned); }));
<span class="keyword">return</span>;
}
<span class="type">var</span> existingAdorner = GetInteranlAdorner(adorned);
<span class="keyword">if</span> (existingAdorner == <span class="keyword">null</span>)
{
<span class="keyword">if</span> (childControl != <span class="keyword">null</span> && isVisible)
{
<span class="comment">// show</span>
<span class="type">var</span> newAdorner = <span class="keyword">new</span> <span class="type">ControlAdorner</span>(adorned);
newAdorner.Child = childControl;
layer.Add(newAdorner);
SetInternalAdorner(adorned, newAdorner);
}
}
<span class="keyword">else</span>
{
<span class="keyword">if</span> (childControl != <span class="keyword">null</span> && isVisible)
{
<span class="comment">// switch template</span>
<span class="type">Control</span> ctrl = childControl;
}
<span class="keyword">else</span>
{
<span class="comment">// hide</span>
existingAdorner.Child = <span class="keyword">null</span>;
layer.Remove(existingAdorner);
SetInternalAdorner(adorned, <span class="keyword">null</span>);
}
}
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="type">T</span> FindVisualParent<<span class="type">T</span>>(<span class="type">UIElement</span> element) <span class="keyword">where</span> T : <span class="type">UIElement</span>
{
<span class="type">UIElement</span> parent = element;
<span class="keyword">while</span> (parent != <span class="keyword">null</span>)
{
<span class="type">T</span> correctlyTyped = parent <span class="keyword">as</span> <span class="type">T</span>;
<span class="keyword">if</span> (correctlyTyped != <span class="keyword">null</span>)
{
<span class="keyword">return</span> correctlyTyped;
}
parent = VisualTreeHelper.GetParent(parent) <span class="keyword">as</span> <span class="type">UIElement</span>;
}
<span class="keyword">return</span> <span class="keyword">null</span>;
}
<span class="preproc">#endregion</span>
}
<!--[if IE]>
<![endif]--></pre></div><br />
<div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;">Sample Output</div><div class="MsoNormal"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsYYlEJK9dFb3zRrJHmxgaREj_h8HIGm3Dm3rSsq54zE8Z9H4rtJmKqAtX7fzNSZYxRiW0jeNkLnctTEYKto6NNHwhrG3un-8lHASnhHcX3YbqtKn_EW3Vu8aJ4DHp7agSsHjf1UBsBc51/s1600/SmartTooltip_new.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsYYlEJK9dFb3zRrJHmxgaREj_h8HIGm3Dm3rSsq54zE8Z9H4rtJmKqAtX7fzNSZYxRiW0jeNkLnctTEYKto6NNHwhrG3un-8lHASnhHcX3YbqtKn_EW3Vu8aJ4DHp7agSsHjf1UBsBc51/s1600/SmartTooltip_new.png" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><div class="MsoNormal"><b><span style="font-family: Calibri; font-size: small;"> </span></b></div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><a href="http://cid-644359989761c04e.office.live.com/self.aspx/.Public/BlogSamples/SmartToolTip.zip" target="_blank">Sample Link</a></div><div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;"><span style="font-size: small;"><span style="font-family: Calibri;">Happy coding.</span></span></div></div></div></div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-66700697873614021642010-10-20T00:54:00.004+05:302011-03-08T15:14:24.409+05:30Win7/Vista like busy Indicator control using Spinner animation in WPF<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<span style="font-size: x-small;"><span style="font-family: tahoma,sans-serif;"><span lang="EN-IN"><span style="font-family: Calibri;"><span style="font-size: small;">I have been working on <b>WPF XBAP</b> projects which establish the connection between mobile and system similar to Remote Desktop connectivity. I am in need to show the current status and waiting status between mobile and system connection. Hence I've created this control which is showing similar to <b>Win7/Vista</b> busy indicator. I am happy to share the control with you.</span></span></span> </span></span><br />
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<span lang="EN-IN"><span style="font-family: Calibri; font-size: small;">Initially I have a tried to show the circle shaped rectangular using rotate animation. But I couldn't get the expected feel similar to Win7/Vista like busy indicator. Then I have spent few minutes in net and I come to know about the spinner animation and found the <b>ImageStrip</b> control from this </span><a href="http://wpfcontrib.codeplex.com/" target="_blank"><span style="color: blue; font-family: Calibri; font-size: small;">link</span></a><span style="font-family: Calibri;"><span style="font-size: small;"> for implementing Image animation. Then I have created Win7/Vista like busy indicator using the following code and control template.</span></span></span></div>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<b><span lang="EN-IN"><span style="font-family: Calibri;"><span style="font-size: small;">ImageStrip Class:-</span></span></span></b></div>
<pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: 300px; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
</code><div>
<span style="color: teal;"> 1</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> ImageStrip : Control
</span><span style="color: teal;"> 2</span> <span style="color: black;"> {
</span><span style="color: teal;"> 3</span> <span style="color: black;"> </span><span style="color: blue;">#region</span><span style="color: black;"> Dependency Properties</span><span style="color: black;">
</span><span style="color: teal;"> 4</span> <span style="color: black;">
</span><span style="color: teal;"> 5</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">int</span><span style="color: black;"> Frame
</span><span style="color: teal;"> 6</span> <span style="color: black;"> {
</span><span style="color: teal;"> 7</span> <span style="color: black;"> </span><span style="color: blue;">get</span><span style="color: black;"> { </span><span style="color: blue;">return</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;">)GetValue(FrameProperty); }
</span><span style="color: teal;"> 8</span> <span style="color: black;"> </span><span style="color: blue;">set</span><span style="color: black;"> { SetValue(FrameProperty, value); }
</span><span style="color: teal;"> 9</span> <span style="color: black;"> }
</span><span style="color: teal;">10</span> <span style="color: black;">
</span><span style="color: teal;">11</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> DependencyProperty FrameProperty </span><span style="color: black;">=</span><span style="color: black;">
</span><span style="color: teal;">12</span> <span style="color: black;"> DependencyProperty.Register(</span><span style="color: maroon;">"</span><span style="color: maroon;">Frame</span><span style="color: maroon;">"</span><span style="color: black;">, </span><span style="color: blue;">typeof</span><span style="color: black;">(</span><span style="color: blue;">int</span><span style="color: black;">), </span><span style="color: blue;">typeof</span><span style="color: black;">(ImageStrip), </span><span style="color: blue;">new</span><span style="color: black;"> FrameworkPropertyMetadata(</span><span style="color: purple;">0</span><span style="color: black;">, FrameworkPropertyMetadataOptions.AffectsRender));
</span><span style="color: teal;">13</span> <span style="color: black;">
</span><span style="color: teal;">14</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">double</span><span style="color: black;"> FrameSize
</span><span style="color: teal;">15</span> <span style="color: black;"> {
</span><span style="color: teal;">16</span> <span style="color: black;"> </span><span style="color: blue;">get</span><span style="color: black;"> { </span><span style="color: blue;">return</span><span style="color: black;"> (</span><span style="color: blue;">double</span><span style="color: black;">)GetValue(FrameSizeProperty); }
</span><span style="color: teal;">17</span> <span style="color: black;"> </span><span style="color: blue;">set</span><span style="color: black;"> { SetValue(FrameSizeProperty, value); }
</span><span style="color: teal;">18</span> <span style="color: black;"> }
</span><span style="color: teal;">19</span> <span style="color: black;">
</span><span style="color: teal;">20</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> DependencyProperty FrameSizeProperty </span><span style="color: black;">=</span><span style="color: black;">
</span><span style="color: teal;">21</span> <span style="color: black;"> DependencyProperty.Register(</span><span style="color: maroon;">"</span><span style="color: maroon;">FrameSize</span><span style="color: maroon;">"</span><span style="color: black;">, </span><span style="color: blue;">typeof</span><span style="color: black;">(</span><span style="color: blue;">double</span><span style="color: black;">), </span><span style="color: blue;">typeof</span><span style="color: black;">(ImageStrip), </span><span style="color: blue;">new</span><span style="color: black;"> FrameworkPropertyMetadata(0D, FrameworkPropertyMetadataOptions.AffectsRender));
</span><span style="color: teal;">22</span> <span style="color: black;">
</span><span style="color: teal;">23</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> ImageSource Image
</span><span style="color: teal;">24</span> <span style="color: black;"> {
</span><span style="color: teal;">25</span> <span style="color: black;"> </span><span style="color: blue;">get</span><span style="color: black;"> { </span><span style="color: blue;">return</span><span style="color: black;"> (ImageSource)GetValue(ImageProperty); }
</span><span style="color: teal;">26</span> <span style="color: black;"> </span><span style="color: blue;">set</span><span style="color: black;"> { SetValue(ImageProperty, value); }
</span><span style="color: teal;">27</span> <span style="color: black;"> }
</span><span style="color: teal;">28</span> <span style="color: black;">
</span><span style="color: teal;">29</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> DependencyProperty ImageProperty </span><span style="color: black;">=</span><span style="color: black;">
</span><span style="color: teal;">30</span> <span style="color: black;"> DependencyProperty.Register(</span><span style="color: maroon;">"</span><span style="color: maroon;">Image</span><span style="color: maroon;">"</span><span style="color: black;">, </span><span style="color: blue;">typeof</span><span style="color: black;">(ImageSource), </span><span style="color: blue;">typeof</span><span style="color: black;">(ImageStrip), </span><span style="color: blue;">new</span><span style="color: black;"> FrameworkPropertyMetadata(</span><span style="color: blue;">null</span><span style="color: black;">, FrameworkPropertyMetadataOptions.AffectsRender));
</span><span style="color: teal;">31</span> <span style="color: black;">
</span><span style="color: teal;">32</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> Orientation Orientation
</span><span style="color: teal;">33</span> <span style="color: black;"> {
</span><span style="color: teal;">34</span> <span style="color: black;"> </span><span style="color: blue;">get</span><span style="color: black;"> { </span><span style="color: blue;">return</span><span style="color: black;"> (Orientation)GetValue(OrientationProperty); }
</span><span style="color: teal;">35</span> <span style="color: black;"> </span><span style="color: blue;">set</span><span style="color: black;"> { SetValue(OrientationProperty, value); }
</span><span style="color: teal;">36</span> <span style="color: black;"> }
</span><span style="color: teal;">37</span> <span style="color: black;">
</span><span style="color: teal;">38</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> DependencyProperty OrientationProperty </span><span style="color: black;">=</span><span style="color: black;">
</span><span style="color: teal;">39</span> <span style="color: black;"> DependencyProperty.Register(</span><span style="color: maroon;">"</span><span style="color: maroon;">Orientation</span><span style="color: maroon;">"</span><span style="color: black;">, </span><span style="color: blue;">typeof</span><span style="color: black;">(Orientation), </span><span style="color: blue;">typeof</span><span style="color: black;">(ImageStrip), </span><span style="color: blue;">new</span><span style="color: black;"> FrameworkPropertyMetadata(Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
</span><span style="color: teal;">40</span> <span style="color: black;">
</span><span style="color: teal;">41</span> <span style="color: black;"> </span><span style="color: blue;">#endregion</span><span style="color: black;">
</span><span style="color: teal;">42</span> <span style="color: black;">
</span><span style="color: teal;">43</span> <span style="color: black;"> </span><span style="color: blue;">#region</span><span style="color: black;"> Rendering</span><span style="color: black;">
</span><span style="color: teal;">44</span> <span style="color: black;">
</span><span style="color: teal;">45</span> <span style="color: black;"> </span><span style="color: blue;">protected</span><span style="color: black;"> </span><span style="color: blue;">override</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> OnRender(DrawingContext drawingContext)
</span><span style="color: teal;">46</span> <span style="color: black;"> {
</span><span style="color: teal;">47</span> <span style="color: black;"> </span><span style="color: blue;">if</span><span style="color: black;"> (Image </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">)
</span><span style="color: teal;">48</span> <span style="color: black;"> {
</span><span style="color: teal;">49</span> <span style="color: black;"> Rect rect </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> Rect(</span><span style="color: purple;">0</span><span style="color: black;">, </span><span style="color: purple;">0</span><span style="color: black;">, RenderSize.Width, RenderSize.Height);
</span><span style="color: teal;">50</span> <span style="color: black;">
</span><span style="color: teal;">51</span> <span style="color: black;"> ImageBrush brush </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ImageBrush(Image);
</span><span style="color: teal;">52</span> <span style="color: black;"> brush.Stretch </span><span style="color: black;">=</span><span style="color: black;"> Stretch.None;
</span><span style="color: teal;">53</span> <span style="color: black;"> brush.Viewbox </span><span style="color: black;">=</span><span style="color: black;"> (Orientation </span><span style="color: black;">==</span><span style="color: black;"> Orientation.Vertical) </span><span style="color: black;">?</span><span style="color: black;">
</span><span style="color: teal;">54</span> <span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> Rect(</span><span style="color: purple;">0</span><span style="color: black;">, (((Frame </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: purple;">0.5</span><span style="color: black;">) </span><span style="color: black;">*</span><span style="color: black;"> FrameSize) </span><span style="color: black;">/</span><span style="color: black;"> Image.Height) </span><span style="color: black;">-</span><span style="color: black;"> </span><span style="color: purple;">0.5</span><span style="color: black;">, </span><span style="color: purple;">1</span><span style="color: black;">, </span><span style="color: purple;">1</span><span style="color: black;">) :
</span><span style="color: teal;">55</span> <span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> Rect((((Frame </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: purple;">0.5</span><span style="color: black;">) </span><span style="color: black;">*</span><span style="color: black;"> FrameSize) </span><span style="color: black;">/</span><span style="color: black;"> Image.Width) </span><span style="color: black;">-</span><span style="color: black;"> </span><span style="color: purple;">0.5</span><span style="color: black;">, </span><span style="color: purple;">0</span><span style="color: black;">, </span><span style="color: purple;">1</span><span style="color: black;">, </span><span style="color: purple;">1</span><span style="color: black;">);
</span><span style="color: teal;">56</span> <span style="color: black;">
</span><span style="color: teal;">57</span> <span style="color: black;"> drawingContext.DrawRectangle(brush, </span><span style="color: blue;">null</span><span style="color: black;">, rect);
</span><span style="color: teal;">58</span> <span style="color: black;"> }
</span><span style="color: teal;">59</span> <span style="color: black;"> }
</span><span style="color: teal;">60</span> <span style="color: black;">
</span><span style="color: teal;">61</span> <span style="color: black;"> </span><span style="color: blue;">#endregion</span><span style="color: black;">
</span><span style="color: teal;">62</span> <span style="color: black;"> }
</span><span style="color: teal;">63</span> <span style="color: black;"></span></div>
</pre>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<br />
<b><span lang="EN-IN"><span style="font-family: Calibri;"><span style="font-size: small;">BusyIndicator Class:-</span></span></span></b></div>
<pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: 300px; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
</code><div>
<span style="color: teal;"> 1</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> BusyIndicator : Control
</span><span style="color: teal;"> 2</span> <span style="color: black;"> {
</span><span style="color: teal;"> 3</span> <span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> BusyIndicator()
</span><span style="color: teal;"> 4</span> <span style="color: black;"> {
</span><span style="color: teal;"> 5</span> <span style="color: black;"> DefaultStyleKeyProperty.OverrideMetadata(</span><span style="color: blue;">typeof</span><span style="color: black;">(BusyIndicator), </span><span style="color: blue;">new</span><span style="color: black;"> FrameworkPropertyMetadata(</span><span style="color: blue;">typeof</span><span style="color: black;">(BusyIndicator)));
</span><span style="color: teal;"> 6</span> <span style="color: black;"> }
</span><span style="color: teal;"> 7</span> <span style="color: black;">
</span><span style="color: teal;"> 8</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">string</span><span style="color: black;"> Text
</span><span style="color: teal;"> 9</span> <span style="color: black;"> {
</span><span style="color: teal;">10</span> <span style="color: black;"> </span><span style="color: blue;">get</span><span style="color: black;"> { </span><span style="color: blue;">return</span><span style="color: black;"> (</span><span style="color: blue;">string</span><span style="color: black;">)GetValue(TextProperty); }
</span><span style="color: teal;">11</span> <span style="color: black;"> </span><span style="color: blue;">set</span><span style="color: black;"> { SetValue(TextProperty, value); }
</span><span style="color: teal;">12</span> <span style="color: black;"> }
</span><span style="color: teal;">13</span> <span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">static</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> DependencyProperty TextProperty </span><span style="color: black;">=</span><span style="color: black;"> DependencyProperty.Register(</span><span style="color: maroon;">"</span><span style="color: maroon;">Text</span><span style="color: maroon;">"</span><span style="color: black;">, </span><span style="color: blue;">typeof</span><span style="color: black;">(</span><span style="color: blue;">string</span><span style="color: black;">), </span><span style="color: blue;">typeof</span><span style="color: black;">(BusyIndicator), </span><span style="color: blue;">new</span><span style="color: black;"> UIPropertyMetadata(</span><span style="color: blue;">null</span><span style="color: black;">));
</span><span style="color: teal;">14</span> <span style="color: black;"> }
</span><span style="color: teal;">15</span> <span style="color: black;"></span></div>
</pre>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<b><span lang="EN-IN"><span style="font-family: Calibri;"><span style="font-size: small;">XAML Style:-</span></span></span></b></div>
<pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: 300px; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
</code><div>
<span style="color: teal;"> 1</span> <span style="color: blue;"><</span><span style="color: maroon;">ResourceDictionary
</span><span style="color: teal;"> 2</span> <span style="color: maroon;"> </span><span style="color: red;">xmlns</span><span style="color: blue;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><span style="color: red;">
</span><span style="color: teal;"> 3</span> <span style="color: red;"> xmlns:x</span><span style="color: blue;">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: red;">
</span><span style="color: teal;"> 4</span> <span style="color: red;"> xmlns:local</span><span style="color: blue;">="clr-namespace:SpinnerAnimation"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 5</span> <span style="color: black;">
</span><span style="color: teal;"> 6</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Style </span><span style="color: red;">x:Key</span><span style="color: blue;">="{x:Type local:BusyIndicator}"</span><span style="color: red;"> TargetType</span><span style="color: blue;">="{x:Type local:BusyIndicator}"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 7</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="HorizontalAlignment"</span><span style="color: red;"> Value</span><span style="color: blue;">="Center"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;"> 8</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="VerticalAlignment"</span><span style="color: red;"> Value</span><span style="color: blue;">="Center"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;"> 9</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Template"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">10</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter</span><span style="color: red;">.Value</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">11</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate </span><span style="color: red;">TargetType</span><span style="color: blue;">="{x:Type local:BusyIndicator}"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">12</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Border </span><span style="color: red;">x:Name</span><span style="color: blue;">="mainBorder"</span><span style="color: red;"> Background</span><span style="color: blue;">="#FFFFFFFF"</span><span style="color: red;"> CornerRadius</span><span style="color: blue;">="3"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">13</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">14</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Border </span><span style="color: red;">x:Name</span><span style="color: blue;">="shaddowBorder"</span><span style="color: red;"> Background</span><span style="color: blue;">="#FFFFFFFF"</span><span style="color: red;"> CornerRadius</span><span style="color: blue;">="3"</span><span style="color: red;"> BorderBrush</span><span style="color: blue;">="#0D566B"</span><span style="color: red;"> BorderThickness</span><span style="color: blue;">="1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">15</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Border</span><span style="color: red;">.Effect</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">16</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DropShadowEffect </span><span style="color: red;">BlurRadius</span><span style="color: blue;">="2"</span><span style="color: red;"> ShadowDepth</span><span style="color: blue;">="3"</span><span style="color: red;"> Opacity</span><span style="color: blue;">="0.6"</span><span style="color: red;"> Color</span><span style="color: blue;">="#FF000000"</span><span style="color: red;"> Direction</span><span style="color: blue;">="310"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">17</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Border.Effect</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">18</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Border</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">19</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">StackPanel </span><span style="color: red;">HorizontalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">20</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Viewbox </span><span style="color: red;">Height</span><span style="color: blue;">="24"</span><span style="color: red;"> Width</span><span style="color: blue;">="24"</span><span style="color: red;"> Margin</span><span style="color: blue;">="2"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">21</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">local:ImageStrip </span><span style="color: red;">Image</span><span style="color: blue;">="Images\BusyIndicator.png"</span><span style="color: red;"> FrameSize</span><span style="color: blue;">="20"</span><span style="color: red;"> Width</span><span style="color: blue;">="20"</span><span style="color: red;"> Height</span><span style="color: blue;">="20"</span><span style="color: red;"> Margin</span><span style="color: blue;">="0 3 0 0"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">22</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">local:ImageStrip</span><span style="color: red;">.Effect</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">23</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DropShadowEffect </span><span style="color: red;">BlurRadius</span><span style="color: blue;">="3"</span><span style="color: red;"> ShadowDepth</span><span style="color: blue;">="3"</span><span style="color: red;"> Opacity</span><span style="color: blue;">="0.6"</span><span style="color: red;"> Color</span><span style="color: blue;">="#FF000000"</span><span style="color: red;"> Direction</span><span style="color: blue;">="300"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">24</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">local:ImageStrip.Effect</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">25</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">FrameworkElement</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">26</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">EventTrigger </span><span style="color: red;">RoutedEvent</span><span style="color: blue;">="FrameworkElement.Loaded"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">27</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">28</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">29</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Int32Animation </span><span style="color: red;">From</span><span style="color: blue;">="0"</span><span style="color: red;"> To</span><span style="color: blue;">="17"</span><span style="color: red;"> Duration</span><span style="color: blue;">="0:0:0.75"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Frame"</span><span style="color: red;"> RepeatBehavior</span><span style="color: blue;">="Forever"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">30</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">31</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">32</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">EventTrigger</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">33</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">FrameworkElement.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">34</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">local:ImageStrip</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">35</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Viewbox</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">36</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Label </span><span style="color: red;">x:Name</span><span style="color: blue;">="label"</span><span style="color: red;"> FontFamily</span><span style="color: blue;">="Calibri"</span><span style="color: red;"> Content</span><span style="color: blue;">="{TemplateBinding Text}"</span><span style="color: red;"> FontSize</span><span style="color: blue;">="12"</span><span style="color: red;"> FontWeight</span><span style="color: blue;">="Bold"</span><span style="color: red;"> HorizontalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">37</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">StackPanel</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">38</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">39</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Border</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">40</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">41</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="Text"</span><span style="color: red;"> Value</span><span style="color: blue;">="{x:Null}"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">42</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Visibility"</span><span style="color: red;"> Value</span><span style="color: blue;">="Collapsed"</span><span style="color: red;"> TargetName</span><span style="color: blue;">="label"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">43</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Visibility"</span><span style="color: red;"> Value</span><span style="color: blue;">="Collapsed"</span><span style="color: red;"> TargetName</span><span style="color: blue;">="shaddowBorder"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">44</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">45</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">46</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">47</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter.Value</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">48</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">49</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Style</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">50</span> <span style="color: black;">
</span><span style="color: teal;">51</span> <span style="color: black;"></span><span style="color: blue;"></</span><span style="color: maroon;">ResourceDictionary</span><span style="color: blue;">></span></div>
</pre>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<br />
<span lang="EN-IN"><span style="font-family: Calibri;"><span style="font-size: small;">By using ImageStrip control, we can also show the downloading, ready to connect, etc., indicators. We just need to create an appropriate image and give the <b>Frame, FrameSize, Image</b> and <b>Orientation</b> (If it is required). The sample code is below,</span></span></span></div>
<pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: 300px; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
</code><div>
<span style="color: teal;"> 1</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">local:ImageStrip </span><span style="color: red;">Image</span><span style="color: blue;">="Images/Download.png"</span><span style="color: red;"> FrameSize</span><span style="color: blue;">="22.27"</span><span style="color: red;"> Width</span><span style="color: blue;">="22"</span><span style="color: red;"> Height</span><span style="color: blue;">="22"</span><span style="color: red;"> Margin</span><span style="color: blue;">="10"</span><span style="color: red;"> Grid.Row</span><span style="color: blue;">="2"</span><span style="color: red;"> Grid.Column</span><span style="color: blue;">="3"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 2</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">FrameworkElement</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 3</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">EventTrigger </span><span style="color: red;">RoutedEvent</span><span style="color: blue;">="FrameworkElement.Loaded"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 4</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 5</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 6</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Int32Animation </span><span style="color: red;">From</span><span style="color: blue;">="0"</span><span style="color: red;"> To</span><span style="color: blue;">="6"</span><span style="color: red;"> Duration</span><span style="color: blue;">="0:0:1.5"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Frame"</span><span style="color: red;"> RepeatBehavior</span><span style="color: blue;">="Forever"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;"> 7</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 8</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;"> 9</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">EventTrigger</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">10</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">FrameworkElement.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">11</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">local:ImageStrip</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">12</span> <span style="color: black;">
</span><span style="color: teal;">13</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">local:ImageStrip </span><span style="color: red;">Image</span><span style="color: blue;">="Images/Ready.png"</span><span style="color: red;"> FrameSize</span><span style="color: blue;">="21"</span><span style="color: red;"> Width</span><span style="color: blue;">="21"</span><span style="color: red;"> Height</span><span style="color: blue;">="21"</span><span style="color: red;"> Grid.Row</span><span style="color: blue;">="3"</span><span style="color: red;"> Grid.Column</span><span style="color: blue;">="2"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">14</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">FrameworkElement</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">15</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">EventTrigger </span><span style="color: red;">RoutedEvent</span><span style="color: blue;">="FrameworkElement.Loaded"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">16</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">17</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">18</span> <span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Int32Animation </span><span style="color: red;">From</span><span style="color: blue;">="0"</span><span style="color: red;"> To</span><span style="color: blue;">="5"</span><span style="color: red;"> Duration</span><span style="color: blue;">="0:0:1.3"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Frame"</span><span style="color: red;"> RepeatBehavior</span><span style="color: blue;">="Forever"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: teal;">19</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">20</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">BeginStoryboard</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">21</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">EventTrigger</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">22</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">FrameworkElement.Triggers</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">23</span> <span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">local:ImageStrip</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: teal;">24</span> <span style="color: black;"></span></div>
</pre>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span lang="EN-IN"><b><span style="font-family: Calibri;"><span style="font-size: small;">Sample Output:-</span></span></b></span></div>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjm8JJsBofkyrPmMb6LVyoDNeHPTkcUTFaJlXl0ZdsCmL2kRvT34VgNr5AukFVDQqyGOmrwlVzAZIRfAaDalF4pXcZVv_ZkDMregxjCnz6jAL_x01yQgFWpxzBCQWxZGdIoqzN0hbobCZ5/s1600/Spinner_Output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" ex="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjm8JJsBofkyrPmMb6LVyoDNeHPTkcUTFaJlXl0ZdsCmL2kRvT34VgNr5AukFVDQqyGOmrwlVzAZIRfAaDalF4pXcZVv_ZkDMregxjCnz6jAL_x01yQgFWpxzBCQWxZGdIoqzN0hbobCZ5/s1600/Spinner_Output.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span lang="EN-IN"><a href="http://cid-644359989761c04e.office.live.com/self.aspx/.Public/BlogSamples/SpinnerAnimation.zip" target="_blank"><span style="font-family: Calibri; font-size: small;"><b>Sample Link</b></span></a></span></div>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;">
<span style="font-size: small;"><span lang="EN-IN"><span style="font-family: Calibri;">Happy Coding… </span></span><span lang="EN-IN" style="font-family: Wingdings;">J</span></span><span lang="EN-IN"></span></div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-48779368128581757162010-08-10T04:50:00.002+05:302010-08-10T05:06:44.454+05:30Error while downloading .NET Framework 3.5 pre-requisite (.msp file) with a WPF project in ClickOnce<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">In my <b style="mso-bidi-font-weight: normal;">WPF XBAP</b> application, I've been trying to deploy it into remote server (It contains public domain) and install an application using certificate authority installer pre-requisites (since my application is running in Full-Trust mode) and the .NET Framework 3.5 SP1. I have set option which should download all the pre-requisites from the same location as the application.<span style="mso-spacerun: yes;"> </span>The application is published using Visual Studio 2008 Professional Edition. If .NET Framework 3.5 is already installed then the <b style="mso-bidi-font-weight: normal;">ClickOnce</b> installation should works fine. Otherwise it should download the missing pre-requisites from the same location and install to the Client machine.</span></div>
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">If you try to download the application on the clean XP machine, you might have been facing the following issue. </span><br />
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr style="height: 40.8pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"><td style="background-color: transparent; border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; border-right: windowtext 1pt solid; border-top: windowtext 1pt solid; height: 40.8pt; mso-border-alt: solid windowtext .5pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New";">"An error occurred downloading the following resource:</span></div>
<span style="font-family: "Courier New";"><span style="color: black;">http://hostname/sampleapp/DotNetFX35/dotNetFX20/aspnet.msp</span>"</span></td></tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
</div>
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">In order to avoiding this issue, you would have to add the <b style="mso-bidi-font-weight: normal;">MIME type</b> of the <b style="mso-bidi-font-weight: normal;">.msp file</b> to the <b style="mso-bidi-font-weight: normal;">IIS</b> of hosting server. You can access the <b style="mso-bidi-font-weight: normal;">MIME types</b> by going into your site's <b style="mso-bidi-font-weight: normal;">properties -> HTTP headers -> MIME types </b>then click NEW and add an extension and MIME type. </span></div>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<b style="mso-bidi-font-weight: normal;"></b></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-pattern: gray-5 auto; mso-shading: windowtext; mso-yfti-tbllook: 1184;"><tbody>
<tr style="height: 102.7pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"><td style="background-color: transparent; border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; border-right: windowtext 1pt solid; border-top: windowtext 1pt solid; height: 102.7pt; mso-border-alt: solid windowtext .5pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Extension</b><span style="mso-tab-count: 1;"> </span>: <span style="mso-tab-count: 1;"> </span>.msp</span></div>
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">MIME</b><span style="mso-tab-count: 2;"> </span>: <span style="mso-tab-count: 1;"> </span>application/microsoftpatch</span></div>
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<b style="mso-bidi-font-weight: normal;"></b></div>
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Extension</b><span style="mso-tab-count: 1;"> </span>: <span style="mso-tab-count: 1;"> </span>.msu</span><br />
<br />
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">MIME</b><span style="mso-tab-count: 2;"> </span>: <span style="mso-tab-count: 1;"> </span>application/microsoftupdate</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 0pt;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">Please refer this </span><a href="http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/11690784-8270-4117-950c-61232cbd6a2c/"><span style="font-family: Calibri;">link</span></a><span style="font-family: Calibri;"> for more details.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">Hope it will help!!</span></div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-18540334000988829762010-06-02T13:35:00.008+05:302013-09-23T15:18:50.411+05:30How to add Watermark Text to TextBox and PasswordBox in WPF?<div dir="ltr" style="text-align: left;" trbidi="on"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script><style type="text/css">.csharpcode, .csharpcode pre
{
font-size: 12px;
font-width: 400;
color: black;
font-family: "Courier New";
}
.csharpcode pre { margin: 0px; }
.csharpcode .comment { color: #008000; }
.csharpcode .comment2 { color: #808080; }
.csharpcode .type { color: #2B91AF; }
.csharpcode .keyword { color: #0000FF; }
.csharpcode .string { color: #A31515; }
.csharpcode .preproc { color: #0000FF; }
</style><div class="WordSection1"><div class="MsoNormal"><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">I had a requirement in my sample application to show the <b>watermark text</b> (Help text) in input <b>TextBox</b> and <b>PasswordBox</b> (like Win7 Style of authentication). After a few minutes of search through internet, I got lots of sample application for showing watermark text in TextBox. But I couldn't get a sample application for showing watermark text to the PasswordBox. Again I searched for PasswordBox and finally I got an idea from this <a href="http://stackoverflow.com/questions/1607066/wpf-watermark-passwordbox-from-watermark-textbox" target="_blank">forum</a> post. </span><br />
</div><br />
<div class="MsoNormal"><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">Since the PasswordBox is a sealed class, you cannot inherit a custom class from PasswordBox. Also Password property is not a dependency property hence you cannot write triggers. Hence I have created a custom class with attached properties such as <b><i>WatermarkText </i></b>(for showing the help text about the box), <b><i>IsMonitoring</i></b> (for monitoring the input), <b><i>TextLength</i></b> (for finding the input text length) and <b><i>HasText</i></b> (an internal property which decides whether the watermark text needs to be shown in box or not). The following code and style will help you to achieve this functionality.</span></div><div class="MsoNormal"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .2in; margin-right: 0in;">WaterMarkTextHelper class:-</div><div class="MsoNormal"><br />
<div class="csharpcode"><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .2in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 98%;"><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">WaterMarkTextHelper</span> : <span class="type">DependencyObject</span>
{
<span class="preproc">#region</span> Attached Properties
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">bool</span> GetIsMonitoring(<span class="type">DependencyObject</span> obj)
{
<span class="keyword">return</span> (<span class="keyword">bool</span>)obj.GetValue(IsMonitoringProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetIsMonitoring(<span class="type">DependencyObject</span> obj, <span class="keyword">bool</span> <span class="keyword">value</span>)
{
obj.SetValue(IsMonitoringProperty, <span class="keyword">value</span>);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> IsMonitoringProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"IsMonitoring"</span>, <span class="keyword">typeof</span>(<span class="keyword">bool</span>), <span class="keyword">typeof</span>(<span class="type">WaterMarkTextHelper</span>), <span class="keyword">new</span> <span class="type">UIPropertyMetadata</span>(<span class="keyword">false</span>, OnIsMonitoringChanged));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">bool</span> GetWatermarkText(<span class="type">DependencyObject</span> obj)
{
<span class="keyword">return</span> (<span class="keyword">bool</span>)obj.GetValue(WatermarkTextProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetWatermarkText(<span class="type">DependencyObject</span> obj, <span class="keyword">string</span> <span class="keyword">value</span>)
{
obj.SetValue(WatermarkTextProperty, <span class="keyword">value</span>);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> WatermarkTextProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"WatermarkText"</span>, <span class="keyword">typeof</span>(<span class="keyword">string</span>), <span class="keyword">typeof</span>(<span class="type">WaterMarkTextHelper</span>), <span class="keyword">new</span> <span class="type">UIPropertyMetadata</span>(<span class="keyword">string</span>.<span class="type">Empty</span>));
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> GetTextLength(<span class="type">DependencyObject</span> obj)
{
<span class="keyword">return</span> (<span class="keyword">int</span>)obj.GetValue(TextLengthProperty);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> SetTextLength(<span class="type">DependencyObject</span> obj, <span class="keyword">int</span> <span class="keyword">value</span>)
{
obj.SetValue(TextLengthProperty, <span class="keyword">value</span>);
<span class="keyword">if</span> (<span class="keyword">value</span> >= 1)
obj.SetValue(HasTextProperty, <span class="keyword">true</span>);
<span class="keyword">else</span>
obj.SetValue(HasTextProperty, <span class="keyword">false</span>);
}
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> TextLengthProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"TextLength"</span>, <span class="keyword">typeof</span>(<span class="keyword">int</span>), <span class="keyword">typeof</span>(<span class="type">WaterMarkTextHelper</span>), <span class="keyword">new</span> <span class="type">UIPropertyMetadata</span>(0));
<span class="preproc">#endregion</span>
<span class="preproc">#region</span> Internal DependencyProperty
<span class="keyword">public</span> <span class="keyword">bool</span> HasText
{
<span class="keyword">get</span> { <span class="keyword">return</span> (<span class="keyword">bool</span>)GetValue(HasTextProperty); }
<span class="keyword">set</span> { SetValue(HasTextProperty, <span class="keyword">value</span>); }
}
<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="type">DependencyProperty</span> HasTextProperty =
<span class="type">DependencyProperty</span>.RegisterAttached(<span class="string">"HasText"</span>, <span class="keyword">typeof</span>(<span class="keyword">bool</span>), <span class="keyword">typeof</span>(<span class="type">WaterMarkTextHelper</span>), <span class="keyword">new</span> <span class="type">FrameworkPropertyMetadata</span>(<span class="keyword">false</span>));
<span class="preproc">#endregion</span>
<span class="preproc">#region</span> Implementation
<span class="keyword">static</span> <span class="keyword">void</span> OnIsMonitoringChanged(<span class="type">DependencyObject</span> d, <span class="type">DependencyPropertyChangedEventArgs</span> e)
{
<span class="keyword">if</span> (d <span class="keyword">is</span> TextBox)
{
<span class="type">TextBox</span> txtBox = d <span class="keyword">as</span> <span class="type">TextBox</span>;
<span class="keyword">if</span> ((<span class="keyword">bool</span>)e.NewValue)
txtBox.TextChanged += TextChanged;
<span class="keyword">else</span>
txtBox.TextChanged -= TextChanged;
}
<span class="keyword">else</span> <span class="keyword">if</span> (d <span class="keyword">is</span> PasswordBox)
{
<span class="type">PasswordBox</span> passBox = d <span class="keyword">as</span> <span class="type">PasswordBox</span>;
<span class="keyword">if</span> ((<span class="keyword">bool</span>)e.NewValue)
passBox.PasswordChanged += PasswordChanged;
<span class="keyword">else</span>
passBox.PasswordChanged -= PasswordChanged;
}
}
<span class="keyword">static</span> <span class="keyword">void</span> TextChanged(<span class="keyword">object</span> sender, <span class="type">TextChangedEventArgs</span> e)
{
<span class="type">TextBox</span> txtBox = sender <span class="keyword">as</span> <span class="type">TextBox</span>;
<span class="keyword">if</span> (txtBox == <span class="keyword">null</span>) <span class="keyword">return</span>;
SetTextLength(txtBox, txtBox.<span class="type">Text</span>.Length);
}
<span class="keyword">static</span> <span class="keyword">void</span> PasswordChanged(<span class="keyword">object</span> sender, <span class="type">RoutedEventArgs</span> e)
{
<span class="type">PasswordBox</span> passBox = sender <span class="keyword">as</span> <span class="type">PasswordBox</span>;
<span class="keyword">if</span> (passBox == <span class="keyword">null</span>) <span class="keyword">return</span>;
SetTextLength(passBox, passBox.Password.Length);
}
<span class="preproc">#endregion</span>
}
<!--[if IE]>
<![endif]--></pre></div><div class="MsoNormal"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .2in; margin-right: 0in;">XAML Style:-</div><div class="MsoNormal"></div><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 350px; line-height: 20px; margin-left: .2in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 98%;"><code style="color: black; word-wrap: normal;"></code><div><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Style </span><span style="color: red;">TargetType</span><span style="color: blue;">="{x:Type PasswordBox}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.IsMonitoring"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.WatermarkText"</span><span style="color: red;"> Value</span><span style="color: blue;">="Password"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Template"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter</span><span style="color: red;">.Value</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate </span><span style="color: red;">TargetType</span><span style="color: blue;">="{x:Type PasswordBox}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate</span><span style="color: red;">.Resources</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="enterGotFocus"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> To</span><span style="color: blue;">=".2"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="exitGotFocus"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="enterHasText"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> From</span><span style="color: blue;">=".2"</span><span style="color: red;"> To</span><span style="color: blue;">="0"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="exitHasText"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate.Resources</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Border </span><span style="color: red;">Name</span><span style="color: blue;">="Bd"</span><span style="color: red;">
<span style="color: red;"> Background</span><span style="color: blue;">="{TemplateBinding Background}"</span><span style="color: red;">
<span style="color: red;"> BorderBrush</span><span style="color: blue;">="{TemplateBinding BorderBrush}"</span><span style="color: red;">
<span style="color: red;"> BorderThickness</span><span style="color: blue;">="{TemplateBinding BorderThickness}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ScrollViewer </span><span style="color: red;">x:Name</span><span style="color: blue;">="PART_ContentHost"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> Margin</span><span style="color: blue;">="1"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">TextBlock </span><span style="color: red;">x:Name</span><span style="color: blue;">="Message"</span><span style="color: red;"> FontStyle</span><span style="color: blue;">="Italic"</span><span style="color: red;">
<span style="color: red;"> Text</span><span style="color: blue;">="{TemplateBinding local:WaterMarkTextHelper.WatermarkText}"</span><span style="color: red;">
<span style="color: red;"> Foreground</span><span style="color: blue;">="Gray"</span><span style="color: red;"> IsHitTestVisible</span><span style="color: blue;">="False"</span><span style="color: red;"> FontFamily</span><span style="color: blue;">="Calibri"</span><span style="color: red;">
<span style="color: red;"> Opacity</span><span style="color: blue;">="0.8"</span><span style="color: red;"> HorizontalAlignment</span><span style="color: blue;">="Left"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> Margin</span><span style="color: blue;">="6,0,0,0"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Border</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="IsEnabled"</span><span style="color: red;"> Value</span><span style="color: blue;">="false"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">TargetName</span><span style="color: blue;">="Bd"</span><span style="color: red;"> Property</span><span style="color: blue;">="Background"</span><span style="color: red;"> Value</span><span style="color: blue;">="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Foreground"</span><span style="color: red;"> Value</span><span style="color: blue;">="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="IsEnabled"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Value</span><span style="color: blue;">="1"</span><span style="color: red;"> TargetName</span><span style="color: blue;">="Bd"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.Conditions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Condition </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.HasText"</span><span style="color: red;"> Value</span><span style="color: blue;">="False"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Condition </span><span style="color: red;">Property</span><span style="color: blue;">="IsFocused"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.Conditions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource enterGotFocus}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource exitGotFocus}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.HasText"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger</span><span style="color: red;">.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource enterHasText}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger</span><span style="color: red;">.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource exitHasText}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate.Triggers</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter.Value</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Style</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Style </span><span style="color: red;">x:Key</span><span style="color: blue;">="WaterMarkTextBox"</span><span style="color: red;"> TargetType</span><span style="color: blue;">="{x:Type TextBox}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.IsMonitoring"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.WatermarkText"</span><span style="color: red;"> Value</span><span style="color: blue;">="Username"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Template"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter</span><span style="color: red;">.Value</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate </span><span style="color: red;">TargetType</span><span style="color: blue;">="{x:Type TextBox}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate</span><span style="color: red;">.Resources</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="enterGotFocus"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> To</span><span style="color: blue;">=".2"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="exitGotFocus"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="enterHasText"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> From</span><span style="color: blue;">=".2"</span><span style="color: red;"> To</span><span style="color: blue;">="0"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Storyboard </span><span style="color: red;">x:Key</span><span style="color: blue;">="exitHasText"</span><span style="color: red;"> </span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">DoubleAnimation </span><span style="color: red;">Duration</span><span style="color: blue;">="0:0:0.4"</span><span style="color: red;"> Storyboard.TargetProperty</span><span style="color: blue;">="Opacity"</span><span style="color: red;"> Storyboard.TargetName</span><span style="color: blue;">="Message"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Storyboard</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate.Resources</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Border </span><span style="color: red;">Name</span><span style="color: blue;">="Bd"</span><span style="color: red;">
<span style="color: red;"> Background</span><span style="color: blue;">="{TemplateBinding Background}"</span><span style="color: red;">
<span style="color: red;"> BorderBrush</span><span style="color: blue;">="{TemplateBinding BorderBrush}"</span><span style="color: red;">
<span style="color: red;"> BorderThickness</span><span style="color: blue;">="{TemplateBinding BorderThickness}"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ScrollViewer </span><span style="color: red;">x:Name</span><span style="color: blue;">="PART_ContentHost"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> Margin</span><span style="color: blue;">="1"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">TextBlock </span><span style="color: red;">x:Name</span><span style="color: blue;">="Message"</span><span style="color: red;"> Text</span><span style="color: blue;">="{TemplateBinding local:WaterMarkTextHelper.WatermarkText}"</span><span style="color: red;"> FontStyle</span><span style="color: blue;">="Italic"</span><span style="color: red;">
<span style="color: red;"> Foreground</span><span style="color: blue;">="Gray"</span><span style="color: red;"> IsHitTestVisible</span><span style="color: blue;">="False"</span><span style="color: red;"> FontFamily</span><span style="color: blue;">="Calibri"</span><span style="color: red;"> Opacity</span><span style="color: blue;">="0.8"</span><span style="color: red;"> HorizontalAlignment</span><span style="color: blue;">="Left"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;">
<span style="color: red;"> Margin</span><span style="color: blue;">="6,0,0,0"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Grid</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Border</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ControlTemplate</span><span style="color: red;">.Triggers</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="IsEnabled"</span><span style="color: red;"> Value</span><span style="color: blue;">="false"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">TargetName</span><span style="color: blue;">="Bd"</span><span style="color: red;"> Property</span><span style="color: blue;">="Background"</span><span style="color: red;"> Value</span><span style="color: blue;">="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Setter </span><span style="color: red;">Property</span><span style="color: blue;">="Foreground"</span><span style="color: red;"> Value</span><span style="color: blue;">="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.Conditions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Condition </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.HasText"</span><span style="color: red;"> Value</span><span style="color: blue;">="False"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Condition </span><span style="color: red;">Property</span><span style="color: blue;">="IsFocused"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.Conditions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource enterGotFocus}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">MultiTrigger</span><span style="color: red;">.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource exitGotFocus}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">MultiTrigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger </span><span style="color: red;">Property</span><span style="color: blue;">="local:WaterMarkTextHelper.HasText"</span><span style="color: red;"> Value</span><span style="color: blue;">="True"</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger</span><span style="color: red;">.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource enterHasText}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger.EnterActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Trigger</span><span style="color: red;">.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">BeginStoryboard </span><span style="color: red;">Storyboard</span><span style="color: blue;">="{StaticResource exitHasText}"</span><span style="color: blue;">/></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger.ExitActions</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Trigger</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate.Triggers</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ControlTemplate</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter.Value</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Setter</span><span style="color: blue;">></span><span style="color: black;">
<span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Style</span><span style="color: blue;">></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div></pre><div class="MsoNormal"></div><div class="MsoNormal"><b><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">Since the custom class contains attached properties, we can use these attached properties to any TextBox control in our application for showing Watermark. You just need to merge the “</span></b><b><i><span lang="EN-IN" style="font-family: "Calibri","sans-serif";">ResourceDictionary</span></i></b><b><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">” which contains the Style of Textbox and then need to assign the Watermark text to the TextBox using “</span></b><b><i><span style="font-family: Calibri; font-size: small;">WatermarkText</span></i></b><b><span lang="EN-IN" style="font-family: "Calibri","sans-serif"; font-weight: normal;">” attached property. The sample code is given below.</span></b></div><div class="MsoNormal"></div><pre style="background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zCCDmgal6rW4pMGfUivz1FAslPsc9AtSHUZbHDEbLw2R4d28PPePiyRXlf3RCAJGsb6-W8PLXBKye7EccaUnUWlE5ItVN-S-LC9hPYoxnWHVUvCPZ77KztyErSuTQWbKWCgVpNcppAsT/s320/codebg.gif") repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; height: 330px; line-height: 20px; margin-left: .2in; margin-right: 0in; overflow: auto; padding: 0px; text-align: left; width: 98%;"><code style="color: black; word-wrap: normal;"></code><div><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">Window</span><span style="color: red;">.Resources</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ResourceDictionary</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ResourceDictionary</span><span style="color: red;">.MergedDictionaries</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">ResourceDictionary </span><span style="color: red;">Source</span><span style="color: blue;">="Resource.xaml"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ResourceDictionary.MergedDictionaries</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">ResourceDictionary</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">Window.Resources</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">GroupBox </span><span style="color: red;">Header</span><span style="color: blue;">="Dial-up Setting"</span><span style="color: red;"> HorizontalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: red;"> Grid.Column</span><span style="color: blue;">="1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">StackPanel </span><span style="color: red;">VerticalAlignment</span><span style="color: blue;">="Center"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">TextBox </span><span style="color: red;">Height</span><span style="color: blue;">="25"</span><span style="color: red;"> Width</span><span style="color: blue;">="200"</span><span style="color: red;"> Margin</span><span style="color: blue;">="10"</span><span style="color: red;"> Style</span><span style="color: blue;">="{StaticResource WaterMarkTextBox}"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">PasswordBox </span><span style="color: red;">Height</span><span style="color: blue;">="25"</span><span style="color: red;"> Width</span><span style="color: blue;">="200"</span><span style="color: red;"> </span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">TextBox </span><span style="color: red;">Height</span><span style="color: blue;">="25"</span><span style="color: red;"> Width</span><span style="color: blue;">="200"</span><span style="color: red;"> Margin</span><span style="color: blue;">="10"</span><span style="color: red;"> Style</span><span style="color: blue;">="{StaticResource WaterMarkTextBox}"</span><span style="color: red;">
</span><span style="color: red;"> local:WaterMarkTextHelper.WatermarkText</span><span style="color: blue;">="Domain"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">StackPanel</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: black;"> </span><span style="color: blue;"></</span><span style="color: maroon;">GroupBox</span><span style="color: blue;">></span></div></pre><div class="MsoNormal"><br />
</div><div style="font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold; margin-left: .2in; margin-right: 0in;">Sample Output:-</div><div class="MsoNormal"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYw1OpQEV5IBAwxbZDd0Pi65nPMwJj5GfP6A93C5jtwgKavojakiLZ15Zm0fpI4JaIH4lSQnFb2jM1dE0arshILT59UdSvcfwRN1sFIlzfr2H1xH2tAM2qKFfsSNCvKMOHkjF-Bv7N7Hqs/s1600/Watermark.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" ex="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYw1OpQEV5IBAwxbZDd0Pi65nPMwJj5GfP6A93C5jtwgKavojakiLZ15Zm0fpI4JaIH4lSQnFb2jM1dE0arshILT59UdSvcfwRN1sFIlzfr2H1xH2tAM2qKFfsSNCvKMOHkjF-Bv7N7Hqs/s1600/Watermark.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="color: #0070c0; font-family: "Calibri","sans-serif"; font-size: 14.0pt; font-weight: bold;"><a href="http://cid-644359989761c04e.skydrive.live.com/self.aspx/.Public/BlogSamples/Watermark%5E_Demo.zip" target="_blank">Sample Link</a></div><div class="MsoNormal" style="line-height: 150%; margin: 0in 0in 10pt;"><br />
<span style="font-size: small;"><span style="font-family: Calibri;">Put a comment if you have any questions. Happy coding.</span><span style="font-family: Wingdings;"></span></span></div></div></div></div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com5tag:blogger.com,1999:blog-8107153432545906959.post-61771134923444735712010-05-31T13:52:00.002+05:302010-06-02T01:25:51.214+05:30STEPS FOR XBAP SAMPLE DEPLOYMENT<span style="font-family: Verdana, sans-serif;">The following are the steps for deploying the XBAP samples.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<strong><span style="font-family: Verdana, sans-serif;">1. VIRTUAL DIRECTORY CREATION IN IIS</span></strong><br />
<br />
<span style="font-family: Verdana, sans-serif;">Create a Virtual Directory in local machine with local path. Please use the following steps to do this.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">I. Open <strong>Internet Information Services</strong> (IIS) Manager. (<strong>Start -> Run -> inetmgr.exe</strong>).</span><br />
<span style="font-family: Verdana, sans-serif;">II. Navigate to (<strong>Machine name -> Sites -> Default Web Sites</strong>).</span><br />
<span style="font-family: Verdana, sans-serif;">III. Right click on “<strong>Default Web Sites</strong>” and select “<strong>Add Application option</strong>”. </span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIP9iohCsy8ttugIbzomlVLeLtd6o-oRgjUJ4wGaPWtWKIEcGw0mkcenBuYrAYJnA5YG4wD09zr1kgKyWCS4EksagJ9LPt5OhysNU58QjWCIbyLla_Zd9clCpNOwsMZyLlzUTvyWfLr-sU/s1600/image001.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIP9iohCsy8ttugIbzomlVLeLtd6o-oRgjUJ4wGaPWtWKIEcGw0mkcenBuYrAYJnA5YG4wD09zr1kgKyWCS4EksagJ9LPt5OhysNU58QjWCIbyLla_Zd9clCpNOwsMZyLlzUTvyWfLr-sU/s320/image001.png" width="320" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">IV. It will open “<strong>Add Application</strong>” dialog box. From this dialog box, please enter the “<strong>Alias</strong>” and “<strong>Physical Path</strong>”. Then Click OK button.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtZT2gtXlleXI6jvt1u-x1uKIyrgLrW8Db09QRC2sseTUTaLr47UD_uGj5hB9_ahIiXm9pegV6qdZC8zpzDE04Wvpq3V9kmGfFcFYVoQywi_D6CX3BlBrKv41lqnW1DxDsSs8vDzqe2ML3/s1600/image003.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtZT2gtXlleXI6jvt1u-x1uKIyrgLrW8Db09QRC2sseTUTaLr47UD_uGj5hB9_ahIiXm9pegV6qdZC8zpzDE04Wvpq3V9kmGfFcFYVoQywi_D6CX3BlBrKv41lqnW1DxDsSs8vDzqe2ML3/s320/image003.png" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">V. It will create a “<strong>Virtual directory</strong>” with the name of “<strong>Sample</strong>” to the physical path of “E:\Work\SourceCode\Version\Project\Control”.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<strong><span style="font-family: Verdana, sans-serif;">2. WORKING SAMPLE APPLICATION WITH VS IDE</span></strong><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">We should always work with Admin mode for deploying the XBAP application since we don’t have rights to access IIS in non-admin mode. Open VS IDE in Admin mode.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt1alffhoqO-rZHgUDbDZqwJEFA64Kas47Fd87PCBmqlwbR5DnrKR2hJAcuVVSSgzPWoGweuTC7Qqg1_SwDS6vasCzNOhxcXHRzEZ_giBxUosKnYGqVqoQAtTqQ6LwocBuj_jnk1eKWLUV/s1600/image005.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt1alffhoqO-rZHgUDbDZqwJEFA64Kas47Fd87PCBmqlwbR5DnrKR2hJAcuVVSSgzPWoGweuTC7Qqg1_SwDS6vasCzNOhxcXHRzEZ_giBxUosKnYGqVqoQAtTqQ6LwocBuj_jnk1eKWLUV/s320/image005.png" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<strong><span style="font-family: Verdana, sans-serif;">3. DEPLOYING SAMPLE APPLICATION</span></strong><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">I. Open the solution file.</span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">II. Do necessary changes in the application and build it. </span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">III. Once the build get succeeded then open the properties of “Sample” application. </span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">IV. From the properties window, go to Signing tab and make sure that “<strong>Sign the ClickOnce manifests</strong>” check box is checked. If not, select the certificate key from the Certificate storage. </span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmMxv9T83-Ao1ukAU4tbvOhOcPZ6TsaJn7Sqj7PXdGpq-BElC-7ynlAq0m6nkDQs1Mqg2z4NTeZ3jfU47fbfnOwRo8ZzmmMI6OLj-A4NYIV5MRC7zum0dlsgiWo4RRndqJX0JkquNU19g6/s1600/image007.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmMxv9T83-Ao1ukAU4tbvOhOcPZ6TsaJn7Sqj7PXdGpq-BElC-7ynlAq0m6nkDQs1Mqg2z4NTeZ3jfU47fbfnOwRo8ZzmmMI6OLj-A4NYIV5MRC7zum0dlsgiWo4RRndqJX0JkquNU19g6/s400/image007.png" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">V. Then navigate to “<strong>Security</strong>” tab and make sure that “<strong>This is a full trust application</strong>” radio button is in checked condition. Normally XBAP applications are run within a security sandbox to prevent untrusted applications from controlling local system resources. (E.g. deleting local files). In order to access local file system, port access, bitmap effects, etc., you need to run your application in <strong>“Full trust</strong>” mode.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"></span></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcTRlT4LAMEPk3OtwSTLKUEKetw9kGInC5xAe_XtVNHs1Js-GN0HFOWiOwCKSnE5rVgC9_exbqmW_J4bGZDHjPYUZeJ_PdZFRT8BJiZVdJwXuv1SltTyCcJJzSwoHu7cxtGkmpI-KxnsLw/s1600/image009.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="132" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcTRlT4LAMEPk3OtwSTLKUEKetw9kGInC5xAe_XtVNHs1Js-GN0HFOWiOwCKSnE5rVgC9_exbqmW_J4bGZDHjPYUZeJ_PdZFRT8BJiZVdJwXuv1SltTyCcJJzSwoHu7cxtGkmpI-KxnsLw/s400/image009.jpg" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">VI. After that, select “<strong>Publish</strong>” tab and enter the publish location (Both local path and internet path where we would like to Run the application) and publish version information.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEKOgpJWGNdf84i-yeEuIRkY_ejwY2kulKmbQhoWinvcR0_k1nmfY8mmxQPQV69_tULZu1DAF7NlQ4m-C4n1GfxBSFtG9GfX8_VF3fT6TMlDCIL7lkR8w4SEgvhKSNSxZzgPLUfxx0Xnc2/s1600/image010.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="231" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEKOgpJWGNdf84i-yeEuIRkY_ejwY2kulKmbQhoWinvcR0_k1nmfY8mmxQPQV69_tULZu1DAF7NlQ4m-C4n1GfxBSFtG9GfX8_VF3fT6TMlDCIL7lkR8w4SEgvhKSNSxZzgPLUfxx0Xnc2/s400/image010.png" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">VII. Before that, make sure that the files needed to include with the application along with the published folder. This can be achieved with help of “<strong>Application Files</strong>” dialog by clicking the “<strong>Application Files</strong>” button. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtNA4XJ1LzLA9a8lBfKl-aCpq_MfF7PYEpMEOrU2rYGyXcvFNKzdG5Cdc0RbzR1DKIn_uKPoEzJyXsQCzK_EpSG-HobZlpR5U4VyQSJczIgvR7A9mFI4S0YA8dkrE9F-J1eyAG2EvYmBN_/s1600/image012.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="287" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtNA4XJ1LzLA9a8lBfKl-aCpq_MfF7PYEpMEOrU2rYGyXcvFNKzdG5Cdc0RbzR1DKIn_uKPoEzJyXsQCzK_EpSG-HobZlpR5U4VyQSJczIgvR7A9mFI4S0YA8dkrE9F-J1eyAG2EvYmBN_/s400/image012.png" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">VIII. We need to mention the “<strong>Prerequisites</strong>” to run our application. This will be provided by using “<strong>Prerequisites</strong>” dialog.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNX1to2Hx7glXcCAOFm52naP7SQZVxzyn6giiDAVpEetLtrbD5BOQ0lz5SInE0LTpmM3UskN-JI27pEYnrGIpbbYC3j5DPTYsu6xjpNMqXLh9ruetAyVBkL3RY3LcI60e6G2eazzV6h7AG/s1600/image014.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="311" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNX1to2Hx7glXcCAOFm52naP7SQZVxzyn6giiDAVpEetLtrbD5BOQ0lz5SInE0LTpmM3UskN-JI27pEYnrGIpbbYC3j5DPTYsu6xjpNMqXLh9ruetAyVBkL3RY3LcI60e6G2eazzV6h7AG/s400/image014.png" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"></span></div>
<span style="font-family: Verdana, sans-serif;">IX. Then provide the publishing details which will be shown in the main “index.htm” page.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpdOTjuEl5RSeD3onFKPopl20d-Gi1U5kUwd86TPcQUPMZ4OaCTPPq5LJPtT2zkRXF_HrfwOHyC226O_W3P52ZxtEe7cwv1GZETiFUfAfRYKFCQApClOPq0Qps77lJs-0uRgHbcF9kgbdX/s1600/image016.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" gu="true" height="237" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpdOTjuEl5RSeD3onFKPopl20d-Gi1U5kUwd86TPcQUPMZ4OaCTPPq5LJPtT2zkRXF_HrfwOHyC226O_W3P52ZxtEe7cwv1GZETiFUfAfRYKFCQApClOPq0Qps77lJs-0uRgHbcF9kgbdX/s400/image016.png" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">X. Once you complete all above steps, please use publish wizard and publish the sample application.</span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<strong><span style="font-family: Verdana, sans-serif;">4. DEPLOYING AN APPLICATION TO THE REMOTE SERVER</span></strong><br />
<span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">I. Since we already given the internet URL while publishing the project application, we need to create a sample virtual directory in “<strong>Remote server’s IIS</strong>”. It will make URL available over the internet.</span><span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">II. Then place the sample application’s (<strong>XBAP application</strong>) files and folder from local machine to the remote server.</span>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com1tag:blogger.com,1999:blog-8107153432545906959.post-83780321515093603132010-05-17T20:58:00.002+05:302010-05-17T21:04:50.934+05:30How to get the DependencyObject under the mouse cursor?<div class="Section1">
<div class="MsoNormal">
With help of <b><i><u><a href="http://msdn.microsoft.com/en-us/library/ms635657(v=VS.100).aspx">VisualTreeHelper</a></u></i></b> and its <b><i><u><a href="http://msdn.microsoft.com/en-us/library/ms608752(v=VS.100).aspx">HitTest</a></u></i></b>() methods, we can easily find the <b><i><u><a href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyobject.aspx">DependencyObject</a></u></i></b> under the mouse cursor. Use the following code snippet to achieve this.</div>
<div class="MsoNormal">
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 478.8pt;" valign="top" width="638"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">DependencyObject</span>> hitTestList = <span style="color: blue;">null</span>;</span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">//Raised When Mouse is entered inside Panel</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> Panel_MouseEnter(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">MouseEventArgs</span> e)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> hitTestList = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">DependencyObject</span>>();</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">Point</span> pt = e.GetPosition(sender <span style="color: blue;">as</span> <span style="color: #2b91af;">IInputElement</span>);</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">VisualTreeHelper</span>.HitTest( </span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> sender <span style="color: blue;">as</span> <span style="color: #2b91af;">Visual</span>, <span style="color: blue;">null</span>,</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> CollectAllVisuals_Callback,</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">PointHitTestParameters</span>(pt));</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> hitTestList.Reverse();</span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">DependencyObject</span> elementToFind = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">DependencyObject</span> element <span style="color: blue;">in</span> hitTestList)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (element.GetType().Name.Equals(<span style="color: #a31515;">"ElementToFind"</span>))</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> elementToFind = element;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// ...</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// ...</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">HitTestResultBehavior</span> CollectAllVisuals_Callback(<span style="color: #2b91af;">HitTestResult</span> result)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (result == <span style="color: blue;">null</span> || result.VisualHit == <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> <span style="color: #2b91af;">HitTestResultBehavior</span>.Stop;</span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> hitTestList.Add(result.VisualHit);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> <span style="color: #2b91af;">HitTestResultBehavior</span>.Continue;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
Drop me a comment if you have any queries.</div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-84569396374179716912010-05-14T15:50:00.003+05:302010-05-14T15:59:54.776+05:30How to load Bitmap image to Image object in WPF<div class="Section1">
<div class="MsoNormal" style="line-height: 150%; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
I am doing an application (which I am converting <b>Windows forms 2.0</b> application into <b>WPF</b> application for rich look) in WPF and I am need of the load the <b>Image</b> from an instance of a <b><i><a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx">System.Drawing.Bitmap</a></i>. </b>Initially I was struggled to do this. After a few minutes of search in goggle, I found the following solution. With help of <b><i><a href="http://msdn.microsoft.com/en-us/library/system.windows.interop.imaging.aspx">Imaging</a></i></b> class, we can create a <b><i><u><a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx">BitmapSource</a></u></i></b> and assign the BitmapSource value to the Image. The following code will help you to do this. </div>
<div class="MsoNormal" style="line-height: 150%; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 495.75pt;" valign="top" width="661"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">BitmapSource</span> ToBitmapSource(<span style="color: blue;">this</span> System.Drawing.<span style="color: #2b91af;">Bitmap</span> source)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">BitmapSource</span> bitmapSrc = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">var</span> hBitmap = source.GetHbitmap();</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">try</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> bitmapSrc = System.Windows.Interop.<span style="color: #2b91af;">Imaging</span>.CreateBitmapSourceFromHBitmap(</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> hBitmap,</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">IntPtr</span>.Zero,</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">Int32Rect</span>.Empty,</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">BitmapSizeOptions</span>.FromEmptyOptions());</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Win32Exception</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> bitmapSrc = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> } </span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">finally</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">NativeMethods</span>.DeleteObject(hBitmap);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> bitmapSrc;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> } </span></div>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">internal</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">NativeMethods</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> [<span style="color: #2b91af;">DllImport</span>(<span style="color: #a31515;">"gdi32.dll"</span>)]</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> [<span style="color: blue;">return</span>: <span style="color: #2b91af;">MarshalAs</span>(<span style="color: #2b91af;">UnmanagedType</span>.Bool)]</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">internal</span> <span style="color: blue;">static</span> <span style="color: blue;">extern</span> <span style="color: blue;">bool</span> DeleteObject(<span style="color: #2b91af;">IntPtr</span> hObject);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> } </span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
Please check this <a href="http://stackoverflow.com/questions/94456/load-a-wpf-bitmapimage-from-a-system-drawing-bitmap">link</a> for more details.</div>
<div class="MsoNormal">
</div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-34163251058585396392010-05-04T18:45:00.002+05:302010-05-04T18:46:47.553+05:30How to close the whole application in WPF Browser based application (XBAP application)<div class="Section1">
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
In Windows based WPF application, there is an option to close the whole application using (<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;">Application</span><span style="font-family: "Courier New"; font-size: 10pt;">.Current.ShutDown) </span>statement. But the same statement is not working in Web based WPF application (perhaps it will close the application. But not close the IE browser – It showing with the blank inactive tab). We have an option to close the application along with the IE window by using the following code,</div>
<div class="MsoNormal">
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr style="height: 183.75pt;"><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; height: 183.75pt; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 478.8pt;" valign="top" width="638"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> buttonClose_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">RoutedEventArgs</span> e)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">WindowInteropHelper</span> wih = <span style="color: blue;">new</span> <span style="color: #2b91af;">WindowInteropHelper</span>(<span style="color: #2b91af;">Application</span>.Current.MainWindow);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">IntPtr</span> ieHwnd = GetAncestor(wih.Handle, 2 <span style="color: green;">/*GA_ROOT*/</span>);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> PostMessage(ieHwnd, 0x10<span style="color: green;">/*WM_CLOSE*/</span>, <span style="color: #2b91af;">IntPtr</span>.Zero, <span style="color: #2b91af;">IntPtr</span>.Zero);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> [<span style="color: #2b91af;">DllImport</span>(<span style="color: #a31515;">"user32"</span>, ExactSpelling = <span style="color: blue;">true</span>, CharSet = <span style="color: #2b91af;">CharSet</span>.Auto)]</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">extern</span> <span style="color: #2b91af;">IntPtr</span> GetAncestor(<span style="color: #2b91af;">IntPtr</span> hwnd, <span style="color: blue;">int</span> flags);</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> [<span style="color: #2b91af;">DllImport</span>(<span style="color: #a31515;">"user32"</span>, CharSet = <span style="color: #2b91af;">CharSet</span>.Auto)]</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">extern</span> <span style="color: blue;">bool</span> PostMessage(<span style="color: #2b91af;">IntPtr</span> hwnd, <span style="color: blue;">int</span> msg, <span style="color: #2b91af;">IntPtr</span> wparam, <span style="color: #2b91af;">IntPtr</span> lparam);</span></div>
</td></tr>
</tbody></table>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-20047695833651296172010-04-28T15:46:00.004+05:302010-04-28T15:51:00.945+05:30How to find the visual parent or child element using VisualTreeHelper<div class="Section1">
<div class="MsoNormal">
<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx">VisualTreeHelper</a> is very useful class which help us to find or drill-down element from the hosted container. </div>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
The following method will help you to find the visual <b><i><u>parent element</u></i></b> from the container.</div>
<div class="MsoNormal">
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 478.8pt;" valign="top" width="638"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> T FindVisualParent<T>(<span style="color: #2b91af;">UIElement</span> element) <span style="color: blue;">where</span> T : <span style="color: #2b91af;">UIElement</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">UIElement</span> parent = element;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">while</span> (parent != <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> T correctlyTyped = parent <span style="color: blue;">as</span> T;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (correctlyTyped != <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> correctlyTyped;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> parent = <span style="color: #2b91af;">VisualTreeHelper</span>.GetParent(parent) <span style="color: blue;">as</span> <span style="color: #2b91af;">UIElement</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span><br />
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
The following method will help you to find the <b><i><u>child element</u></i></b> from the container.</div>
<div class="MsoNormal">
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 509.9pt;" valign="top" width="680"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> T FindChild<T>(<span style="color: #2b91af;">DependencyObject</span> parent)<span style="color: blue;">where</span> T : <span style="color: #2b91af;">DependencyObject</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (parent == <span style="color: blue;">null</span>) <span style="color: blue;">return</span> <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<br />
<span style="font-family: "Courier New"; font-size: 10pt;"> T childElement = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> childrenCount = <span style="color: #2b91af;">VisualTreeHelper</span>.GetChildrenCount(parent);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i < childrenCount; i++)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">var</span> child = <span style="color: #2b91af;">VisualTreeHelper</span>.GetChild(parent, i);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> T childType = child <span style="color: blue;">as</span> T;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (childType == <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> childElement = FindChild<T>(child);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (childElement != <span style="color: blue;">null</span>) <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">else</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> childElement = (T)child;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> childElement;</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
</div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-59339464242733548132010-02-26T15:41:00.011+05:302011-05-27T15:38:59.040+05:30How to detect CTRL + ALT key combinations in WPF<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21820185-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="Section1">
<div class="MsoNormal" style="line-height: 150%; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Key combinations are a fancy pair of words to describe pressing/holding multiple keyboard buttons to perform a command. <br />
<br />
<div>
</div>
<b>Ex:-</b> Few of ever using key combinations are,<br />
<ul>
<li><b>Ctrl + S</b> to Save,</li>
<li><b>Ctrl + C</b> to Copy,</li>
<li><b>Alt + F4</b> to close an application,</li>
<li><b>Ctrl + Alt + Del </b>to lock our computer, etc., </li>
</ul>
</div>
There are many such combinations, and while I provided some common ones, many applications like Visual Studio provide their own key combinations to help save you some time. Let's add some key combinations to our little program also.<br />
<br />
<div class="MsoNormal" style="line-height: 150%; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
</div>
<div class="MsoNormal" style="line-height: 150%; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
</div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 478.8pt;" valign="top" width="638"><div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">void</span> SpecialKeyHandler(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">KeyEventArgs</span> e)</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Ctrl + N </span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> ((<span style="color: #2b91af;">Keyboard</span>.Modifiers == <span style="color: #2b91af;">ModifierKeys</span>.Control) && (e.Key == <span style="color: #2b91af;">Key</span>.N))</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"New"</span>);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<br />
<div>
</div>
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Ctrl + O </span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> ((<span style="color: #2b91af;">Keyboard</span>.Modifiers == <span style="color: #2b91af;">ModifierKeys</span>.Control) && (e.Key == <span style="color: #2b91af;">Key</span>.O))</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"Open"</span>);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<br />
<div>
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Ctrl + S </span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> ((<span style="color: #2b91af;">Keyboard</span>.Modifiers == <span style="color: #2b91af;">ModifierKeys</span>.Control) && (e.Key == <span style="color: #2b91af;">Key</span>.S))</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"Save"</span>);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<br />
<div>
</div>
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Ctrl + Alt + I </span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> ((<span style="color: #2b91af;">Keyboard</span>.Modifiers == (<span style="color: #2b91af;">ModifierKeys</span>.Alt | <span style="color: #2b91af;">ModifierKeys</span>.Control)) && (e.Key == <span style="color: #2b91af;">Key</span>.I))</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"Ctrl + Alt + I"</span>);</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
</div>
<br />
<div>
</div>
The key approach doesn't work for another reason because your commonly used <b>Alt, Ctrl, Shift</b>, and <b>Windows</b> keys can't be accessed from the Key enum at all. Instead, those four keys can only be accessed using the <i><a href="http://msdn.microsoft.com/en-us/library/system.windows.input.modifierkeys.aspx">ModifierKeys</a></i> enum and checking whether <i><a href="http://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.modifiers.aspx">Keyboard.Modifiers</a></i> is equal to that key. <br />
<br /></div>
</div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-15159947148416091822009-12-30T18:47:00.003+05:302009-12-31T10:12:47.704+05:30How to enable .NET Framework 3.5 SP1 Bootstrapper package in ClickOnce application.<div class=Section1> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'>I have struggled with the issue which I was not able to include the .NET Framework 3.5 SP1 bootstrapper package in my click once WPF XBAP application. Even If the .NET Framework 3.5 SP1 bootstrapper package is selected in the Prerequisite dialog box for a Setup project or in ClickOnce publishing, and also the "<b>Download prerequisites from the same location as my application</b>" option is selected, the following build error is shown: <o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'>The install location for prerequisites has not been set to '<b>component vendor's web site</b>' and the file '<b>dotNetFx35setup.exe</b>' in item '<b>Microsoft.Net.Framework.3.5.SP1</b>' cannot be located on disk. <o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'>To resolve this issue, please do the following steps:<o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'><b><span lang=EN-US>Update the Package Data</span></b><span lang=EN-US> <o:p></o:p></span></p> <ol start=1 type=1> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US>Open the <b><Drive>:</b>\<b>Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1</b> folder or <b>%ProgramFiles(x86)%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1</b> on x64 operating systems. <o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US>Edit the <b>Product.xml</b> file in Notepad.</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US>Paste the following into the </span><span lang=EN-US style='font-size:10.0pt; line-height:150%;font-family:"Courier New";color:#0066FF'><</span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:blue'>PackageFiles</span><span lang=EN-US style='font-size:10.0pt; line-height:150%;font-family:"Courier New";color:#0066FF'>></span><span lang=EN-US> element: <br> </span><span lang=EN-US style='font-size:10.0pt;line-height:150%; font-family:"Courier New";color:blue'><PackageFile </span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:red'>Name</span><span lang=EN-US style='font-size:10.0pt;line-height: 150%;font-family:"Courier New";color:blue'>="TOOLS\clwireg.exe"/><br> <PackageFile </span><span lang=EN-US style='font-size:10.0pt; line-height:150%;font-family:"Courier New";color:red'>Name</span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:blue'>="TOOLS\clwireg_x64.exe"/><br> <PackageFile </span><span lang=EN-US style='font-size:10.0pt; line-height:150%;font-family:"Courier New";color:red'>Name</span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:blue'>="TOOLS\clwireg_ia64.exe"/></span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> <li class=MsoNormal style='color:blue;mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US style='color:windowtext'>Find the element for </span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"'><PackageFile</span><span lang=EN-US style='color:windowtext'> </span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:red'>Name</span><span lang=EN-US style='font-size:10.0pt;line-height: 150%;font-family:"Courier New"'>="dotNetFX30\XPSEPSC-x86-en-US.exe"</span><span lang=EN-US style='color:windowtext'> and change the </span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"'>PublicKey</span><span lang=EN-US style='color:windowtext'> value to: </span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"'>3082010A0282010100A2DB0A8DCFC2C1499BCDAA3A34AD23596BDB6CBE2122B794C8EAAEBFC6D526C232118BBCDA5D2CFB36561E152BAE8F0DDD14A36E284C7F163F41AC8D40B146880DD98194AD9706D05744765CEAF1FC0EE27F74A333CB74E5EFE361A17E03B745FFD53E12D5B0CA5E0DD07BF2B7130DFC606A2885758CB7ADBC85E817B490BEF516B6625DED11DF3AEE215B8BAF8073C345E3958977609BE7AD77C1378D33142F13DB62C9AE1AA94F9867ADD420393071E08D6746E2C61CF40D5074412FE805246A216B49B092C4B239C742A56D5C184AAB8FD78E833E780A47D8A4B28423C3E2F27B66B14A74BD26414B9C6114604E30C882F3D00B707CEE554D77D2085576810203010001 <o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US>Find the element for </span><span lang=EN-US style='font-size:10.0pt;line-height: 150%;font-family:"Courier New";color:blue'>< PackageFile</span><span lang=EN-US> </span><span lang=EN-US style='font-size:10.0pt;line-height: 150%;font-family:"Courier New";color:red'>Name</span><span lang=EN-US style='font-size:10.0pt;line-height:150%;font-family:"Courier New"; color:blue'>="dotNetFX30\XPSEPSC-amd64-en-US.exe"</span><span lang=EN-US> and change the </span><span lang=EN-US style='font-size:10.0pt; line-height:150%;font-family:"Courier New";color:blue'>PublicKey</span><span lang=EN-US> value to the same as in step 4 above</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l3 level1 lfo1'><span lang=EN-US>Save the <b>product.xml</b> file</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> </ol> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'><b><span lang=EN-US>Download and Extract the Core Installation Files</span></b><span lang=EN-US> <o:p></o:p></span></p> <ol start=1 type=1> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l0 level1 lfo2'><span lang=EN-US>Navigate to the following URL: <a href="http://go.microsoft.com/fwlink?LinkID=118080">http://go.microsoft.com/fwlink?LinkID=118080</a><o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l0 level1 lfo2'><span lang=EN-US>Download the <b><i><u><span style='color:blue'>dotNetFx35.exe</span></u></i></b> file to your local disk.</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l0 level1 lfo2'><span lang=EN-US>Open a Command Prompt window and change to the directory to which you downloaded dotNetFx35.exe.</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l0 level1 lfo2'><span lang=EN-US>At the command prompt, type: <br> <b><span style='color:blue'>dotNetFx35.exe /x:</span></b><br> This will extract the Framework files to a folder named “<b>WCU</b>” in the current directory. <o:p></o:p></span></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%;mso-list:l0 level1 lfo2'><span lang=EN-US>Copy the contents of the <b>WCU\dotNetFramework</b> folder and paste them in the <b>%Program Files%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1</b> fo<b>lder (%ProgramFiles(x86)%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1</b> on <b>x64</b> operating systems). <o:p></o:p></span></li> </ol> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:36.0pt;line-height:150%'><b><span lang=EN-US style='color:red'>Note:</span></b><span lang=EN-US style='color:red'> </span><span lang=EN-US>Do not copy the <b>WCU\dotNetFramework</b> folder itself. There should be 5 folders under the <b>WCU</b> folder, and each of these should now appear in the <b>DotNetFx35SP1</b> folder. The folder structure should resemble the following:<o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>DotNetFx35SP1 (folder) <o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>dotNetFX20 (folder)<o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US> dotNetFX30 (folder)</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>dotNetFX35 (folder)</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>dotNetMSP (folder)</span><span lang=EN-US> </span><span lang=EN-US><o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span lang=EN-US style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>TOOLS (folder)</span><span lang=EN-US> <o:p></o:p></span></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>en (or some other localized folder)</span><span lang=EN-US> </span><o:p></o:p></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;margin-left:54.0pt;text-indent:-18.0pt;line-height:150%;mso-list:l2 level1 lfo5'><![if !supportLists]><span style='font-family:Wingdings'><span style='mso-list:Ignore'>ü<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>dotNetFx35setup.exe (file)</span><span lang=EN-US> </span><o:p></o:p></p> <p class=MsoListParagraph style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;text-indent:-18.0pt;line-height:150%;mso-list:l0 level1 lfo2'><![if !supportLists]><span lang=EN-US><span style='mso-list:Ignore'>6.<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US>You may now delete the files and folders you downloaded and extracted in steps 2 and 4.<o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'>Please refer the following link for more details.<o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; line-height:150%'><a href="http://download.microsoft.com/download/A/2/8/A2807F78-C861-4B66-9B31-9205C3F22252/VS2008SP1Readme.htm#General%20Issues">http://download.microsoft.com/download/A/2/8/A2807F78-C861-4B66-9B31-9205C3F22252/VS2008SP1Readme.htm#General%20Issues</a><o:p></o:p></p> </div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-14019796339388783512009-12-18T13:04:00.002+05:302009-12-18T13:06:21.858+05:30How to read all countries using C#<div class="Section1">
<div class="MsoNormal" style="line-height: 18pt;">
<span style="color: #333333; font-family: "Verdana", "sans-serif"; font-size: 10pt;">We can use <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx">CultureInfo</a> & </span><span lang="EN" style="color: #333333; font-family: "Verdana", "sans-serif"; font-size: 10pt;"><a href="http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.aspx">RegionInfo</a></span><b><span lang="EN" style="color: black; font-family: "Arial", "sans-serif"; font-size: 15pt;"> </span></b><span style="color: #333333; font-family: "Verdana", "sans-serif"; font-size: 10pt;">class for getting all the countries information. From the CultureInfo class, we can get all the Culture information available in .Net Framework. Then we can use RegionInfo class for reading all the information about the region along with the Country name. Please use the following code snippet to achieve this.</span><br />
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none;"><tbody>
<tr style="height: 246.35pt;"><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; height: 246.35pt; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 744.85pt;" valign="top" width="993"><div class="MsoNormal">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">static</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;">{</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">List</span><<span style="color: blue;">string</span>> countriesList = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: blue;">string</span>>();</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">CultureInfo</span> culture <span style="color: blue;">in</span> <span style="color: #2b91af;">CultureInfo</span>.GetCultures(<span style="color: #2b91af;">CultureTypes</span>.AllCultures & ~<span style="color: #2b91af;">CultureTypes</span>.NeutralCultures))</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (!<span style="color: blue;">string</span>.IsNullOrEmpty(culture.Name))</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> {</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">RegionInfo</span> ri = <span style="color: blue;">new</span> <span style="color: #2b91af;">RegionInfo</span>(culture.LCID);</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span> (!countriesList.Contains(ri.EnglishName))</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> countriesList.Add(ri.EnglishName);</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> }</span><br />
<br />
<span style="font-family: "Courier New"; font-size: 10pt;"> countriesList.Sort();</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span><br />
</div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> str <span style="color: blue;">in</span> countriesList)</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(str);</span><span style="font-family: "Courier New"; font-size: 10pt;"> </span><br />
</div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #2b91af;">Console</span>.ReadLine();</span><br />
</div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;">}</span><br />
</div>
</td></tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 18pt;">
<span style="color: #333333; font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span><br />
</div>
<br />
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-90274280803575246902009-12-16T15:22:00.001+05:302009-12-16T15:26:47.667+05:30How to get all Culture information using C#<div class="Section1"><div class="MsoNormal">The <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx">CultureInfo</a> class will provide us all Culture information available in .Net Framework. <span lang="EN" style="mso-ansi-language: EN;"><span style="mso-spacerun: yes;"> </span>You can use <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultures.aspx">CultureInfo.GetCultures</a> static method for getting all the culture information. To get associated specific culture, please use static method <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.cultureinfo.createspecificculture.aspx">CultureInfo.CreateSpecificCulture</a>.</span><span lang="EN" style="mso-ansi-language: EN;"> </span><br />
</div><br />
<span lang="EN" style="mso-ansi-language: EN;">The following example will show you how to get all culture information.</span><br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 594.95pt;" valign="top" width="793"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: blue;">static </span><span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)</span><br />
<div class="MsoNormal" style="mso-layout-grid-align: none;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">{</span><br />
<span style="font-family: Courier New;"><span style="font-size: x-small;"> <span style="font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"></span><span style="color: green;">// Get culture names</span></span></span></span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: #2b91af;"> List</span><<span style="color: blue;">string</span>> list = <span style="color: blue;">new </span><span style="color: #2b91af;">List</span><<span style="color: blue;">string</span>>();</span><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">foreach </span>(<span style="color: #2b91af;">CultureInfo</span> ci <span style="color: blue;">in </span><span style="color: #2b91af;">CultureInfo</span>.GetCultures(<span style="color: #2b91af;">CultureTypes</span>.AllCultures))</span><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: blue;"> string </span>specName = <span style="color: #a31515;">"(none)"</span>;</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: blue;"> try </span>{ specName = <span style="color: #2b91af;">CultureInfo</span>.CreateSpecificCulture(ci.Name).Name;}</span><br />
</div><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">catch</span>(<span style="color: #2b91af;">Exception</span>) { }</span><br />
<br />
<div class="MsoNormal" style="mso-layout-grid-align: none;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>list.Add(<span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"{0,-12}{1,-12}{2}"</span>, ci.Name, specName, ci.EnglishName));</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> }</span><br />
</div><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> list.Sort(); </span><br />
<br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: #2b91af;"> Console</span>.WriteLine(<span style="color: #a31515;">"CULTURE<span style="mso-spacerun: yes;"> </span>SPEC.CULTURE<span style="mso-spacerun: yes;"> </span>ENGLISH NAME"</span>);</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: #2b91af;"> Console</span>.WriteLine(<span style="color: #a31515;">"----------------------------------------------------"</span>);</span><br />
<br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">foreach </span>(<span style="color: blue;">string</span> str <span style="color: blue;">in </span>list)</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: #2b91af;"> Console</span>.WriteLine(str);</span><br />
<br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="color: #2b91af;"> Console</span>.ReadLine();</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">}</span><br />
</td></tr>
</tbody></table><br />
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-5454209805132632522009-11-03T13:08:00.005+05:302009-11-05T11:50:22.281+05:30How to load the WPF controls dynamically at Runtime<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; line-height: 150%;">In order to load the WPF controls dynamically at Runtime,<span style="mso-spacerun: yes;"> </span>please do the following steps.</span><br />
<br />
<ul><div class="MsoListParagraph" style="line-height: 150%; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify; text-indent: -18pt;"></div>
</ul><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; line-height: 150%;">1. Create a dummy XAML content file (Dynamic_Content.xaml) with Controls details.</span><br />
<ul><div class="MsoListParagraph" style="line-height: 150%; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify; text-indent: -18pt;"></div>
</ul><div style="background: #f2f2f2; border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; border-right: windowtext 1pt solid; border-top: windowtext 1pt solid; margin-left: 36pt; margin-right: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; padding-top: 1pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">StackPanel</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: red;"><span style="mso-spacerun: yes;"> </span>xmlns</span><span style="color: blue;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: red;"><span style="mso-spacerun: yes;"> </span>xmlns</span><span style="color: blue;">:</span><span style="color: red;">x</span><span style="color: blue;">="http://schemas.microsoft.com/winfx/2006/xaml"></span></span><br />
<br />
<br />
<span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Button</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> x</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">:</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Name</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="buttonStart" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">IsEnabled</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="True"</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> Content</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="Start" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Height</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="25"</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> Width</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="100" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Margin</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="5" /></span><br />
<span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Button</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> x</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">:</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Name</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="buttonStop" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">IsEnabled</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="False"</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> Content</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="Stop" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Height</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="25"</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> Width</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="100" </span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">Margin</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">="5" /></span><br />
<br />
<br />
<div class="MsoListParagraph" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin-left: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">StackPanel</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">></span><br />
</div></div><br />
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; line-height: 150%;">2. Select the file (Dynamic_Content.xaml) in Solution Explorer and <span style="mso-spacerun: yes;"> </span>go to the properties.</span><br />
<br />
<span style="font-family: Trebuchet MS;"><span style="font-size: x-small;">3. <span style="font-size: 10pt; line-height: 150%;">Set “Build Action” as “Content” and “Copy to Output Directory” as “Copy always”.</span></span></span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: Trebuchet MS;">4. <span style="font-size: 10pt; line-height: 150%;">Then you can use </span></span><u><span style="color: #0070c0; font-family: "Courier New"; font-size: 10pt; line-height: 150%;"><a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx"><span style="color: #0070c0;">XamlReader</span></a></span></u><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt; line-height: 150%;"> class for reading the XAML content which we have the controls.</span></span><br />
<br />
<span style="font-family: Trebuchet MS;"><span style="font-size: x-small;">5. <span style="font-size: 10pt; line-height: 150%;">Please use the following code to read and load controls from XAML content file.</span></span></span><br />
<br />
<br />
<div style="background: #f2f2f2; border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; border-right: windowtext 1pt solid; border-top: windowtext 1pt solid; margin-left: 36pt; margin-right: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; padding-top: 1pt;"><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">private</span><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> <span style="color: blue;">void </span>tab_TabItemAdded(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">TabItemEventArgs</span> e)</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">{</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">FileStream</span> stream = <span style="color: blue;">new </span><span style="color: #2b91af;">FileStream</span>(<span style="color: #a31515;">@"Dynamic_Content.xaml"</span>, <span style="color: #2b91af;">FileMode</span>.Open, <span style="color: #2b91af;">FileAccess</span>.Read);</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">StackPanel</span> panel = <span style="color: #2b91af;">XamlReader</span>.Load(stream) <span style="color: blue;">as</span> <span style="color: #2b91af;">StackPanel</span>;</span><br />
</div><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>e.TabItem.Content = panel;</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>e.TabItem.Header = <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"Tab Item - {0}"</span>, tab.Items.Count);</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>stream.Close();</span><br />
</div><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">Button</span> buttonStart = panel.Children[0] <span style="color: blue;">as</span> <span style="color: #2b91af;">Button</span>;</span><br />
</div><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>buttonStart.Click += <span style="color: blue;">new</span> <span style="color: #2b91af;">RoutedEventHandler </span>buttonStart_Click);<span style="mso-spacerun: yes;"> </span></span><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">}</span><br />
</div><div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"></span><br />
</div><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">void</span><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> buttonStart_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">RoutedEventArgs </span>e)</span><br />
</div><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">{</span><br />
<div class="MsoNormal" style="background: #f2f2f2; border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; padding-top: 0cm;"><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"Start button invloked"</span>);</span><br />
</div><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">}</span><br />
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-85447846282106540282009-10-30T14:37:00.007+05:302010-06-24T13:21:19.536+05:30How to push certificate to "Trusted root certificate authorities" using Installer<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;">In order to run your Full Trust enabled WPF XBAP application, you have to use “<b>Self signed certificate authority file</b>” for running and deploying XBAP application. The certificate should pushed it into “<b>Trusted Publisher</b>” and “<b>Authority Root</b>” certificate storages. You can use </span><span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;"><a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx"><span style="color: #0b5394;">X509Certificate2</span></a> </span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;">and</span><span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;"> <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509store.aspx"><span style="color: #073763;">X509Store</span></a> </span><span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;">classes in your installer assembly for pushing the certificate to certificate storage. Please use the following code snippet. </span><br />
<div class="Section1">
<br />
<div style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; border-right: windowtext 1pt solid; border-top: windowtext 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; padding-top: 1pt;">
<br />
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">string </span><span style="font-family: "Courier New"; font-size: 10pt;">certPath = <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">@"{0}\Aaa.cer"</span>, <span style="color: #2b91af;">Environment</span>.GetFolderPath(<span style="color: #2b91af;">Environment</span>.<span style="color: #2b91af;">SpecialFolder</span>.System));</span><br />
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;">X509Certificate2 </span><span style="font-family: "Courier New"; font-size: 10pt;">certificate = <span style="color: blue;">new</span> <span style="color: #2b91af;">X509Certificate2</span>(certPath);</span><br />
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;">X509Store</span><span style="font-family: "Courier New"; font-size: 10pt;"> trustedPublisherStore = <span style="color: blue;">new</span> <span style="color: #2b91af;">X509Store</span>(<span style="color: #2b91af;">StoreName</span>.TrustedPublisher, <span style="color: #2b91af;">StoreLocation</span>.LocalMachine);</span><br />
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;">X509Store</span><span style="font-family: "Courier New"; font-size: 10pt;"> trustedAuthorityRootStore = <span style="color: blue;">new</span> <span style="color: #2b91af;">X509Store</span>(<span style="color: #2b91af;">StoreName</span>.AuthRoot, <span style="color: #2b91af;">StoreLocation</span>.LocalMachine);</span><br />
<br />
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">try</span><br />
<span style="font-family: "Courier New"; font-size: 10pt;">{</span><span style="font-family: "Courier New"; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: Courier New; font-size: x-small;"> </span><span style="font-size: 10pt;"><span style="font-family: Courier New;">trustedPublisherStore.Open(<span style="color: #2b91af;">OpenFlags</span>.ReadWrite);</span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: Courier New; font-size: x-small;"> </span><span style="font-size: 10pt;"><span style="font-family: Courier New;">trustedPublisherStore.Add(certificate);</span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: Courier New; font-size: x-small;"> </span><span style="font-size: 10pt;"><span style="font-family: Courier New;">trustedAuthorityRootStore.Open(<span style="color: #2b91af;">OpenFlags</span>.ReadWrite);</span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: Courier New; font-size: x-small;"> </span><span style="font-size: 10pt;"><span style="font-family: Courier New;">trustedAuthorityRootStore.Add(certificate);</span></span><br />
<span style="font-family: "Courier New"; font-size: 10pt;">}</span><br />
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">catch</span><span style="font-family: "Courier New"; font-size: 10pt;"> (<span style="color: #2b91af;">Exception </span>ex)</span><br />
<span style="font-family: "Courier New"; font-size: 10pt;">{</span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: "Courier New"; font-size: 10pt;"><span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt;"> MessageBox</span><span style="font-family: "Courier New"; font-size: 10pt;">.Show(ex.Message + <span style="color: #a31515;">"\n\n"</span> + ex.StackTrace);</span><br /><span style="font-family: "Courier New"; font-size: 10pt;">}</span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: "Courier New"; font-size: 10pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">finally</span><br /><span style="font-family: "Courier New"; font-size: 10pt;">{</span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="font-family: "Courier New"; font-size: 10pt;"><span style="font-family: "Courier New"; font-size: 10pt;">trustedPublisherStore.Close();</span></span></span></div>
<div class="MsoNormal" style="background: #f2f2f2;">
<span style="font-family: "Courier New"; font-size: 10pt;"><span style="font-family: "Courier New"; font-size: 10pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> trustedAuthorityRootStore.Close();</span><br /><span style="font-family: "Courier New"; font-size: 10pt;">}</span></span></span></div>
</div>
<br />
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;">For more information about <span class="MsoHyperlink"><a href="http://savij.com/2007/02/19/5/" title="Permanent Link to Signing & Deploying CAB Based ClickOnce Code">Signing & Deploying CAB Based ClickOnce Code</a>.</span></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;">Please refer the following link to know more about “<b>WPF - XBAP as Full Trust Application</b>”</span></div>
<br />
<div class="MsoNormal">
<span style="color: #073763; font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"><a href="http://blogs.microsoft.co.il/blogs/maxim/archive/2008/03/05/wpf-xbap-as-full-trust-application.aspx">http://blogs.microsoft.co.il/blogs/maxim/archive/2008/03/05/wpf-xbap-as-full-trust-application.aspx</a></span><br />
<br /></div>
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com2tag:blogger.com,1999:blog-8107153432545906959.post-33864535391680193622009-09-25T12:09:00.007+05:302009-12-17T11:50:10.698+05:30Reading file from local system in Silverlight application<span style="color: #333333; font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog(VS.95).aspx">OpenFileDialog</a> class will help us to read the one or more files from local system. The<br />following code snippet will help us to read the file from local machine.</span><span style="color: #333333; font-family: "Trebuchet MS", "sans-serif"; font-size: 10pt;"> </span><br />
<div class="Section1">
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #f2f2f2; border-bottom: medium none; border-collapse: collapse; border-left: medium none; border-right: medium none; border-top: medium none; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"><td style="border-bottom: black 1pt solid; border-left: black 1pt solid; border-right: black 1pt solid; border-top: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; padding-bottom: 0cm; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0cm; width: 478.8pt;" valign="top" width="638"><span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">OpenFileDialog</span><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> file = <span style="color: blue;">new</span> <span style="color: #2b91af;">OpenFileDialog</span>();</span><br />
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">file.Filter = <span style="color: #a31515;">"Text files (*.txt)|*.txt|All Files(*.*)|*.*"</span>;</span><br />
<br />
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">if</span><span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"> (file.ShowDialog() == <span style="color: blue;">true</span>)</span><br />
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">{</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">using</span> (<span style="color: #2b91af;">StreamReader</span> reader = file.File.OpenText())</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">this</span>.txtFileContent.Text = reader.ReadToEnd();</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>reader.Close();</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}</span><br />
</div>
<div class="MsoNormal" style="mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-no-proof: yes;">}</span><br />
</div>
</td></tr>
</tbody></table>
<br />
</div>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-35688816471942715002009-05-10T09:18:00.003+05:302009-05-10T09:24:50.826+05:30Signing assembly<strong>Sy:- </strong><br /><span style="font-family:courier new;"><span style="font-size:85%;">sn [-q-quiet] <option>[<parameters>]<br /><strong></strong></span></span><br /><strong>Options:-</strong><br /><span style="font-family:courier new;font-size:85%;">-c [<csp>]<br />Set/reset the name of the CSP to use for MSCORSN operations.<br />-d <container><br />Delete key container named <container>.<br />-D <assembly1><assembly2><br />Verify <assembly1>and <assembly2>differ only by signature.<br />-e <assembly><outfile><br />Extract public key from <assembly>into <outfile>.<br />-i <infile><container><br />Install key pair from <infile>into a key container named <container>.<br />-k [<keysize>] <outfile><br />Generate a new key pair of the specified size and write it into <outfile>.<br />-m [yn]<br />Enable (y), disable (n) or check (no parameter) whether key containers<br />are machine specific (rather than user specific).<br />-o <infile>[<outfile>]<br />Convert public key in <infile>to text file <outfile>with comma separated<br />list of decimal byte values.<br />If <outfile>is omitted, text is copied to clipboard instead.<br />-p <infile><outfile><br />Extract public key from key pair in <infile>and export to <outfile>.<br />-pc <container><outfile><br />Extract public key from key pair in <container>and export to <outfile>.<br />-Pb [yn]<br />Enable (y), disable (n) or check (no parameters) the CLR policy allowing<br />trusted applications to bypass strong name signature verification on their<br />assemblies.<br />-q<br />Quiet mode. This option must be first on the command line and will suppress<br />any output other than error messages.<br />-R[a] <assembly><infile><br />Re-sign signed or partially signed assembly with the key pair in <infile>.<br />If -Ra is used, hashes are recomputed for all files in the assembly.<br />-Rc[a] <assembly><container><br />Re-sign signed or partially signed assembly with the key pair in the key<br />container named <container>.<br />If -Rca is used, hashes are recomputed for all files in the assembly.<br />-Rh <assembly><br />Re-compute hashes for all files in the assembly.<br />-t[p] <infile><br />Display token for public key in <infile>(together with the public key<br />itself if -tp is used).<br />-T[p] <assembly><br />Display token for public key of <assembly>(together with the public key<br />itself if -Tp is used).<br />-TS <assembly><infile><br />Test-sign signed or partially signed assembly with the key pair in<br /><infile>.<br />-TSc <assembly><container><br />Test-sign signed or partially signed assembly with the key pair in the key<br />container named <container>.<br />-v[f] <assembly><br />Verify <assembly>for strong name signature self consistency. If -vf is<br />specified, force verification even if disabled in the registry.<br />-Vl<br />List current settings for strong name verification on this machine.<br />-Vr <assembly>[<userlist>] [<infile>]<br />Register <assembly>for verification skipping (with an optional, comma<br />separated list of usernames for which this will take effect and an<br />optional test public key in <infile>).<br /><assembly>can be specified as * to indicate all assemblies or *,<public> to<br />indicate that all assemblies with the given public key token. Public key<br />tokens should be specified as a string of hex digits.<br />-Vu <assembly><br />Unregister <assembly>for verification skipping. The same rules for<br /><assembly>naming are followed as for -Vr.<br />-Vx<br />Remove all verification skipping entries.<br />-?<br />-h<br />Displays this help text.<br /></span><br /><strong>Ex:-</strong><br /><span style="font-size:85%;"><span style="font-family:courier new;">sn -R "aeembly name.dll" "keyfile.snk"</span> </span><br /><strong></strong><br /><strong>For more Info:-</strong><br /><a href="http://msdn.microsoft.com/en-us/library/k5b5tt23.aspx"><span style="font-family:trebuchet ms;font-size:85%;">http://msdn.microsoft.com/en-us/library/k5b5tt23.aspx</span></a>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-54222631861579677452008-03-11T12:55:00.000+05:302008-03-11T12:55:04.875+05:30Daily Fun, Quote, Motivation, Inspiration, Joke, Astrology, Music, Tips for daily life..: Motivational<a href="http://mydailyfun.blogspot.com/search/label/Motivational">Daily Fun, Quote, Motivation, Inspiration, Joke, Astrology, Music, Tips for daily life..: Motivational</a>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-74306781824960199932008-02-15T14:36:00.000+05:302008-02-15T14:36:45.156+05:30pinvoke.net: the interop wiki!<a href="http://www.pinvoke.net/">pinvoke.net: the interop wiki!</a>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com1tag:blogger.com,1999:blog-8107153432545906959.post-14002914357307211692008-01-10T18:23:00.000+05:302008-01-10T18:23:11.525+05:30Using C# to turn On/Off local area network connection during NUnit test.<a href="http://konsulent.sandelien.no/VB_help/Network/">Using C# to turn On/Off local area network connection during NUnit test.</a>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0tag:blogger.com,1999:blog-8107153432545906959.post-49584705159007624362008-01-07T10:34:00.000+05:302008-01-07T10:34:59.741+05:30Code Samples<a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336738.aspx">Code Samples</a>PRABU PICHAIhttp://www.blogger.com/profile/15183216276336767550noreply@blogger.com0