tag:blogger.com,1999:blog-70493166316929649222024-02-08T10:36:43.433-08:00My.RAM.Serialize()Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.comBlogger48125tag:blogger.com,1999:blog-7049316631692964922.post-17851137603904858292011-03-04T09:02:00.000-08:002011-03-04T09:33:45.407-08:00A Time Of Transition...My time at KPMG has come to an end... As I reflect back on these past 3+ years, I've certainly learned more here than I ever have in my career. I attribute a lot of my success to one person.
<p>
I certainly owe a huge debt of gratitude to <a href="http://coolthingoftheday.blogspot.com/">Greg</a>. Through him, I was allowed to use the latest technologies, think outside of the box, and work on highly critical projects with a huge sense of responsibility.
</p>
Thanks, Greg. You've certainly been the best manager I've ever had (pretty sad huh :P), but not only that, you've also been a great mentor and friend. I really could not have gotten luckier when I landed the job at KPMG and became a part of your team. Thanks again.Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-50702027723035620182010-12-15T08:56:00.001-08:002010-12-15T08:59:45.531-08:00VB + C# Adventures (Final Part)<p>Now that I’ve been using <strong>C</strong># continuously for my current project, I can honestly say that I can switch between <strong>VB.NET</strong> and <strong>C#</strong> easily.  As I’ve said before, I learned <strong>.NET</strong> in <strong>C#</strong> a long time ago and personal projects are done in <strong>C#</strong>, but most of my production experience has been using <strong>VB.NET</strong>.  </p> <p>Do I regret having to use <strong>VB.NET</strong>?  Not at all, because it’s all about the framework, not the syntax.  I like being able to use both languages and achieve the same outcome.  Of course I can’t say that I know <strong>C#</strong> inside and out, but I can’t say the same about <strong>VB.NET </strong>either.  I also feel a sense of pride being able to do more than one language and not complain about it.  I still find it funny when my developer friends say something like “Oh I hate <strong>VB.NET</strong>.” or “I can program in <strong>C#</strong> about 3x faster than <strong>VB.NET</strong>.”</p> <p>So which language do I prefer?  I have always preferred <strong>C#</strong> over <strong>VB.NET</strong>, but I’ve never complained and never will, if I have to use <strong>VB.NET</strong> for a project.  Sometimes there’s no choice in what language you have to use and knowing both is a useful skill to have.  Maybe one day if we need to develop some kind of math intensive library, <strong>F#</strong> will be thrown my way :)</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-22641047615259394962010-12-10T10:05:00.001-08:002010-12-10T10:08:43.057-08:00Closing a WPF Window Through Your ViewModel<p>I ran into the issue of properly closing a <strong>Window</strong> (<strong>View</strong>) from my <strong>ViewModel</strong> a while ago.  How does one do this without breaking <strong>MVVM</strong> or adding too much complexity?  Since I’m developing my current project using <strong>Prism</strong> and my <strong>IUnityContainers</strong> are injected into my <strong>ViewModels</strong>, why not just inject <strong>this.Close()</strong> also?</p> <div class="csharpcode"> <pre class="alt"><span class="rem">/**** Window (View) ****/</span></pre>
<pre>...</pre>
<pre class="alt"><span class="kwrd">public</span> Window(IUnityContainer unityContainer)</pre>
<pre>{ </pre>
<pre class="alt"> InitializeComponent(); </pre>
<pre> <span class="kwrd">this</span>.DataContext = <span class="kwrd">new</span> ViewModel(unityContainer, <span class="kwrd">this</span>.Close);</pre>
<pre class="alt">}</pre>
<pre><span class="rem">/**** End Window (View) ****/</span></pre>
<pre class="alt"> </pre>
<pre><span class="rem">/**** ViewModel ****/</span></pre>
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> ViewModel</pre>
<pre>{ </pre>
<pre class="alt"> <span class="kwrd">public</span> ViewModel(IUnityContainer unityContainwer, Action closeAction) </pre>
<pre> { </pre>
<pre class="alt"> ... </pre>
<pre> CloseCommand = <span class="kwrd">new</span> DelegateCommand(closeAction); </pre>
<pre class="alt"> } </pre>
<pre> </pre>
<pre class="alt"> <span class="kwrd">public</span> DelegateCommand CloseCommand </pre>
<pre> { </pre>
<pre class="alt"> get; </pre>
<pre> <span class="kwrd">private</span> set; </pre>
<pre class="alt"> }</pre>
<pre>}</pre>
<pre class="alt"><span class="rem">/**** End ViewModel ****/</span></pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Does this break <strong>MVVM</strong> at all?  Is testability decreased because I injected the <strong>this.Close()</strong> method into my <strong>ViewModel</strong>?  I would argue not since I’ve used the <strong>Action</strong> delegate.  This seems to be the easiest/simplest way to do what I (and many others) want.  Now there may be some purists out there that don’t want any user entered code in the code-behind, but as you might have guessed, I’m no purist.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-78267193132999070902010-12-08T09:57:00.001-08:002010-12-08T09:57:27.989-08:00WPF, MVVM and TextBoxes<p>Overall, I like <strong>WPF</strong> and <strong>MVVM</strong>.  That’s not to say that I think <strong>MVVM</strong> is a perfect design pattern.  I find myself breaking the purity of <strong>MVVM</strong> sometimes because I think there’s a lot of compromise needed to do what I want to without adding complexity.</p> <p>Anyway, one of the biggest gripes about <strong>MVVM</strong> and <strong>TextBoxes</strong> is that the data for bound <strong>TextBoxes</strong> is updated when the <strong>TextBox</strong> control loses focus.  But that makes sense, right?  Well, what if you’ve updated a <strong>TextBox</strong> and hit a <strong>MenuItem</strong> to save your data.  Guess what?  The <strong>TextBox</strong> doesn’t lose focus and your save takes the stale <strong>TextBox</strong> data.  Needless to say this is <strong>VERY</strong> frustrating… </p> <p>One solution would be to move the focus off of the <strong>TextBox</strong> like so:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">((System.Windows.UIElement)System.Windows.Input.Keyboard.FocusedElement).MoveFocus(<span style="color: #0000ff">new</span> System.Windows.Input.TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));</pre>
<br /></div>
<p>You can call that before you actually execute your save command, but even that seems like a bit too much effort to do what should logically be done anyway… I’ve done the above in some of my projects, but there has to be some other way to do what I want…</p>
<p>Instead of using the vanilla <strong>Menu</strong> control, I turned to <strong>Infragistics’</strong> <strong>xamMenu</strong>.  I was hoping that their menu would take into account something like the issue I was having with my <strong>TextBox</strong> data.  I was right… sort of.  It turns out that if I use their <strong>xamMenu</strong> like so:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">ig:xamMenu</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ig:xamMenuItem</span> <span style="color: #ff0000">Header</span><span style="color: #0000ff">="Save"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ig:XamMenuItem.InputBindings</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">MouseBinding</span> <span style="color: #ff0000">MouseAction</span><span style="color: #0000ff">="LeftClick"</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">="{Binding SaveCommand}"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ig:XamMenuItem.InputBindings</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ig:xamMenuItem</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">ig:xamMenu</span><span style="color: #0000ff">></span></pre>
<br /></div>
<p>The above doesn’t do what I want either… After some experimenting, I found that if I use the vanilla <strong>MenuItem</strong> elements instead of <strong>Infragistics’</strong> <strong>XamMenuItem</strong> elements, my <strong>TextBox</strong> data updates and saves.  It seems weird to me that using a combination of the <strong>Infragistics</strong> <strong>xamMenu</strong> and the vanilla <strong>MenuItem</strong> causes the data to update correctly, yet using all <strong>Infragistics’</strong> elements doesn’t.</p>
<p><shrug> In the end I ended up using vanilla <strong>Button</strong> elements in the <strong>xamMenu</strong> because using the vanilla <strong>MenuItem</strong> elements caused spacing issues:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">ig:xamMenu</span><span style="color: #0000ff">></span> <br /> <span style="color: #0000ff"><</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">="{Binding SaveCommand}"</span> <span style="color: #ff0000">Background</span><span style="color: #0000ff">="Transparent"</span> <span style="color: #ff0000">BorderBrush</span><span style="color: #0000ff">="Transparent"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">StackPanel</span> <span style="color: #ff0000">Orientation</span><span style="color: #0000ff">="Horizontal"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Image</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">="None"</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">="{StaticResource Image}"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Background</span><span style="color: #0000ff">="Transparent"</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="4,0,0,0"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Save"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Button</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">ig:xamMenu</span><span style="color: #0000ff">></span></pre>
<br /></div> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-88452689098004929052010-10-20T12:32:00.001-07:002010-10-20T12:41:29.236-07:00VS2010 IDE vs Stand Alone Execution Weirdness (Mouse Wheel)<p>So I’m doing some <strong>ActiveX</strong> <strong>Interop</strong> with my <strong>WPF</strong> application.  As most people know, it’s more of a two step process with WPF since you have to host the <strong>ActiveX</strong> control inside of a <strong>WindowsFormsHost</strong> object before you can introduce it into a <strong>WPF</strong> Control or Window. </p> <p>Anyway, I was testing my component in the IDE and it seemed to be working fine.  Next, I ran the application by itself because it’s faster than through the IDE and I found that my mouse wheel was not working.  What gives? Why would it work properly in the IDE, but not by itself?</p> <p>I got frustrated and posted a question on the <strong>MSDN</strong> forums about it.  Since my <strong>ActiveX</strong> component has license restrictions, I couldn’t provide a proper sample application.  I then got the suggestion to host the <strong>Interop</strong> component in a <strong>Winforms</strong> application as a test.  My <strong>Winforms</strong> sample project works as it should inside and outside of the IDE.</p> <p>I then tried to just start a simple <strong>WPF</strong> application with the <strong>Interop</strong> control and the same behavior occurs as in my main project: Mouse Wheel works in the IDE, but not stand alone.  At this point it seems like it’s a <strong>WPF/ActiveX Interop</strong> issue.</p> <p>Another suggestion I got was to use <strong>Spy++</strong> to see my component was responding to the Mouse Wheel messages.  I opened up <strong>Spy++</strong>, but before I did anything I noticed that my application was now handling the Mouse Wheel messages.  Now here’s what’s confusing me, as soon as I closed <strong>Spy++</strong>, my application stopped handling Mouse Wheel messages again.  Why does the simple fact of having <strong>Spy++</strong> open make my <strong>ActiveX</strong> component work correctly???  I didn’t event start logging the component!</p> <p>According to <strong>Spy++</strong>, my component was indeed handling Mouse Wheel messages as indicated by the log and also because the component was scrolling as it should… I’m waiting for a response to my forum post, hopefully someone can tell me what’s going on.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-59537227605323493872010-10-04T09:06:00.001-07:002010-10-04T09:06:16.788-07:00VB + C# Adventures (Part 5)<h2>I Miss This</h2> <p><strong>VB</strong> definitely makes certain things easier than <strong>C#</strong>.  This may go back to the whole <strong>VB</strong> making me lazy thing, but I miss being able to do this and not having to worry about a null reference exception: </p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">...<br /><br /><span style="color: #0000ff">Dim</span> i <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span> = Len(Trim(SomeString))<br /><br />...</pre>
<br /></div>
<p><em>Note that if the code above were to changed to <strong>SomeString.Trim.Length</strong>, a null reference exception could occur in either language.</em></p>
<p>Conversion methods are available in the <strong>System.Convert </strong>namespace, but in <strong>VB</strong> you can do the old <strong>CBool(SomeObject)</strong>, <strong>CInt(SomeObject)</strong>, etc.  I’m not saying that using the <strong>System.Convert</strong> methods are bad or anything, just that I need to get used to certain things.  </p>
<p> </p>
<h2>Style</h2>
<p>I’ll be blunt, I hate sloppy code.  I try to be consistent in my style and cleanliness regardless of the language I’m programming in.  I think that <strong>C#</strong> definitely has more possibilities as far as clean styles go.  For example:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">...<br /><span style="color: #0000ff">if</span> (someCondition)<br /> DoThis();<br />...<br /><span style="color: #0000ff">if</span> (someCondition){<br /> DoThis();<br />}<br />...<br /><span style="color: #0000ff">if</span> (someCondition)<br />{<br /> DoThis();<br />}<br />...<br /></pre>
<br /></div>
<p>I find all three of the above styles readable.  However, given the syntactic flexibility of <strong>C#</strong>, messiness is just as easy:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">...<br /><span style="color: #0000ff">if</span> (someCondition) DoThis(); <span style="color: #0000ff">if</span>(someOtherCondition) {DoThis();AlsoDoThis();}<br /><span style="color: #0000ff">int</span> i = 0;</pre>
<br /></div>
<p>I’ve always hated code that sat on one line, even way back in college when I was learning <strong>C/C++</strong>.  Sure it can be more succinct, but I find it harder to read.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-47700181057381964512010-09-30T08:43:00.001-07:002010-09-30T08:44:28.505-07:00My Prism Journey (Part 3)<h2>It’s Me, Not You</h2> <p><strong>WPF’s</strong> bare controls are decent, but not always as robust as people need or want.  I initially setup my <strong>Shell</strong> using the basic <strong>Grid</strong> component on a <strong>Window</strong>.  Of course I was and still am in the learning phase, but as my project becomes more “real”, I realize that I should probably start using the components that’ll actually be needed once my project hits our production environment.</p> <p>Since I’ll be using floating panes, I turned to <strong>Infragistics</strong>.  We use their controls in many of our <strong>WinForms</strong> applications so it seemed logical to use them for my <strong>Prism</strong> project.  I figured this would be easy since <strong>Prism</strong> can inject views into any control that hosts an <strong>ItemControl</strong> or <strong>ContentControl</strong>.  </p> <p>There was a bit of a learning curve to get <strong>Infragistics’</strong> Dock Manager to work the way I wanted.  Although I was easily able to place <strong>ConentControls</strong> in the various dock regions, for some reason I couldn’t get the Dock Manager to fill its parent container.  This behavior wasn’t expected because the <strong>WinForms</strong> equivalent did fill in the area as expected.  I also followed the Getting Started sample from scratch in a new project and the control didn’t fill…</p> <p>I did some searching and it looked like others were having the same issue.  The post I found was dated 2009 with no answer so I figured that this issue wasn’t resolved.  I was pretty irate that the expected behavior wasn’t implemented over a year later.  I even went so far as to gripe to the <a href="http://coolthingoftheday.blogspot.com/">boss</a> about it and asked if I could look at other companies’ components.</p> <p>After my grumbling session, I took a step back.  <strong>Infragistics</strong> has been in the controls game a long time (remember <strong>Sheridan</strong> and <strong>VB</strong> pre <strong>.NET</strong>?), they couldn’t have let something like this slip.  I did some more searching and I found that all I needed was a single property: <strong>LayoutMode=”FillContainer”</strong></p> <p>Open hand facing upwards and forcefully place forehead into hand…</p> <p> </p> <h2>Views, ViewModels, And Events</h2> <p>Not all applications have simple UIs.  I have a registered library that handles some of my <strong>Region</strong> management based on certain requirements.  This manager will inject a <strong>View+ViewModel</strong> into a <strong>Region</strong>, nothing complicated here.  In my <strong>ViewModel</strong> I subscribe to certain events, which again is nothing complicated.  </p> <p>I noticed something odd when I retrieved data through my application.  Every time I retrieved data, the time it took to display multiplied.  At first, I thought it was because my <strong>View</strong> wasn’t being properly removed from my <strong>Region</strong>. Nope, the <strong>ActiveView</strong> count is 0 as it should be.  I then placed break points in my data layer and found the culprit.  </p> <p>The expected behavior is that if I request data, a new data layer is instantiated, and my data is returned.  However, every time I requested data, a data layer was instantiated, and the data was returned, but the previously instantiated data layer never got destroyed and was also retrieving data!  </p> <p>This immediately made me look at the fact that I subscribed to a retrieval event, but never unsubscribed from it.  <strong>Prism’s</strong> event system must have still had a reference to the CallBack and was still calling it.  This explained the multiplicative time increase.  I ended up having to make sure that my <strong>Region</strong> manager library unsubscribes from any events when removing <strong>Views</strong> from my <strong>Regions</strong>.  </p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-24137989153062894092010-09-23T11:57:00.001-07:002010-09-23T12:00:32.015-07:00VB + C# Adventures (Part 4)<h4>Event Handlers</h4> <p>Adding and removing event handlers in <strong>VB</strong> is pretty straightforward.  I think the syntax, although wordy, lends itself to readability better than its <strong>C#</strong> counterpart.  In <strong>VB</strong> for example:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">...<br /><span style="color: #0000ff">AddHandler</span> o.SomeEvent, <span style="color: #0000ff">AddressOf</span> Handler<br />...<br /><span style="color: #0000ff">RemoveHandler</span> o.SomeEvent, <span style="color: #0000ff">AddressOf</span> Handler</pre>
<br /></div>
<p>In <strong>C#</strong>, you’d have to do the following:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">...<br />o.SomeEvent += <span style="color: #0000ff">new</span> EventHandler(Handler);<br />...<br />o.SomeEvent -= <span style="color: #0000ff">new</span> EventHandler(Handler);</pre>
<br /></div>
<p>Now the thing that struck me as “funny” was the need to create a new <strong>EventHandler</strong> delegate (or whatever event handler delegate you created) to remove it in the <strong>C#</strong> syntax…</p>
<p> </p>
<h4>Method Parameters Passed By Reference</h4>
<p>Since I’m using methods that pass parameters as reference, you have to use the <strong>ref</strong> identifier before those parameters in <strong>C#</strong>.  At first this bugged me because I was so used to not having to do it in <strong>VB</strong>.  But is it necessarily better not having to identify a reference parameter?  I got to thinking about this and I now think it’s good to have to denote it.  </p>
<p>Why do I think so now?  The intent of a parameter passed by reference is to change the parameter itself (of course this has different implications for value types versus reference types).  This can lead to confusion if you don’t know that the variable that you’re passing in can change.  Requiring the <strong>ref</strong> identifier alleviates this confusion in my opinion.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-57575411855755611412010-09-21T12:06:00.001-07:002010-09-21T12:06:45.664-07:00My Prism Journey (Part 2)<p>Have you registered some types in your <strong>bootstrapper </strong>like I have?  Through Prism’s Dependency Injection, I’ve been passing the <strong>EventAggregator</strong> around to my objects as a parameter.  I’ve also passed in some other registered types, but then I got to thinking…why not just resolve it through the <strong>UnityContainer</strong>?  Instead of injecting all the registered types I need, I can just pass in a single <strong>IUnityContainer</strong> and resolve all of the types I need.  Pretty slick!</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-91059885056555215742010-09-20T15:16:00.001-07:002010-09-20T15:16:47.942-07:00VB + C# Adventures (Part 3)<p>I ran into a little hiccup today, which I found amusing.  Parentheses use is <strong>very</strong> important in <strong>C#</strong>, whereas in <strong>VB</strong> you can be lazy about them (think method calls).  In my <strong>C#</strong> project, I was trying to do an <strong>object.ToString.ToUpper</strong>, but for some reason <strong>Intellisense</strong> couldn’t didn’t find <strong>ToUpper</strong>.  Well, given that <strong>ToString</strong> is a method call, you need to call it as such: <strong>object.ToString().ToUpper()</strong>.  Has <strong>VB</strong> made me a lazy developer? :)</p> <p>Optional parameters… I personally never liked them, but they’re pretty ubiquitous in <strong>VB</strong> land.  It wasn’t until <strong>.NET 4</strong> that <strong>C#</strong> got this language feature.  <strong>VB</strong> will let you have optional value and reference parameters, whereas <strong>C#</strong> won’t let you have optional reference/out parameters.  I’m currently using a data access layer written in <strong>VB</strong> that has a few methods with optional parameters for my <strong>C#</strong> project and I saw this first hand through <strong>Intellisense</strong>.  No brackets were present around the optional reference parameters through <strong>C#</strong>…</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-13898004625848430372010-09-17T13:51:00.001-07:002010-09-17T13:51:57.080-07:00My Prism Journey (Part 1)<p>I’m not going to describe what <a href="http://compositewpf.codeplex.com/"><strong>Prism</strong></a> is because you can just do a search :)  I’m going to post my experiences in trying to leverage the <strong>Prism</strong> libraries to create a modular application.  The tutorials that come with the library are very helpful so people should definitely read the <strong>chm</strong> file for help.  I’m also trying to be as <strong>MVVM</strong> as possible so hopefully I don’t completely mangle my application.</p> <p>One of the components that I’m adding to my application requires <strong>COM Interop… </strong>yay.  I did the obligatory <strong>aximp</strong> call on my <strong>ActiveX</strong> component, but for some reason I got a <strong>file not found</strong> exception whenever I tried to access the component at runtime.  Adding the references created by <strong>aximp</strong> didn’t seem to work.</p> <p>I had to actually create a new <strong>WinForms</strong> control library, add the component to my <strong>toolbox</strong>, drag the component to the control, and then I was able to access the component at runtime.  No worries, I just copied the interop dlls and placed them in a folder so that those can be used instead of the <strong>aximp</strong> generated ones.</p> <p>To include interop <strong>ActiveX</strong> components in your <strong>WPF</strong> application, you need to host the <strong>ActiveX</strong> component in a <strong>WinForms</strong> control.  No problem, add <strong>WindowsFormsIntegration</strong> so you can use the <strong>WindowsFormHost</strong> control in your <strong>WPF</strong> app/control.  You can then add the component to the <strong>WindowsFormHost.Child</strong> and it will display.  Pretty straight forward…</p> <p>After getting the above sorted out, I got my interop control to display in the specified <strong>region </strong>in my <strong>shell</strong>.  However, it was displaying incorrectly… I set the <strong>ActiveX.Dock = Fill</strong>, but it wasn’t filling the <strong>region</strong>.  I sat there for a good hour or so trying to figure this one out… No matter what I did, it just wouldn’t fill the damn <strong>region</strong>.  </p> <p>I then decided to create a little test program to see where the issue could possibly be.  I added a <strong>WindowsFormHost</strong> and a reference to the <strong>ActiveX</strong> component.  It filled fine!  Ok, maybe it’s because the <strong>region</strong> in my application is wrapped with a <strong>T</strong><strong>abcontrol</strong>.  I wrapped the <strong>WindowsFormHost</strong> with the <strong>TabControl</strong> and it still filled correctly.  Wait, to add a <strong>region</strong> to your <strong>shell</strong>, you need to specify what the region is hosted in, which is either an <strong>ItemsControl</strong> or <strong>ContentControl</strong>.  </p> <p>It turns out that I used <strong>ItemsControls</strong> to host my <strong>regions</strong> (because the tutorial used those as well).  I then tried switching my <strong>region</strong> hosts to <strong>ContentControls</strong> and now my <strong>ActiveX</strong> component fills as it should… Sheesh.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com2tag:blogger.com,1999:blog-7049316631692964922.post-50809584640717993282010-09-16T13:41:00.001-07:002010-09-16T13:47:56.857-07:00VB + C# Adventures (Part 2)<p>We’re using <strong>Visual Studio 2010</strong> so all of my gripes, comparisons, etc will be based on that.  </p> <p>The biggest thing I noticed right off the bat is in the IDE.  <strong>C#</strong> <strong>Intellisense</strong> is kind of clunky compared to its <strong>VB</strong> counterpart.  I found this kind of weird…</p> <p><strong></strong></p> <p><strong>C# Syntax</strong></p> <p>I’m finding myself using parentheses where I should be using brackets, but it’s rare.  </p> <p>I miss the <strong>With</strong> construct that’s in <strong>VB</strong>.</p> <p>I sometimes declare my variable name before the type.</p> <p>Semi-colons…don’t forget those!</p> <p>Curly-braces galore!</p> <p>I find the syntax to be a bit more cryptic.</p> <p> </p> <p><strong>VB Syntax</strong></p> <p>More verbose, but I find it easier to read (this is just personal preference I guess).</p> <p>Gotta love direct access to <strong>My.Settings</strong> and <strong>My.Resources</strong>.</p> <p>No need to <strong>break</strong> after every case in <strong>Select</strong> (<strong>Switch</strong>) statements.</p> <p>Delegate parameters need an <strong>AddressOf</strong> identifier when passing into a method, whereas <strong>C#</strong> you just pass in the method.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-80770155118477737752010-09-16T13:15:00.001-07:002010-09-16T13:23:24.322-07:00VB + C# Adventures (Part 1)<p>I’ll be starting a new series documenting my experiences with using <strong>VB</strong> and <strong>C#</strong> simultaneously.  This isn’t meant to be a <a href="http://www.harding.edu/fmccown/vbnet_csharp_comparison.html">comparison</a> between the languages, but rather just a non-technical (as can be anyway) dump of the things that are going through my head as I use both languages.  I’m sure this has been done before, but this ought to be fun anyway.</p> <p>Some personal background…</p> <p>Back when I was in college, I learned <strong>C++</strong> as my first language.  Of course there was some minor <strong>SPARC</strong> assembly (like I really remember any of that…) and later <strong>Java</strong> as required by whichever classes I was taking.  I had extremely light exposure to <strong>VB6</strong> in my senior year in one of my design classes.  We did <strong>UML </strong>diagrams and we tied it into a <strong>VB</strong> skeleton with absolutely no requirement to write any code.  I literally wrote zero lines of <strong>VB</strong> code in that class.</p> <p>My first professional job was at a mortgage company and the environment was <strong>VB6</strong>.  It didn’t take long for me to get adjusted, but I found <strong>VB6 </strong>a little odd as it went against most of the guiding principles I learned in college as to how to write a program.  Anyway, I’m not going to jump onto the “bash <strong>VB</strong>” train because that train is full…</p> <p>Since <strong>VB6</strong> was on my resume, my proceeding jobs were also related to me using <strong>VB6</strong>.  I didn’t mind it, but at the same time I wasn’t really learning anything new… I guess you can say that I started getting bored.  </p> <p>Fast forward to my current job.  When I first started here, I had zero professional experience with <strong>.NET</strong>.  I’ve always wanted to get into it, but opportunities seemed slim for me given that I had no professional experience in <strong>.NET </strong>(catch 22…, but it’s worse for game developers).  I did do some studying on my own in <strong>C#</strong>, but I wasn’t about to lie and say that I had real-world <strong>.NET</strong> experience.  I was very fortunate to come across a job listing for my current position and also for the fact that <a href="http://coolthingoftheday.blogspot.com/">Greg</a> gave me a shot.</p> <p>Jumping from <strong>VB6</strong> to <strong>VB.NET</strong> wasn’t difficult.  I guess it was because I had retained some of the objected-oriented knowledge from college and the syntax between the two wasn’t too different.  I was (and still am) excited to learn something new for a change.  So far, doing things in <strong>C#</strong> isn’t too difficult for me.  I had some prior experience with <strong>C</strong>-style syntax already and I know the<strong> .NET</strong> framework from doing things in<strong> VB.NET</strong> already.</p> <p>I feel that a good carpenter can build a great house with any brand of tools you give them.  The same holds true in the case of a good<strong> .NET</strong> developer (or any developer for that matter).  A good or bad developer will be a good or bad developer regardless of what language they are using.  This is why I really don’t understand the <strong>C#</strong> snobbery I see a lot of.  Both languages have their pros and cons, but in the end it’s the result that matters.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-34517530346756558182010-08-17T08:14:00.001-07:002010-08-17T08:14:49.603-07:00Visual Studio 2010, When “Save All” Doesn’t Mean “Save All”<p>I found a minor bug related to the <strong>Save All </strong>functionality while updating our build definitions.  A new project was added to our TFS and this needed to be cloaked for all of our existing build definitions.  No problem, just add the path, set it to <strong>cloaked</strong>, and copy the line so you can easily paste it in your next build definition without having to pick the path.  </p> <p>I did this for five of our definitions and I decided to go back to the first one for some reason to double check.  Why didn’t the path get saved?  I hit <strong>Save All</strong> and didn’t get a prompt when I closed the build definitions, so what gives?  Okay, maybe it was a glitch or something so I did it again, this time I tried using the regular <strong>Save </strong>instead of <strong>Save All</strong>.  This time my build definitions were updated.  </p> <p>It seems like there’s a bug with <strong>Save All </strong>and updating build definitions.  I submitted the issue to Microsoft, but they want a video… I’m always wary about submitting anything work related to the public domain so I had to decline.  Hopefully the issue gets resolved, but in the meantime if anybody else is having the same issue, just hit <strong>Save</strong> instead.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-30020430186294547432010-08-09T13:26:00.001-07:002010-08-09T13:27:53.600-07:00The Reappearing Breakpoint (VS2010)<p>Today I somehow made VS2010 crash in the middle of debugging.  After I reopened my project, I noticed that a breakpoint that I had deleted previously kept on showing up.  Needless to say this was quite confusing since I removed it.  No problem, I’ll just remove it again…</p> <p>Whenever I ran my application in debug mode, the breakpoint would magically reappear! I thought maybe it was a glitch, so I just closed and reopened my project.  F5 and why is it reappearing when I just deleted it?  Okay, I’ll just shut down VS and reopen it… F5, OMG why won’t you go away?!  </p> <p>Debug->Delete All Breakpoints fixed it… life’s a glitch.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-36724487465463593192010-06-09T13:22:00.001-07:002010-06-23T09:04:17.609-07:00VS2008 to VS2010 Upgrade Notes<p><strong>UPDATE 6/23/2010:</strong></p> <p>The issue with one of our setup project builds has been successfully resolved with a workaround that I thought didn’t work at first.  It turns out our Microsoft contact couldn’t reproduce the issue.  It was the end of the day so I decided to shelve this issue until this morning.  I tried running the setup project from my XP machine with the workaround and it worked.  More importantly, I ran it on our build machine and it worked!  The thing that threw me off was that it failed on my Windows 7 development machine, which is where I initially tested the issue.  I suspect it might have to do with the fact that the interop assemblies were actually built on my old XP development environment and that something isn’t jiving now when I use the same assemblies to build on my Windows 7 machine.  In any case, copying the interop dlls to the same path as the <strong>vdproj</strong> file works like a charm.</p> <p> </p> <p> </p> <p>Using the latest and greatest development environment is always fun.  However, upgrading from a previous version isn’t always easy.  When we converted our dev environment from VS2005 to VS2008, there were a number of headaches to get everything working properly.  So far, upgrading to VS2010 from VS2008 is proving no different.  Since we’re still on TFS2008, we used <a href="http://blogs.msdn.com/b/willbar/archive/2009/11/01/building-net-4-0-applications-using-team-build-2008.aspx">this</a> workaround to build VS2010 solutions on our Build machines.  </p> <p>So after our build machines had VS2010 installed and the above <strong>MSBuildPath</strong> workaround was applied, I ran my first build.  It was a ClickOnce build and it actually ran without any issues.  The application compiled and everything got copied over to our drop location…Cool!  So then I tried running our MSI build for the same project.  I was expecting it to build fine since the ClickOnce build is a little bit more complex, but the MSI build failed.  After thoroughly checking all settings in the Setup project, I couldn’t figure out why it was failing.  The only reason in the BuildLog.txt was <strong>EXEC : error : Unable to update the dependencies of the project.  </strong>Could the message be a bit more vague, please?</p> <p>After searching the web, it seemed others were having the same <a href="https://connect.microsoft.com/VisualStudio/feedback/details/552799">problem</a>.  The workarounds suggested on that page didn’t work for us.  So instead of waiting around, we decided to open up a support ticket, which our contact at Microsoft is currently looking into.  I had a feeling that Interop assemblies in our project might be causing the problem, but it wasn’t until today that my suspicion was gaining ground.  We have a few projects that have MSI builds, so I went ahead and converted and built those out.  What do you know?  The MSI builds that don’t have Interop assemblies build fine on our build machine.  We’re still waiting for a real solution to this problem, until then, we’re building the MSI package locally for that one project.</p> <p>Another one of our builds has unit tests.  I ran this project’s build without the unit tests first and it completed.  I then ran the build with the unit tests and 99.9% of the unit tests failed, but not all of them, which was weird to me.  These unit tests passed completely when we were using VS2008, so maybe the MSTest reference needed to be updated or something.  I searched MSDN and found this <a href="http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/92716892-87d0-430c-b421-e2c80bb3e038">post</a> about the same exact issue we were having.  I tried the solutions suggested, but they didn’t work.  There were some other odd issues with the build with the unit tests, so I just decided to delete the workspace associated with that build.  After I did this, the unit tests passed and everything looked good.</p> <p>I hope when we upgrade our TFS2008 to TFS2010, that there aren’t going to be more issues.  I have my fingers crossed…</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com1tag:blogger.com,1999:blog-7049316631692964922.post-20097290876116443072010-04-05T09:08:00.001-07:002010-04-05T09:08:37.703-07:00Running an Interactive Application Through a Windows Service<p>Have a need to run an interactive application through a Windows Service?  I do and I did a LOT of searching on the Internet and the answer I found was that it can’t be done anymore ever since Windows Vista was released.</p> <p>A lot of people on MSDN asked this question, but couldn’t seem to get it to work either.  I just assumed that it couldn’t be done since nobody else couldn’t get it to work either.  </p> <p>Luckily, I asked this question myself on one of the MSDN forums and a MSFT moderator was able to point me to this blog: <a href="http://asprosys.blogspot.com/2009/03/allow-service-to-interact-with-desktop.html" target="_blank">http://asprosys.blogspot.com/2009/03/allow-service-to-interact-with-desktop.html</a></p> <p>Thankfully, Stephen Martin was able to get the problem solved and even has some sample code to show you that it does work as it should.  It’s in <strong>C#</strong>, but you can always translate it to <strong>VB</strong> if you need to.  I personally used a converter found here: <a href="http://dotnetspider.com/codeconvert/Default.aspx" target="_blank">http://dotnetspider.com/codeconvert/Default.aspx</a>.  The converter isn’t perfect, but it only had a few things that needed to be fixed.</p> <p>One issue I had though was with running a <strong>.cmd</strong> file (I imagine the same issue would happen for <strong>.com/.bat</strong> files also).  For some reason, running the <strong>CreateProcessAsUser</strong> would show the command window then disappear.  My <strong>.cmd</strong> file was a long file name with spaces so I thought maybe that had something to do with it.  I included double quotes around my command string like this:  <strong>cmd.exe /c “C:\This Is a Long Path\command.cmd”  </strong>The <strong>.cmd</strong> file would not run.  </p> <p>Scratching my head, I put the above string in the <strong>Windows Run</strong> and tried to run it.  It wouldn’t run here either… I then tried putting the <strong>.cmd</strong> file in the root of my <strong>C:\</strong> and tried running it like this: <strong>cmd.exe /c “C:\command.cmd”</strong>  This ran fine.  I figured that since both <strong>CreateProcessAsUser</strong> and <strong>Windows Run</strong> were having the same issue, it was a good thing.  </p> <p>After much playing around with the string and a lot of frustration, I tried the following: <strong>cmd.exe /c “”C:\This Is a Long Path\command.cmd”</strong>  This worked… I’m not too sure why the double quotes are needed twice before the long file name though…  This also works with the <strong>.cmd</strong> file that was in the root of my <strong>C:\ </strong>like this: <strong>cmd.exe /c “”C:\command.cmd”</strong></p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-25490607736049027902010-03-11T11:19:00.001-08:002010-03-11T13:03:00.606-08:00WinForms/WPF Interop ElementHost Not Drawing The WPF Control!<p><strong><Edit></strong></p> <p>It turns out it wasn’t externalizing the WPF control that solved the issue, but rather changing my build configuration to Release instead of Debug.  When I added the externalized assembly, I set the configuration to Release.  I’m not sure exactly why a debug build would cause this behavior…</p> <p><strong></Edit></strong></p> <p><strong><Edit 2></strong></p> <p>It seems to work properly on Windows XP regardless of the build configuration.  Might be a Windows 7 thing…</p> <p><strong></Edit 2></strong></p> <p>I’ve been doing a lot of <strong>WPF</strong> work lately and a lot of it has been with <strong>WinForms</strong> interoperating with <strong>WPF</strong>.  Today I noticed some odd behavior when I tried to add a <strong>WPF</strong> control to a <strong>WinForms</strong> <strong>ElementHost</strong> object…</p> <p>Usually I put the <strong>WPF</strong> control in a separate assembly, but today I thought I didn’t need to since it was just a very simple control.  Immediately I saw that the <strong>WPF</strong> control wouldn’t draw itself properly for some reason.  It would only draw itself sometimes, but if i clicked on the <strong>WPF</strong> control and somehow hit a <strong>Button</strong> or <strong>ComboBox</strong>, the control would show up.</p> <p>I then decided to try and put the simple control in its own assembly and that solved the problem… It looks like there’s some issues with including a <strong>WPF</strong> control in a <strong>WinForms</strong> project directly, in my case anyway.  I’m using Visual Studio 2008 on Win7 x86 and if anybody else has this type of issue, try doing what I did to resolve the issue.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-6102615638659973712009-12-09T15:24:00.001-08:002009-12-09T15:24:25.103-08:00Visual Studio IDE Tab Spacing<p>Don’t you hate it when you get some source code and the tab spacing is different than yours?  I know I do.  You could go line by line and press backspace, which is not the smartest way to do it (I was guilty of this). </p> <p>Here’s the much simpler way to get the tabs aligned:</p> <p><a href="http://lh5.ggpht.com/_jBiTiK8T3Jc/SyAxpaof1-I/AAAAAAAAAMY/LmhO_fMuzL4/s1600-h/tabspacing%5B3%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="tabspacing" border="0" alt="tabspacing" src="http://lh6.ggpht.com/_jBiTiK8T3Jc/SyAxqCRlfUI/AAAAAAAAAMk/ju4BEZwNVGg/tabspacing_thumb%5B1%5D.png?imgmax=800" width="452" height="183" /></a></p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-86250542334385678882009-11-18T09:48:00.001-08:002009-11-18T09:48:55.597-08:00TFS folders and the evil “&”<p>So I tried to make a folder within TFS called “<strong>R&D</strong>”<strong> </strong>and it let me.  No surprises…yet.  After moving a project into this folder, I ran the project to make sure all paths/references were still intact.  The project ran fine so things seemed okay.  </p> <p>It wasn’t until I tried opening a form up in Designer view that I got a weird error:</p> <p><a href="http://lh5.ggpht.com/_jBiTiK8T3Jc/SwQzhnDGLZI/AAAAAAAAALQ/aHg_I8JB7NQ/s1600-h/DesignerError%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DesignerError" border="0" alt="DesignerError" src="http://lh6.ggpht.com/_jBiTiK8T3Jc/SwQzh2O6UBI/AAAAAAAAALU/iXzIyLpj8WE/DesignerError_thumb.png?imgmax=800" width="244" height="167" /></a> </p> <p>How is it that the project can build and run fine, but I’m seeing this?  XML?  I don’t have anything related to XML in the form code, so what gives?  After doing some searching on the internet, it seems that the “<strong>&</strong>” character anywhere in the path causes this issue.  Since my project was in the “<strong>R&D”</strong> folder, I was having this issue.  I renamed the folder and the problem went away…</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-75422035658124592782009-10-29T10:27:00.001-07:002009-10-29T10:31:06.093-07:00WPF Data Binding – ComboBox Items List<p>As I learn WPF I’m running into quite a few roadblocks, but I’m enjoying the fact that it’s a challenge and something new.  One of the things I’m trying to get used to is Data Binding to the WPF UI.  I’m also trying to learn WPF the MVVM way.  There are a lot of examples on how to do this on the web so I’ll just get to what got me stuck for a bit on ComboBox items binding.  Here’s some of my UI XAML and my code behind:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">DockPanel</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="42"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="TopDockPanel"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="auto"</span> <span style="color: #ff0000">DockPanel</span>.<span style="color: #ff0000">Dock</span><span style="color: #0000ff">="Top"</span> <span style="color: #ff0000">LastChildFill</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="auto"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Grid1"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="266"</span> <span style="color: #ff0000">DockPanel</span>.<span style="color: #ff0000">Dock</span><span style="color: #0000ff">="Left"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Label</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="7,7,0,9"</span> <span style="color: #ff0000">HorizontalAlignment</span><span style="color: #0000ff">="Left"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="71"</span><span style="color: #0000ff">></span>Combo1:<span style="color: #0000ff"></</span><span style="color: #800000">Label</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ComboBox</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">="{Binding ComboList1}"</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="84,9,22,13"</span> <span style="color: #ff0000">SelectionChanged</span><span style="color: #0000ff">="Combo1_SelectionChanged"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Grid</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="auto"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Grid2"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="281"</span><span style="color: #0000ff">></span><br /><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Label</span> <span style="color: #ff0000">HorizontalAlignment</span><span style="color: #0000ff">="Left"</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="6,7,0,9"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="89"</span><span style="color: #0000ff">></span>Combo2:<span style="color: #0000ff"></</span><span style="color: #800000">Label</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ComboBox</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">="{Binding ComboList2}"</span> <span style="color: #ff0000">Margin</span><span style="color: #0000ff">="101,9,20,13"</span> <span style="color: #ff0000">IsEditable</span><span style="color: #0000ff">="False"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Grid</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="auto"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Grid3"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="auto"</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">DockPanel</span><span style="color: #0000ff">></span></pre>
<br /></div>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff">Class</span> SomeClass<br /> <span style="color: #0000ff">Private</span> _SomeClassVM <span style="color: #0000ff">As</span> SomeClassViewModel = <span style="color: #0000ff">Nothing</span><br /><br /> <span style="color: #0000ff">Sub</span> <span style="color: #0000ff">New</span>()<br /><br /> <span style="color: #008000">' This call is required by the Windows Form Designer.</span><br /> InitializeComponent()<br /> <span style="color: #008000">' Add any initialization after the InitializeComponent() call.</span><br /> _SomeClassVM = <span style="color: #0000ff">New</span> SomeClassViewModel<br /> <span style="color: #0000ff">Me</span>.DataContext = _SomeClassVM<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span></p><p> <span style="color: #0000ff">Private</span> <span style="color: #0000ff">Sub</span> Combo1_SelectionChanged(<span style="color: #0000ff">ByVal</span> sender <span style="color: #0000ff">As</span> System.<span style="color: #0000ff">Object</span>, <span style="color: #0000ff">ByVal</span> e <span style="color: #0000ff">As</span> System.Windows.Controls.SelectionChangedEventArgs)<br /> _SomeClassVM.Combo1Changed(sender)<br /><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><span style="color: #0000ff">End</span> <span style="color: #0000ff">Class</span><br /></p></pre>
<br /></div>
<p>Nothing complicated, a simple MVVMish implementation (ish because there’s event handler code in the code behind file, I’ll be refactoring this as I go on).  My View Model implements the <strong>INotifyPropertyChanged</strong> Interface so that the UI can be notified of any property changes and update any data bindings as needed.  My View Model also exposes a couple of Public Properties: <strong>ComboList1</strong> and <strong>ComboList2</strong> which are <strong>List (Of String)</strong> objects:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 100.8%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 210px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; height: 455px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> SomeClassViewModel<br /> <span style="color: #0000ff">Implements</span> INotifyPropertyChanged<br /><br /> <span style="color: #0000ff">Private</span> _ComboList1 <span style="color: #0000ff">As</span> List(Of <span style="color: #0000ff">String</span>) <br /> <span style="color: #0000ff">Private</span> _ComboList2 <span style="color: #0000ff">As</span> List(Of <span style="color: #0000ff">String</span>) </p><p> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">ReadOnly</span> <span style="color: #0000ff">Property</span> ComboList1() <span style="color: #0000ff">As</span> List(Of <span style="color: #0000ff">String</span>) <br /> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">Return</span> _ComboList1<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Property</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">ReadOnly</span> <span style="color: #0000ff">Property</span> ComboList2() <span style="color: #0000ff">As</span> List(Of <span style="color: #0000ff">String</span>) <br /> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">Return</span> _ComboList2<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Property</span><br /><br /> <span style="color: #0000ff">Sub</span> <span style="color: #0000ff">New</span>()<br /> _ComboList1 = <span style="color: #0000ff">New</span> List(Of <span style="color: #0000ff">String</span>) <br /><br /> <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> item <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0000ff">In</span> ItemsList <span style="color: #008000">'this is just a list of strings from anywhere</span><br /> _ComboList1.Add(item)<br /> <span style="color: #0000ff">Next</span><br /><br /> OnPropertyChanged(<span style="color: #006080">"SQLServerList"</span>)<br /><br /> _ComboList2 = <span style="color: #0000ff">New</span> List(Of <span style="color: #0000ff">String</span>)<br /><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Sub</span> Combo1Changed(<span style="color: #0000ff">ByVal</span> sender <span style="color: #0000ff">As</span> System.<span style="color: #0000ff">Object</span>)<br /> _ComboList2.Clear()<br /><br /> <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> item <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0000ff">In</span> SomeOtherList <span style="color: #008000">'this is just list of string from another place</span><br /> _ComboList2.Add(sqlDatabase)<br /> <span style="color: #0000ff">Next</span><br /><br /> OnPropertyChanged(<span style="color: #006080">"ComboList2"</span>)<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Event</span> PropertyChanged(<span style="color: #0000ff">ByVal</span> sender <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span>, <span style="color: #0000ff">ByVal</span> e <span style="color: #0000ff">As</span> System.ComponentModel.PropertyChangedEventArgs) <span style="color: #0000ff">Implements</span> System.ComponentModel.INotifyPropertyChanged.PropertyChanged<br /><br /> <span style="color: #0000ff">Private</span> <span style="color: #0000ff">Sub</span> OnPropertyChanged(<span style="color: #0000ff">ByVal</span> propertyName <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>)<br /> <span style="color: #0000ff">RaiseEvent</span> PropertyChanged(<span style="color: #0000ff">Me</span>, <span style="color: #0000ff">New</span> PropertyChangedEventArgs(propertyName))<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><span style="color: #0000ff">End</span> Class</p></pre>
<br /></div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, I thought that clearing and adding items to my <strong>ComboList2</strong> object would suffice in propagating change notifications up to the UI…WRONG.  It seems there’s more to it than just clearing/adding to the list and raising the <strong>PropertyChanged</strong> event.  This implementation only notified the UI that <strong>ComboList2</strong> changed once at the first time I changed <strong>ComboBox1</strong>’s selected item instead of each time.  What gives?</p>
<p>After some fiddling I found that I couldn’t use the current <strong>_ComboList2</strong> object reference.  I had to actually set the<strong> _ComboList2</strong> object to a new List for the UI to update:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Sub</span> Combo1Changed(<span style="color: #0000ff">ByVal</span> sender <span style="color: #0000ff">As</span> System.<span style="color: #0000ff">Object</span>)<br /> <span style="color: #0000ff">Dim</span> NewList <span style="color: #0000ff">As</span> <span style="color: #0000ff">New</span> List(Of <span style="color: #0000ff">String</span>)<br /><br /> <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> item <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0000ff">In</span> SomeOtherList <span style="color: #008000">'this is just list of string from another place</span><br /> NewList.Add(item)<br /> <span style="color: #0000ff">Next</span><br /><br /> _ComboList2 = NewList<br /> OnPropertyChanged(<span style="color: #006080">"ComboList2"</span>)<br /> <span style="color: #0000ff">End</span> Sub</pre>
<br /></div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>There’s a more elegant way to solve the issue I had, which is to use an <strong>ObservableCollection</strong> instead of <strong>List (Of String)</strong> objects:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> SomeClassModel<br /><br /> <span style="color: #0000ff">Private</span> _ComboList1 <span style="color: #0000ff">As</span> ObservableCollection(Of <span style="color: #0000ff">String</span>) = <span style="color: #0000ff">Nothing</span><br /> <span style="color: #0000ff">Private</span> _ComboList2 <span style="color: #0000ff">As</span> ObservableCollection(Of <span style="color: #0000ff">String</span>) = <span style="color: #0000ff">Nothing</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">ReadOnly</span> <span style="color: #0000ff">Property</span> ComboList1() <span style="color: #0000ff">As</span> ObservableCollection(Of <span style="color: #0000ff">String</span>)<br /> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">Return</span> _ComboList1<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Property</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">ReadOnly</span> <span style="color: #0000ff">Property</span> ComboList2() <span style="color: #0000ff">As</span> ObservableCollection(Of <span style="color: #0000ff">String</span>)<br /> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">Return</span> _ComboList2<br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Get</span><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Property</span><br /><br /> <span style="color: #0000ff">Sub</span> <span style="color: #0000ff">New</span>()<br /> _ComboList1 = <span style="color: #0000ff">New</span> ObservableCollection(Of <span style="color: #0000ff">String</span>)<br /><br /> <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> item <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0000ff">In</span> ItemsList <span style="color: #008000">'this is just a list of strings from anywhere</span><br /> _ComboList1.Add(item)<br /> <span style="color: #0000ff">Next</span><br /><br /> _ComboList2 = <span style="color: #0000ff">New</span> ObservableCollection(Of <span style="color: #0000ff">String</span>)<br /><br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><br /> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Sub</span> Combo1Changed(<span style="color: #0000ff">ByVal</span> sender <span style="color: #0000ff">As</span> System.<span style="color: #0000ff">Object</span>)<br /> _ComboList2.Clear<br /><br /> <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> item <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0000ff">In</span> SomeOtherList <span style="color: #008000">'this is just list of string from another place</span><br /> _ComboList2.Add(item)<br /> <span style="color: #0000ff">Next</span><br /> <br /> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /><span style="color: #0000ff">End</span> Class</pre>
<br /></div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>You’ll notice a couple of things.  The first being that the View Model no longer needs <strong>INotifyPropertyChanged</strong>.  This is because <strong>ObservableCollection</strong> implements <strong>INotifyPropertyChanged</strong> (and <strong>INotifyCollectionChanged</strong>).  You’ll also notice that I was able to just clear/add to <strong>_ComboList2</strong> without having to raise any events.  The UI updated as expected and I suspect it’s because when clearing or adding items to the <strong>ObservableCollection</strong>, properties such as <strong>count</strong> raise the <strong>PropertyChanged</strong> event properly.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com1tag:blogger.com,1999:blog-7049316631692964922.post-69089774994967003842009-10-13T15:09:00.001-07:002009-10-13T15:09:19.780-07:00Error in last post. Think of it as a what not to do :)<h5>It turns out that pointing to a file with an Interface inside of it doesn’t work as intended (oops! :/).  Although you can implement the Interface, problems arise when you try to cast it since they’re interfaces in different namespaces…  It looks like you will have to point all libraries that need the interface to a single project that has the Interface you need.</h5> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-56187775676479538942009-10-13T15:05:00.000-07:002009-10-13T15:08:15.241-07:00Sharing an Interface (What not to do)<p>Have you ever had a class library that uses an Interface?  How about two or more libraries that need to use the same Interface?  For instance, <strong>ClassLibrary1 </strong>and <strong>ClassLibrary2</strong> need to implement <strong>ISomeInterface</strong> below:</p> <p><a href="http://lh3.ggpht.com/_jBiTiK8T3Jc/StTntBwSfmI/AAAAAAAAAKQ/5QpWoShhdIM/s1600-h/Interface1%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Interface1" border="0" alt="Interface1" src="http://lh4.ggpht.com/_jBiTiK8T3Jc/StTntTGWDZI/AAAAAAAAAKU/zpYK8BUOl54/Interface1_thumb%5B1%5D.png?imgmax=800" width="233" height="112" /></a> </p> <p>Instead of copying <strong>ISomeInterface.vb </strong>to both <strong>ClassLibrary</strong> projects or adding a project reference, you can add a link to <strong>ISomeInterface.vb</strong> and have access to <strong>ISomeInterface</strong>:</p> <p><a href="http://lh6.ggpht.com/_jBiTiK8T3Jc/StTnt6qOkLI/AAAAAAAAAKY/N09QLp_7SqE/s1600-h/Interface2%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Interface2" border="0" alt="Interface2" src="http://lh6.ggpht.com/_jBiTiK8T3Jc/StTnuCyFsfI/AAAAAAAAAKc/6lTSK5jDnRU/Interface2_thumb.png?imgmax=800" width="244" height="190" /></a> </p> <p><a href="http://lh4.ggpht.com/_jBiTiK8T3Jc/StTnufmqLQI/AAAAAAAAAKg/FFMmg9H_6S8/s1600-h/Interface3%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Interface3" border="0" alt="Interface3" src="http://lh4.ggpht.com/_jBiTiK8T3Jc/StTnunFBypI/AAAAAAAAAKk/t4-Pb4wZ5LE/Interface3_thumb.png?imgmax=800" width="244" height="179" /></a> </p> <p>Now you’ll notice that <strong>ISomeInterface.vb </strong>is part of <strong>ClassLibrary1</strong> as a linked file:</p> <p><a href="http://lh4.ggpht.com/_jBiTiK8T3Jc/StTnuygUaCI/AAAAAAAAAKo/Im5yv6jrAXQ/s1600-h/Interface3%5B5%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Interface3" border="0" alt="Interface3" src="http://lh5.ggpht.com/_jBiTiK8T3Jc/StTnvCzATCI/AAAAAAAAAKs/nSZX0v3JG4k/Interface3_thumb%5B1%5D.png?imgmax=800" width="244" height="124" /></a> </p> <p></p> <p>Now we can implement <strong>ISomeInterface </strong>in <strong>ClassLibrary1:</strong></p> <p><strong><a href="http://lh6.ggpht.com/_jBiTiK8T3Jc/StTnve8kxGI/AAAAAAAAAKw/B0tGVC9YEX8/s1600-h/Interface4%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Interface4" border="0" alt="Interface4" src="http://lh4.ggpht.com/_jBiTiK8T3Jc/StTnvmFp_KI/AAAAAAAAAK0/viGohwxKigQ/Interface4_thumb.png?imgmax=800" width="244" height="94" /></a> </strong></p> <p></p> <p>The benefit of adding the Interface file as a link is that you can maintain the Interface in one location.  You don’t have to worry about having to copy new versions if you decide to change your contract.</p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-41775237921213319602009-08-10T10:12:00.001-07:002009-08-10T10:12:11.821-07:00The Best Things In Life Are Free<p>This post by <a href="http://coolthingoftheday.blogspot.com/2009/08/is-there-free-alternate-to-application.html" target="_blank">Greg</a> inspired me to post to my blog about some of the free software utilities and applications that I use at home.  Although some of the things I list may not be the absolute best, it really is hard to beat free.  Plus a lot of times the term “best” is used subjectively and this includes software.</p> <p><a href="http://www.7-zip.org/" target="_blank">7-Zip</a> is a compression utility used for packing and unpacking various file formats.  Think of it as an open source <a href="http://www.winzip.com" target="_blank">WinZip</a>.  Below is the main feature list from the <a href="http://www.7-zip.org/" target="_blank">7-Zip</a> website:</p> <ul> <li>High compression ratio in new <a href="http://www.7-zip.org/7z.html">7z format</a> with <b>LZMA</b> compression </li> <li>Supported formats: <ul> <li>Packing / unpacking: 7z, ZIP, GZIP, BZIP2 and TAR </li> <li>Unpacking only: ARJ, CAB, CHM, CPIO, DEB, DMG, HFS, ISO, LZH, LZMA, MSI, NSIS, RAR, RPM, UDF, WIM, XAR and Z. </li> </ul> </li> <li>For ZIP and GZIP formats, <b>7-Zip</b> provides a compression ratio that is 2-10 % better than the ratio provided by PKZip and WinZip </li> <li>Strong AES-256 encryption in 7z and ZIP formats </li> <li>Self-extracting capability for 7z format </li> <li>Integration with Windows Shell </li> <li>Powerful File Manager </li> <li>Powerful command line version </li> <li>Plugin for FAR Manager </li> <li>Localizations for 74 languages </li> </ul> <p>---------</p> <p>Every Windows user needs and anti-virus application.  The one I use is <a href="http://www.avast.com" target="_blank">Avast</a> because it seems to be the least intrusive.  I haven’t had a single problem since I began using <a href="http://www.avast.com" target="_blank">Avast</a> over a year ago.  Here are some of the features:</p> <ul> <li>Anti-spyware built-in </li> <li>Web Shield </li> <li>Anti-rootkit built-in </li> <li>Automatic updates </li> <li>Strong self-protection </li> <li>Virus Chest </li> <li>Antivirus kernel </li> <li>System integration </li> <li>Simple User Interface </li> <li>Integrated Virus Cleaner </li> <li>Resident protection </li> <li>Support for 64-bit Windows </li> <li>P2P and IM Shields </li> <li>Internationalization </li> <li>Network Shield </li> </ul> <p>---------</p> <p>Ever have issues with your OS or feel that your registry has become a bit dirty?  <a href="http://www.ccleaner.com/" target="_blank">CCleaner</a> may help you find the issues.  I use it regularly to clean out unnecessary temporary and log files.  I also use it to check for any registry issues:</p> <p>“CCleaner is a freeware PC optimization tool.  It combines a system cleaner that removes unused and temporary files from your system and also a fully featured registry cleaner!  CCleaner allows Windows to run faster, more efficiently and gives you more hard disk space.  The best part is that it's Small, Fast and Free!”</p> <p>---------</p> <p><a href="http://cdburnerxp.se/" target="_blank">CDBurnerXP</a> is one of the best disc burning applications I’ve ever used, free or otherwise.  It handles everything I throw at it without any issues:</p> <ul> <li>burn all kinds of discs </li> <li>audio-CDs with or without gaps between tracks </li> <li>burn and create ISO files </li> <li>data verification after burning process </li> <li>create bootable discs </li> <li>multi-language interface </li> <li>bin/nrg → ISO converter, simple cover printing and much more! </li> <li>Operating Systems: Windows 2000/XP/2003 Server/Vista/Windows 7 </li> </ul> <p>--------- </p> <p>Hate scratched audio CDs?  I know I do.  I use <a href="http://cdexos.sourceforge.net/" target="_blank">CDex</a> to rip from the original disc so that I don’t have to worry about scratching up the original:</p> <ul> <li>Direct recording of multiple tracks </li> <li>Read / store album information from/to the cdplayer.ini file </li> <li>Read / store album information from/to a local and/or remote CD Database (CDDB) </li> <li>Support CD-Text (if your CD-drive supports it) </li> <li>Advanced jitter correction (based on the cd-paranoia ripping library) </li> <li>Indicates track progress and jitter control </li> <li>Normalization of audio signal </li> <li>Supports many CD-Drive from many manufacters </li> <li>Conversion of external WAV files </li> <li>Support for M3U and PLS play list files </li> <li>Best of all, it's free (GPL license, source code available) </li> <li>Serveral languages are supported </li> </ul> <p>--------- </p> <p>Into news feeds?  Then you should be using <a href="www.NewsGator.com/FeedDemon" target="_blank">FeedDemon</a>.  It will sync to your Google Reader account:</p> <ul> <li><strong>Newspaper Format</strong>: When you select a channel, FeedDemon's tabbed browser displays the channel's news items in a newspaper for easy reading. You can display a newspaper of news items for an entire folder or view one feed at a time. </li> <li><strong>News Bins</strong>: Store news items in a central location and provide a handy way to collect items from different channels. If you find an interesting item that you might want to read again, just store it in a news bin for future reference. </li> <li><strong>Shared Experience</strong>: See what news is popular with other NewsGator users and find out who is linking to the news you’re reading. </li> <li><strong>Video</strong>: Watch embedded video right within the newspaper view. </li> <li><strong>Panic Button</strong>: Ever gone on vacation and gotten a little behind on your reading? The Panic Button solves this and many other problems by quickly marking all older items read. </li> <li><strong>Watches</strong>: Look for keywords in news items as they're downloaded. After you create a watch, it examines every incoming news item whenever any channel is updated. </li> <li><strong>News Comes To You</strong>: Subscribe to feeds from all over the web or choose some of the dozens of default feeds. </li> <li><strong>Search</strong>: Search outside of FeedDemon's subscriptions by selecting a feed search engine, then enter your keyword, and FeedDemon will subscribe to a dynamic channel containing the search results for that keyword. </li> <li><strong>Podcasts</strong>: Powerful podcasting tools enable you to download audio files and automatically copy them to your iPod or other media player. The bundled FeedStation utility enables you to schedule your downloads so they happen overnight while you're asleep. When you wake up, you'll find new audio waiting on your media player of choice. </li> </ul> <p>--------- </p> <p>Is Photoshop a bit too expensive for you?  Try <a href="http://paint.net/" target="_blank">Paint.NET</a>.  I use it for editing images, creating icons, and a myriad of other minor image tasks.  A true power user can do much more than I can with it:</p> <ul> <li>Simple, intuitive, and innovative user interface <br />Every feature and user interface element was designed to be immediately intuitive and quickly learnable without assistance. In order to handle multiple images easily, Paint.NET uses a tabbed document interface. The tabs display a live thumbnail of the image instead of a text description. This makes navigation very simple and fast. </li> <li>Layers <br />Usually only found on expensive or complicated professional software, layers form the basis for a rich image composition experience. You may think of them as a stack of transparency slides that, when viewed together at the same time, form one image. </li> <li>Active Online Community <br />Paint.NET has an online forum with a friendly, passionate, and ever-expanding community. Be sure to check out the constantly growing list of tutorials and plugins! <br />Frequently Updated <br />Updates usually come about every 4 to 8 weeks, and contain new features, performance improvements, and bug fixes. Upgrading to the latest version is very simple, requiring only two clicks of the mouse. </li> <li>Special Effects <br />Many special effects are included for enhancing and perfecting your images. Everything from blurring, sharpening, red-eye removal, distortion, noise, and embossing are included. Also included is our unique 3D Rotate/Zoom effect that makes it very easy to add perspective and tilting. </li> <li>Adjustments are also included which help you tweak an image's brightness, contrast, hue, saturation, curves, and levels. You can also convert an image to black and white, or sepia-toned. </li> <li>Powerful Tools <br />Paint.NET includes simple tools for drawing shapes, including an easy-to-use curve tool for drawing splines or Bezier curves. The Gradient tool, new for 3.0, has been cited as an innovative improvement over similar tools provided by other software. The facilities for creating and working with selections is powerful, yet still simple enough to be picked up quickly. Other powerful tools include the Magic Wand for selecting regions of similar color, and the Clone Stamp for copying or erasing portions of an image. There is also a simple text editor, a tool for zooming, and a Recolor tool. </li> <li>Unlimited History <br />Everybody makes mistakes, and everybody changes their mind. To accommodate this, every action you perform on an image is recorded in the History window and may be undone. Once you've undone an action, you can also redo it. The length of the history is only limited by available disk space. </li> <li>Free! <br />Paint.NET doesn't cost a dime. </li> </ul> <p>--------- </p> <p>Do you chat with friends that use different IM networks?  <a href="www.ceruleanstudios.com/" target="_blank">Trillian</a> is a great application that supports various IM networks.  MSN, AIM, Yahoo, ICQ, and IRC are supported.</p> <p>--------- </p> <p>How am I writing this blog post?  <a href="http://download.live.com/" target="_blank">Windows Live Writer</a> of course. <a href="http://coolthingoftheday.blogspot.com/" target="_blank">Greg</a> turned me on to this application and it makes blog posting must simpler:</p> <blockquote> <p>“Writer makes it easy to share your photos and videos on almost any blog service—Windows Live, Wordpress, Blogger, LiveJournal, TypePad, and many more.”</p></blockquote> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0tag:blogger.com,1999:blog-7049316631692964922.post-2364041397526897382009-05-08T16:05:00.001-07:002009-05-08T16:05:07.855-07:00WPF Canvas Coordinate System<p>I noticed that the <strong>Canvas</strong> class doesn’t use the Cartesian coordinate system for mapping points. For instance, here’s a list of points: 0, 0; 15, 5; 25, 18.  Here’s how these points look when drawn to a <strong>Canvas</strong>:</p> <p><a href="http://lh4.ggpht.com/_jBiTiK8T3Jc/SgS6oIsfjxI/AAAAAAAAAJo/QoS9tsI92GY/s1600-h/wpfCanvasPoints%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="wpfCanvasPoints" border="0" alt="wpfCanvasPoints" src="http://lh4.ggpht.com/_jBiTiK8T3Jc/SgS6oSnWnhI/AAAAAAAAAJs/PjcfQi4hJB0/wpfCanvasPoints_thumb.png?imgmax=800" width="244" height="128" /></a> </p> <p>The above image is fine if that’s what you want to do with the points, but that isn’t the result I wanted.  I had to add a <strong>ScaleTransform</strong> to the <strong>Canvas</strong> for it to look the way I wanted.  This can be done in XAML:</p> <div> <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><</span><span style="color: #800000">Canvas</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="MainCanvas"</span> <span style="color: #ff0000">Background</span><span style="color: #0000ff">="AliceBlue"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="400"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="200"</span> <span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">Canvas.RenderTransform</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">ScaleTransform</span> <span style="color: #ff0000">CenterX</span><span style="color: #0000ff">="200"</span> <span style="color: #ff0000">CenterY</span><span style="color: #0000ff">="100"</span> <span style="color: #ff0000">ScaleX</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">ScaleY</span><span style="color: #0000ff">="-1"</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">Canvas.RenderTransform</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">Canvas</span><span style="color: #0000ff">></span></pre>
</div>
<p>or programmatically (VB.NET here):</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">Dim</span> YScale <span style="color: #0000ff">As</span> <span style="color: #0000ff">New</span> ScaleTransform
YScale.ScaleX = 1
YScale.ScaleY = -1
YScale.CenterX = MainCanvas.Width / 2
YScale.CenterY = MainCanvas.Height / 2
MainCanvas.RenderTransform = YScale</pre>
</div>
<p>You’ll notice the <strong>CenterX </strong>and <strong>CenterY</strong> properties are set to the middle of the <strong>Canvas.  </strong>You can think of this as your pivot point when flipping the <strong>Canvas </strong>(The <strong>CenterX</strong> isn’t really needed here since we’re just flipping on the Y axis).The end result is what I was expecting:</p>
<p><a href="http://lh6.ggpht.com/_jBiTiK8T3Jc/SgS6oiWz3II/AAAAAAAAAJw/YPDSxgeFlHQ/s1600-h/wpfCanvasPointsYTransform%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="wpfCanvasPointsYTransform" border="0" alt="wpfCanvasPointsYTransform" src="http://lh6.ggpht.com/_jBiTiK8T3Jc/SgS6o6DeEXI/AAAAAAAAAJ0/8JK_DMCWZ8o/wpfCanvasPointsYTransform_thumb.png?imgmax=800" width="244" height="128" /></a></p> Peter Choihttp://www.blogger.com/profile/07402729528155082461noreply@blogger.com0