<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>WPF on Ash Tewari</title><link>https://www.tewari.info/category/wpf/</link><description>Recent content in WPF on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Mon, 10 Mar 2014 01:58:22 +0000</lastBuildDate><atom:link href="https://www.tewari.info/category/wpf/feed.xml" rel="self" type="application/rss+xml"/><item><title>Announcing CodeDemo</title><link>https://www.tewari.info/2014/03/09/announcing-codedemo/</link><pubDate>Mon, 10 Mar 2014 01:58:22 +0000</pubDate><guid>https://www.tewari.info/2014/03/09/announcing-codedemo/</guid><description>&lt;p&gt;It is a challenge to use code snippets in presentations, demos and live coding sessions. I have struggled with this and seen many speakers jumping through hoops to assimilate code snippets in their demos. I had to create something to ease this pain.&lt;/p&gt;&#10;&lt;p&gt;Today, I am announcing the general availability of &lt;a class="link" href="http://codedemo.net/" title="CodeDemo website"&#10; target="_blank" rel="noopener"&#10; &gt;CodeDemo&lt;/a&gt;. A tool for instructors, presenters and speakers who create instructional demos, record screen-casts or do live presentations. CodeDemo pastes code snippets into your favorite IDE without getting in your way.&lt;/p&gt;&#10;&lt;p&gt;I decided not to open-source CodeDemo to challenge myself to an exercise in commercialization. I decided to learn about entrepreneurship, marketing, sales, licensing and other aspects of software commercialization. It has been an MBA&amp;rsquo;s worth of education so far. This journey is not over yet. I am taking the &lt;a class="link" href="http://theleanstartup.com/principles" title="The Lean Startup"&#10; target="_blank" rel="noopener"&#10; &gt;Lean&lt;/a&gt; approach of creating a &lt;a class="link" href="http://en.wikipedia.org/wiki/Minimum_viable_product" title="minimum viable product"&#10; target="_blank" rel="noopener"&#10; &gt;Minimum Viable Product&lt;/a&gt;. The future of CodeDemo, its feature set and the price, will be shaped by the traction it gets in the market, the feedback from the customers as well as patterns of use reported by the users.&lt;/p&gt;&#10;&lt;p&gt;Head over to &lt;a class="link" href="http://codedemo.net" target="_blank" rel="noopener"&#10; &gt;http://codedemo.net&lt;/a&gt; to grab a copy for yourself. Let me know if find it useful - I will be very excited to hear from you.&lt;/p&gt;&#10;&lt;p&gt;Here is a quick 2 minute introduction to CodeDemo :&lt;/p&gt;&#10;&lt;p&gt;[youtube]aFn3boBAWjw[/youtube]&lt;/p&gt;&#10;</description></item><item><title>Remove ListBoxItem Highlighting</title><link>https://www.tewari.info/2011/04/29/remove-listboxitem-highlighting/</link><pubDate>Sat, 30 Apr 2011 03:25:58 +0000</pubDate><guid>https://www.tewari.info/2011/04/29/remove-listboxitem-highlighting/</guid><description>&lt;p&gt;A Silverlight/Wpf ListBoxItem is highlighted when selected or when the mouse hovers over it.&lt;/p&gt;&#10;&lt;p&gt;I need to display a list of items that are not highlighted when selected. This is a common scenario when displaying an inactive list for simply listing out some information.&lt;/p&gt;&#10;&lt;p&gt;ListBoxItem&amp;rsquo;s default template can be easily inspected and modified using Expression Blend - Select a ListBoxItem in Objects and Timeline pane, Right click and select Edit template &amp;gt; Edit a Copy. Name you template and save it at the scope of your choice.&lt;/p&gt;&#10;&lt;p&gt;This will create a copy of the template and allow you to modify it. Switch to the xaml view. Locate the VisualStates of MouseOver, Selected and Focused, and blank them out -&lt;/p&gt;&#10;&lt;p&gt;&lt;img alt="de-highlighted-xaml" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/wp-content/2011-04-29_2257.png"&gt;&lt;/p&gt;&#10;&lt;p&gt;The style is applied to the ListBoxItems using ItemContainerStyle -&lt;/p&gt;&#10;&lt;p&gt;&lt;img alt="applying-style-to-listboxitems" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/wp-content/2011-04-29_2307.png"&gt;&lt;/p&gt;&#10;&lt;p&gt;Here is the xaml style for the ListBoxItem -&lt;/p&gt;&#10;&lt;p&gt;After the style is applied, the ListBoxItems are not highlighted when selected or focused. Here is a live demo of a ListBox that does not highlight when items are selected : &lt;a class="link" href="https://www.tewari.info/remove-listboxitem-highlighting-demo/" &gt;remove-listboxitem-hlighting-demo&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>Using Model-View-ViewModel in WPF Applications</title><link>https://www.tewari.info/2010/01/25/using-model-view-viewmodel-in-wpf-applications/</link><pubDate>Mon, 25 Jan 2010 22:23:39 +0000</pubDate><guid>https://www.tewari.info/2010/01/25/using-model-view-viewmodel-in-wpf-applications/</guid><description>&lt;p&gt;I am presenting at &lt;a class="link" href="http://www.socalcodecamp.com/" title="socalcodecamp website"&#10; target="_blank" rel="noopener"&#10; &gt;SoCalCodeCamp&lt;/a&gt; this weekend (January 30th, 2010) - &lt;a class="link" href="http://www.socalcodecamp.com/socalcodecamp/session.aspx?sid=0b2ee44f-595d-4f55-a5d6-2b1293f546d0" title="WPF MVVM Presntation "&#10; target="_blank" rel="noopener"&#10; &gt;Advanced WPF - Using Model-View-ViewModel in WPF Applications&lt;/a&gt;.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/tasklist.png"&#10;&#9;&#9;&#9;alt="tasklist-mockup"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;tasklist-mockup&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Agenda :&lt;/p&gt;&#10;&lt;p&gt;1. Roles of the M-V-VM triad&lt;/p&gt;&#10;&lt;p&gt;2. Why use M-V-VM ?&lt;/p&gt;&#10;&lt;p&gt;3. Characteristics of the ViewModel&lt;/p&gt;&#10;&lt;p&gt;4. Build a Sample WPF Application using M-V-VM&lt;/p&gt;&#10;&lt;p&gt;Resources :&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&lt;a class="link" href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" title="MSDN Magazine Article"&#10; target="_blank" rel="noopener"&#10; &gt;MSDN Magazine Article&lt;/a&gt; and Sample Application &lt;a class="link" href="http://code.msdn.microsoft.com/mag200902MVVM/Release/ProjectReleases.aspx" title="Download Demo Application Code"&#10; target="_blank" rel="noopener"&#10; &gt;Download&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="http://martinfowler.com/eaaDev/PresentationModel.html" title="MartinFowler.com"&#10; target="_blank" rel="noopener"&#10; &gt;Martin Fowler’s description of the ‘Presentation Model ‘&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="http://codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx" title="Jeremy Miller&amp;#39;s - Build Your CAB"&#10; target="_blank" rel="noopener"&#10; &gt;Jeremy Miller’s ‘Build Your Own CAB’ series&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;</description></item><item><title>Dial Gauge is a ProgressBar</title><link>https://www.tewari.info/2008/06/10/dial-gauge-is-a-progressbar/</link><pubDate>Wed, 11 Jun 2008 06:49:43 +0000</pubDate><guid>https://www.tewari.info/2008/06/10/dial-gauge-is-a-progressbar/</guid><description>&lt;p&gt;I am not just being philosophical here. In &lt;a class="link" href="http://msdn.microsoft.com/en-us/netframework/aa663326.aspx" title="MSDN-WPF"&#10; target="_blank" rel="noopener"&#10; &gt;WPF&lt;/a&gt;, &lt;a class="link" href="http://msdn.microsoft.com/en-us/magazine/cc163497.aspx" title="Using Templates to Customize WPF Controls"&#10; target="_blank" rel="noopener"&#10; &gt;ControlTemplates&lt;/a&gt; allow you to transform a control&amp;rsquo;s appearance. This is not the same as applying stylesheets. This is an entirely new level of customization. What you see in the screenshot below looks like a Dial but is actually a simple ProgressBar control wearing a &amp;ldquo;Dial&amp;rdquo; template. The Dial template was created using &lt;a class="link" href="http://www.microsoft.com/expression/products/Overview.aspx?key=blend" title="Microsoft-Expression-Blend"&#10; target="_blank" rel="noopener"&#10; &gt;Microsoft Expression Blend&lt;/a&gt; .&lt;/p&gt;&#10;&lt;p&gt;&lt;img alt="dial-is-a-progressbar.PNG" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/images/dial-is-a-progressbar.PNG"&gt;&lt;/p&gt;&#10;&lt;p&gt;Include the ControlTemplate as a Window.Resource and then assign it to ProgressBar element&amp;rsquo;s Template attribute :&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of course that is not all. The ControlTemplate must define some named elements of FrameworkElement type. Charles Petzold has explained it in detail : &lt;a class="link" href="http://msdn.microsoft.com/en-us/magazine/cc163497.aspx" title="Charles-Petzold-Using Templates to Customize WPF Controls"&#10; target="_blank" rel="noopener"&#10; &gt;MSDN Magazine Article&lt;/a&gt;. So, I will not repeat it here.&lt;/p&gt;&#10;&lt;p&gt;The sample code can be downloaded here : &lt;a class="link" href="https://www.tewari.info/downloads/DialTest.zip" title="DialTest.zip"&#10; &gt;DialTest.zip&lt;/a&gt;&#10;License : &lt;a class="link" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/" target="_blank" rel="noopener"&#10; &gt;Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>Using Custom Converter in XAML</title><link>https://www.tewari.info/2008/04/15/using-custom-converter-in-xaml/</link><pubDate>Wed, 16 Apr 2008 05:22:12 +0000</pubDate><guid>https://www.tewari.info/2008/04/15/using-custom-converter-in-xaml/</guid><description>&lt;p&gt;In my previous post : &lt;a class="link" href="https://www.tewari.info/2008/03/07/wpf-linq-to-sql-sample/" title="wpf-linq-to-sql-sample"&#10; &gt;WPF-LINQ To SQL Sample&lt;/a&gt;, I had to resort to modifying .dbml file to get the images stored as varbinary into the WPF ListView control. I had to change the Type of image fields to System.Byte[], instead of using System.Data.Linq.Binary. A better way to do this is to use a custom converter. WPF allows you to specify custom converter as part of the Binding in .xaml, like this -&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;Image Grid.Row=&amp;#34;2&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Source=&amp;#34;{Binding Path=ThumbNailPhoto ,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Converter={StaticResource imageConverter}}&amp;#34;&amp;gt;&amp;lt;/Image&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The custom converter is declared in the same .xaml file as a resource -&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;Window.Resources&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;local:ImageDataConverter x:Key=&amp;#34;imageConverter&amp;#34; /&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;/Window.Resources&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ImageDataConverter is implemented in .xaml.cs file -&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;public class ImageDataConverter : IValueConverter&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; public object Convert(object value, Type targetType, object parameter,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; System.Globalization.CultureInfo culture)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; byte[] image = ((System.Data.Linq.Binary)value).ToArray();&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; return image;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; public object ConvertBack(object value, Type targetType, object parameter,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; System.Globalization.CultureInfo culture)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; throw new NotSupportedException();&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The updated sample code can be downloaded here : &lt;a class="link" href="https://www.tewari.info/downloads/Linq2SqlSample2.zip" title="Linq2SqlSample2.zip"&#10; &gt;WPF-LINQ to SQL Sample&lt;/a&gt;&#10;License : &lt;a class="link" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/" target="_blank" rel="noopener"&#10; &gt;Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>WPF - LINQ to SQL Sample</title><link>https://www.tewari.info/2008/03/07/wpf-linq-to-sql-sample/</link><pubDate>Fri, 07 Mar 2008 07:15:35 +0000</pubDate><guid>https://www.tewari.info/2008/03/07/wpf-linq-to-sql-sample/</guid><description>&lt;p&gt;This exercise in binding a WPF ListView control with LINQ to SQL was a lot of fun ! The following image shows data from &lt;a class="link" href="http://www.codeplex.com/MSFTDBProdSamples" title="MSSQL Sample Databases"&#10; target="_blank" rel="noopener"&#10; &gt;AdventureWorks&lt;/a&gt; sample database displayed in the ListView control. The end result is very admirable, even in this very basic demo. Feeling a complete sense of freedom is unavoidable when working with WPF.&lt;/p&gt;&#10;&lt;p&gt;&lt;img alt="Linq2SqlSample1.Png" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/images/Linq2SqlSample1.Png"&gt;&lt;/p&gt;&#10;&lt;p&gt;This sample demonstrates :&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;LINQ to SQL mapping.&lt;/li&gt;&#10;&lt;li&gt;WPF ListView Control DataBinding.&lt;/li&gt;&#10;&lt;li&gt;Displaying images stored in database as varbinary in WPF control.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;The sample code can be downloaded here : &lt;a class="link" href="https://www.tewari.info/downloads/Linq2SqlSample.zip" title="Linq2SqlSample.zip"&#10; &gt;WPF-LINQ to SQL Sample&lt;/a&gt;&#10;License : &lt;a class="link" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/" target="_blank" rel="noopener"&#10; &gt;Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.&lt;/a&gt; &lt;a class="link" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/" target="_blank" rel="noopener"&#10; &gt;&lt;img alt="Creative Commons License" class="gallery-image" data-flex-basis="681px" data-flex-grow="283" height="31" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="http://i.creativecommons.org/l/by-nc-sa/3.0/us/88x31.png" width="88"&gt;&lt;/a&gt;&lt;/p&gt;&#10;</description></item></channel></rss>