<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Double D's Blog</title>
	<atom:link href="http://derreckdean.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://derreckdean.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 01 Nov 2011 20:59:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='derreckdean.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Double D's Blog</title>
		<link>http://derreckdean.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://derreckdean.wordpress.com/osd.xml" title="Double D&#039;s Blog" />
	<atom:link rel='hub' href='http://derreckdean.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Silverlight, popup windows, and browser/out of browser differences</title>
		<link>http://derreckdean.wordpress.com/2011/11/01/silverlight-popup-windows-and-browserout-of-browser-differences/</link>
		<comments>http://derreckdean.wordpress.com/2011/11/01/silverlight-popup-windows-and-browserout-of-browser-differences/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 20:59:08 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Popups]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=128</guid>
		<description><![CDATA[Opening popup windows in Silverlight is a pain in the rear. However, a way has been found to work around this. Subclass the HyperlinkButton and expose a new method that calls the protected Click() method. internal class OOBPopup : HyperlinkButton { public void Navigate(Uri url) { this.NavigateUri = url; this.TargetName = "_blank"; base.OnClick(); } } [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=128&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Opening popup windows in Silverlight is a pain in the rear. However, a way has been found to work around this. Subclass the HyperlinkButton and expose a new method that calls the protected Click() method.</p>
<p><code><br />
		internal class OOBPopup : HyperlinkButton<br />
		{<br />
			public void Navigate(Uri url)<br />
			{<br />
				this.NavigateUri = url;<br />
				this.TargetName = "_blank";<br />
				base.OnClick();<br />
			}<br />
		}<br />
</code></p>
<p>To use:<br />
<code><br />
	new OOBPopup().Navigate(url);<br />
</code></p>
<p>Let&#8217;s compare this with the two other options, HtmlPage.Navigate() and HtmlPage.PopupWindow(). Everything below is on Windows 7 64-bit. (IB = in browser, OOB = out of browser)</p>
<p>IB IE 9: All three methods work.<br />
IB Safari 5.1.1: Only the OOB popup works.<br />
IB Firefox 7: Only the OOB popup works.<br />
IB Chrome: Only the OOB popup works.<br />
OOB: Only the OOB popup works.</p>
<p>Where a method does not work, either you will get a message saying that the HTML/DOM scripting bridge is disabled, or the browser (especially Safari) will just eat the popup and act like nothing happened.</p>
<p>With the OOBPopup class setting enableHtmlPopups in the OBJECT tag hosting the silverlight app is not required, so it&#8217;s a great way to get popup windows to work. The app I am working on makes heavy use of SSRS so popup windows are necessary.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=128&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/11/01/silverlight-popup-windows-and-browserout-of-browser-differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>Bind a list of items to an accordion control with grouping</title>
		<link>http://derreckdean.wordpress.com/2011/10/24/bind-a-list-of-items-to-an-accordion-control-with-grouping/</link>
		<comments>http://derreckdean.wordpress.com/2011/10/24/bind-a-list-of-items-to-an-accordion-control-with-grouping/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 16:00:47 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI Design]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=123</guid>
		<description><![CDATA[My model looks like this: public sealed class ReportItem { public string Name { get; set; } public string Description { get; set; } public string GroupName { get; set; } } I want to display these reports in an accordion control, where the items are grouped by the GroupName property. The group name would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=123&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My model looks like this:</p>
<p><code><br />
public sealed class ReportItem<br />
{</code></p>
<p>public string Name { get; set; }<br />
public string Description { get; set; }<br />
public string GroupName { get; set; }</p>
<p>}</p>
<p>I want to display these reports in an accordion control, where the items are grouped by the<br />
GroupName property. The group name would be the accordion header buttons, and under each<br />
accordion group would appear the items containing that group name.</p>
<p>You&#8217;ll need a CollectionViewSource:</p>
<p><code><br />
&lt;navigation.Page ... xmlns:data="clr-namespace:System.Windows.Data;assembly=System.Windows"<br />
</code></p>
<p>&nbsp;</p>
<p><code></p>
<p></code></p>
<pre>	&lt;navigation:Page.Resources&gt;
		&lt;data:CollectionViewSource x:Key="ReportsViewSource" Source="{Binding Reports}"&gt;
			&lt;data:CollectionViewSource.GroupDescriptions&gt;
				&lt;PropertyGroupDescription PropertyName="GroupName" /&gt;
			&lt;/data:CollectionViewSource.GroupDescriptions&gt;
		&lt;/data:CollectionViewSource&gt;
	&lt;/navigation:Page.Resources&gt;</pre>
<p><code></p>
<p></code></p>
<p>I&#8217;m using a model object so my report collection is a property called Reports.</p>
<p>The GroupName is the property I am grouping by.</p>
<pre>		&lt;toolkit:Accordion ItemsSource="{Binding BindsDirectlyToSource=True, Source={StaticResource ReportsViewSource}, Path=View.Groups}" Grid.Row="1" HorizontalAlignment="Left" Name="accordion1" Width="315" VerticalAlignment="Stretch"&gt;
			&lt;toolkit:Accordion.ContentTemplate&gt;
				&lt;DataTemplate&gt;
					&lt;ListBox ItemsSource="{Binding Items}" BorderThickness="0"&gt;&lt;!-- this is the Group.Items --&gt;
						&lt;ListBox.ItemTemplate&gt;
							&lt;DataTemplate&gt;
								&lt;TextBlock FontWeight="Bold" Text="{Binding Name}" /&gt;&lt;!-- this is the Report.Name --&gt;
							&lt;/DataTemplate&gt;
						&lt;/ListBox.ItemTemplate&gt;
					&lt;/ListBox&gt;
				&lt;/DataTemplate&gt;
			&lt;/toolkit:Accordion.ContentTemplate&gt;
			&lt;toolkit:Accordion.ItemTemplate&gt;
				&lt;DataTemplate&gt;
					&lt;TextBlock Text="{Binding Name}" /&gt;&lt;!-- this is the Group.Name --&gt;
				&lt;/DataTemplate&gt;
			&lt;/toolkit:Accordion.ItemTemplate&gt;
		&lt;/toolkit:Accordion&gt;</pre>
<p><code><br />
</code></p>
<p>ReportsViewSource is my CollectionViewSource. The property View contains some objects, like Items for the items without grouping.<br />
The property Groups contains a collection of Groups, each with a Name and Items property. The accordion&#8217;s ItemTemplate defines the<br />
headers, while the ContentTemplate defines the content to go into each accordion. Here I am using a ListBox to display the subitems.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=123&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/10/24/bind-a-list-of-items-to-an-accordion-control-with-grouping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>RIA Services and Timestamp/Concurrency Field Gotcha</title>
		<link>http://derreckdean.wordpress.com/2011/09/16/ria-services-and-timestampconcurrency-field-gotcha/</link>
		<comments>http://derreckdean.wordpress.com/2011/09/16/ria-services-and-timestampconcurrency-field-gotcha/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 14:43:52 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Codegen]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=117</guid>
		<description><![CDATA[I&#8217;m working with a table that has a timestamp column in EF. I&#8217;m using this to detect when multiple people are editing the same data so that one person&#8217;s changes don&#8217;t get overwritten by another user. In the EF designer, you would mark this property as StoreGeneratedPattern=Computed and ConcurrencyMode=Fixed, so that the code gen knows [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=117&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working with a table that has a timestamp column in EF. I&#8217;m using this to detect when multiple people are editing the same data so that one person&#8217;s changes don&#8217;t get overwritten by another user. In the EF designer, you would mark this property as<code> StoreGeneratedPattern=Computed</code> and <code>ConcurrencyMode=Fixed</code>, so that the code gen knows to generate a read-only field that gets roundtripped to the server on updates. If, during an update, the timestamp value that gets roundtripped to the server differs from the one in the database, then an <code>OptimisticConcurrencyException </code>is thrown so you have a chance to get the stored version of the data and possibly pop up a dialog that allows you to merge the changes together. </p>
<p>However, I have come across a gotcha when working with RIA services. Since the timestamp field is not NULLable, RIA services marks it as <code>[Required]</code> and <code>[Editable(false)]</code> when generating the code. When creating a new class to add to the data store, this ends up messing with validation, so in my datagrid it pops up with &#8220;Timestamp field is required&#8221;. You can&#8217;t set the field yourself, as it will throw an exception saying that the field is read-only.</p>
<p>A <a href="http://blog.jtango.net/ria-services-auto-generating-concurrency-timestamps" target="_blank">solution is found in the comments here</a> for Linq-to-SQL, so here&#8217;s how to do it for EF.</p>
<p>I didn&#8217;t bother using the EF designer, I right-clicked the file in VS and clicked &#8220;Open With&#8230;&#8221;, then clicked XML editor. This brings up the XML schema that&#8217;s used to generate all of the code. Scroll down until you can find the class, mine was <code>&lt;EntityType Name="Class"&gt;</code>. Find the property for your timestamp, mine was <code>&lt;PropertyType Name="Timestamp" ConcurrencyMode="Fixed" Nullable="false" ...&gt;</code>. Change that <code>Nullable="false"</code> to <code>true</code>, and save. The RIA services generated code will no longer require you to fill in the timestamp, and the database will handle creating the timestamp for you when the object is persisted to the database.</p>
<p>However, there is one more gotcha &#8211; it&#8217;s still marked as a required field. There may be a better way to accomplish this, but what I did was this: I have a field called CreationTimestamp, so I used the <code>partial OnCreationTimestamp()</code> method:</p>
<p><code>		partial void OnCreationTimestampChanged()<br />
		{<br />
			if (Timestamp == null)<br />
				Timestamp = new byte[] { };<br />
		}</code></p>
<p>This fixes the issue, for now.</p>
<p>Anyone know of a better way?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=117&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/09/16/ria-services-and-timestampconcurrency-field-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding to Page Title in Silverlight</title>
		<link>http://derreckdean.wordpress.com/2011/06/10/binding-to-page-title-in-silverlight/</link>
		<comments>http://derreckdean.wordpress.com/2011/06/10/binding-to-page-title-in-silverlight/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 17:33:39 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=111</guid>
		<description><![CDATA[In SL4, the title of a page in a Silverlight navigation project is not implemented as a depenency property. You can&#8217;t bind the title of a page from a view model directly to it. While this article was a great starting point, the first 2 examples did not work for me. I implemented a dependency [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=111&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In SL4, the title of a page in a Silverlight navigation project is not implemented as a depenency property. You can&#8217;t bind the title of a page from a view model directly to it. <a href="http://forums.silverlight.net/forums/p/97849/223734.aspx" title="While this article was a great starting point," target="_blank">While this article was a great starting point,</a> the first 2 examples did not work for me. </p>
<p>I implemented a dependency property to handle it. Gets to the property may not work well, but its purpose is to set the page title, so that should not matter.</p>
<p><code></p>
<p>	///<br />
<summary>
	/// This allows a page title in a Silverlight Navigation application to be bound to.<br />
	/// Silverlight page titles are not DPs so they cannot be bound by normal means.<br />
	/// This replaces the event used in codebehind called OnDataLoaded, whose only<br />
	/// purpose was to set the page title.<br />
	/// Taken &amp; Modified from http://forums.silverlight.net/forums/p/97849/223734.aspx<br />
	/// </summary>
<p>	public class PageTitleBindingHelper : FrameworkElement //, INotifyPropertyChanged<br />
	{</p>
<p>		public string PageTitle<br />
		{<br />
			get { return (string)GetValue(PageTitleProperty); }<br />
			set { SetValue(PageTitleProperty, value); }<br />
		}</p>
<p>		// Using a DependencyProperty as the backing store for PageTitleProperty.  This enables animation, styling, binding, etc...<br />
		public static DependencyProperty PageTitleProperty;</p>
<p>		public PageTitleBindingHelper()<br />
		{<br />
			PageTitleProperty = DependencyProperty.Register("PageTitleProperty", typeof(string), typeof(PageTitleBindingHelper), new PropertyMetadata("", new PropertyChangedCallback(PageTitleChanged)));<br />
		}</p>
<p>		private void PageTitleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)<br />
		{<br />
<del datetime="2011-06-14T20:09:20+00:00">			HtmlPage.Document.SetProperty("title", e.NewValue);<br />
</del><br />
			Page p = App.Window.ContentFrame.Content as Page;<br />
			if (p != null)<br />
				p.Title = (string)e.NewValue;</p>
<p>			//NotifyPropertyChanged("PageTitle");<br />
		}<br />
     }<br />
</code></p>
<p>To use: Place an instance in your page resources and bind the PageTitle property to whatever property is on your view model.</p>
<p>EDIT: HtmlPage seemed to crash randomly for other users of my app, so I&#8217;ve changed this. I have a reference to my main window available from the App class, where I was using it to hide parts of the UI for a kiosk, etc. I use that and figure out what page I am on, and set the title that way. It may not be the cleanest solution, but I will revisit this once I have some spare time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=111&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/06/10/binding-to-page-title-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>FizzBuzz in one line C# Linq</title>
		<link>http://derreckdean.wordpress.com/2011/05/09/fizzbuzz-in-one-line-c-linq/</link>
		<comments>http://derreckdean.wordpress.com/2011/05/09/fizzbuzz-in-one-line-c-linq/#comments</comments>
		<pubDate>Mon, 09 May 2011 21:11:22 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=109</guid>
		<description><![CDATA[The FizzBuzz problem is this: - Print numbers from 1 to 100. - Print &#8220;Fizz&#8221; instead of the number if the current number is evenly divisible by 3. - Print &#8220;Buzz&#8221; instead of the number if the current number is evenly divisible by 5. - Print &#8220;FizzBuzz&#8221; instead of the number if the current number [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=109&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The FizzBuzz problem is this:<br />
- Print numbers from 1 to 100.<br />
- Print &#8220;Fizz&#8221; instead of the number if the current number is evenly divisible by 3.<br />
- Print &#8220;Buzz&#8221; instead of the number if the current number is evenly divisible by 5.<br />
- Print &#8220;FizzBuzz&#8221; instead of the number if the current number is evenly divisible by both 3 and 5.</p>
<p>Here&#8217;s the FizzBuzz problem, expressed as a single line in C# using Linq:</p>
<p><code><br />
Enumerable.Range(1, 100).ToList().ForEach(i =&gt; Console.WriteLine((i % 3 == 0 &amp;&amp; i % 5 == 0) ? "FizzBuzz" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i.ToString()));<br />
</code></p>
<p>It took about 45 seconds to write the code. =]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=109&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/05/09/fizzbuzz-in-one-line-c-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>Run PowerShell scripts within Silverlight 4 OOB Elevated Permissions</title>
		<link>http://derreckdean.wordpress.com/2011/05/09/run-powershell-scripts-within-silverlight-4-oob-elevated-permissions/</link>
		<comments>http://derreckdean.wordpress.com/2011/05/09/run-powershell-scripts-within-silverlight-4-oob-elevated-permissions/#comments</comments>
		<pubDate>Mon, 09 May 2011 21:07:16 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=105</guid>
		<description><![CDATA[You have to run your SL app with elevated permissions out-of-browser, but this will allow you to query Powershell. You&#8217;ll have to parse the output yourself. namespace TestPowershellScripting { using System; using System.ComponentModel; using System.IO; using System.Runtime.InteropServices.Automation; /// /// Powershell runner for Silverlight applications. /// Requires that OOB and elevated permissions are active. /// public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=105&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You have to run your SL app with elevated permissions out-of-browser, but this will allow you to query Powershell. You&#8217;ll have to parse the output yourself.</p>
<p><code></p>
<p>namespace TestPowershellScripting<br />
{<br />
	using System;<br />
	using System.ComponentModel;<br />
	using System.IO;<br />
	using System.Runtime.InteropServices.Automation;</p>
<p>	///<br />
<summary>
	/// Powershell runner for Silverlight applications.<br />
	/// Requires that OOB and elevated permissions are active.<br />
	/// </summary>
<p>	public class PowerShellSL<br />
	{</p>
<p>		///<br />
<summary>
		/// Name of the PowerShell executable.<br />
		/// </summary>
<p>		private const string PowerShellExecutable = "powershell.exe";</p>
<p>		///<br />
<summary>
		/// Specifies whether to include user profile information as part of the PowerShell<br />
		/// executing context. When set to false, PowerShell runs faster, but does not have<br />
		/// access to user-level environment variables.<br />
		/// </summary>
<p>		public bool UseProfile { get; set; }</p>
<p>		///<br />
<summary>
		/// Runs a PowerShell script and returns the output as a string.<br />
		/// In the PowerShell script, use WriteHost to write output to standard output.<br />
		/// The script is written to standard input and run using the WScript library.<br />
		/// </summary>
<p>		/// The PowerShell script to run, expressed as a string.<br />
		///<br />
		/// A FileNotFoundException is thrown if Powershell cannot be run.<br />
		/// An InvalidOperationException is thrown if the automation factory is unavailable.<br />
		public string Run(string script) {</p>
<p>			// Check to see if stuff is available<br />
			if (!AutomationFactory.IsAvailable)<br />
				throw new InvalidOperationException("AutomationFactory is unavailable. Program must be run as out-of-browser with elevated permissions.");</p>
<p>			var shell = AutomationFactory.CreateObject("WScript.Shell");<br />
			string cmd = PowerShellExecutable + " -NonInteractive " + (UseProfile ? "" : "-NoProfile") + " -WindowStyle Hidden -Command -";<br />
			string output = "";</p>
<p>			dynamic result = null;<br />
			try {<br />
				result = shell.Exec(cmd);<br />
				result.StdIn.Write(script);<br />
				result.StdIn.Close();</p>
<p>				while (!result.StdOut.AtEndOfStream) {<br />
					output += result.StdOut.ReadLine() + "\r\n";<br />
				}<br />
			} catch (FileNotFoundException fnfex) {<br />
				throw new FileNotFoundException("PowerShell is not installed on the local computer.", fnfex);</p>
<p>			}</p>
<p>			return output;<br />
		}</p>
<p>		///<br />
<summary>
		/// Runs a PowerShell script asynchronously (using a BackgroundWorker) and returns the output as a string.<br />
		/// When results are available, the delegate 'results' is called with the program output.<br />
		/// In the PowerShell script, use WriteHost to write output to standard output.<br />
		/// The script is written to standard input and run using the WScript library.<br />
		/// </summary>
<p>		/// The PowerShell script to run, expressed as a string.<br />
		/// The delegate method to call when results have been returned.<br />
		/// A FileNotFoundException is thrown if Powershell cannot be run.<br />
		/// An InvalidOperationException is thrown if the automation factory is unavailable.<br />
		public void RunAsync(string script, Action results) {<br />
			BackgroundWorker bw = new BackgroundWorker();<br />
			bw.DoWork += new DoWorkEventHandler(<br />
				(sender, e) =&gt; {<br />
					e.Result = this.Run((string)e.Argument);<br />
				}<br />
			);<br />
			bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(<br />
				(sender, e) =&gt; {<br />
					if (results != null)<br />
						results((string)e.Result);<br />
				}<br />
			);<br />
			bw.RunWorkerAsync(script);<br />
		}</p>
<p>	}</p>
<p>}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=105&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/05/09/run-powershell-scripts-within-silverlight-4-oob-elevated-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>JQuery Input Field Magic</title>
		<link>http://derreckdean.wordpress.com/2011/04/25/jquery-input-field-magic/</link>
		<comments>http://derreckdean.wordpress.com/2011/04/25/jquery-input-field-magic/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 20:47:05 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=103</guid>
		<description><![CDATA[I&#8217;m working on a form that takes in names of children to be added as visitors to an organization. The form has 20 rows of input fields enclosed in a TBODY, so I know which rows are not header rows. I don&#8217;t want to show all 20 rows, since most people have on average three [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=103&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a form that takes in names of children to be added as visitors to an organization. The form has 20 rows of input fields enclosed in a TBODY, so I know which rows are not header rows. I don&#8217;t want to show all 20 rows, since most people have on average three children, but I want to be able to handle a large group of children in a family, in case the Duggars move here or something. So, the following javascript hides all fields except the first and except any that are pre-filled (in the event that form validation fails).</p>
<p><code><br />
				&lt;script type="text/javascript"&gt;</p>
<p>					var $children = $("#children");<br />
					$children.find("tbody tr:not(:first):not(:has(input[value]))").hide();<br />
					$children.append("<br />
<tfoot>
<tr>
<th colspan='4'></th>
</tr>
</tfoot>
<p>");<br />
					$("#addChild").click(function () {<br />
						var nextrow = $children.find("tbody tr:hidden:first")[0];<br />
						$(nextrow).show();<br />
						nextrow = $children.find("tbody tr:hidden:first")[0];<br />
						if (nextrow == null) {<br />
							// get rid of add button since there are no more hidden rows to display<br />
							$("#addChild").remove();<br />
						}<br />
					});</p>
<p>				&lt;/script&gt;<br />
</code></p>
<p>Let&#8217;s look at this line:<br />
<code><br />
$children.find("tbody tr:not(:first):not(:has(input[value]))").hide();<br />
</code></p>
<p>I&#8217;m basically saying, find all TR (table rows) inside of a TBODY tag, excluding the first and excluding any rows that contain INPUT tags that contain a value.</p>
<p>The next line adds a TFOOT tag to the end of the table, and adds a button inside a row called addChild.</p>
<p>The next code block acts when the button is clicked. It finds the next hidden row, and displays it. It then finds the next hidden row after that, and if one is not found, the button is removed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=103&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/04/25/jquery-input-field-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>My gripes with the Facebook iPhone app</title>
		<link>http://derreckdean.wordpress.com/2011/03/03/my-gripes-with-the-facebook-iphone-app/</link>
		<comments>http://derreckdean.wordpress.com/2011/03/03/my-gripes-with-the-facebook-iphone-app/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 21:16:14 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[FB]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=100</guid>
		<description><![CDATA[I use the Facebook iPhone app all the time, far more than I use the web site. The app is great, except for a couple flaws, one which I think is a major issue. There is no way to block posts from other people like you can with the web site. I had this group [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=100&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I use the Facebook iPhone app all the time, far more than I use the web site. The app is great, except for a couple flaws, one which I think is a major issue.</p>
<p>There is no way to block posts from other people like you can with the web site. I had this group &#8220;liked&#8221; called No Stressss, which had some cool stuff occasionally, but most of the time posts were made in Arabic and there would be 10 posts in a row,  as if the person was copying-and-pasting and posting stuff rapid-fire. I blocked their posts from the web site, but they still show up on my phone, since the phone app doesn&#8217;t seem to follow the same post display rules as the web site does. Since I use Facebook on my phone more than I do the regular web site, I had to &#8220;unlike&#8221; them so the barrage of posts didn&#8217;t show up on my phone anymore. I didn&#8217;t understand how to unlike someone at first, especially since I wasn&#8217;t able to see their posts on the web site and you can&#8217;t hide posts from people from the phone app, so I had to type the name of the person and find the tiny &#8220;unlike&#8221; link on the left side to remove them.</p>
<p>That&#8217;s no so bad, I guess. There should be a way to block posts and like/unlike people from the phone. That&#8217;s not the most annoying issue though&#8230; I&#8217;ll read Facebook once or twice a day, at most. The way the news feed on the phone is set up is you scroll up and down a &#8220;page&#8221; of posts. If you pull the list down (scroll up) and then let go, you will refresh the list of posts. If you scroll to the bottom, there is a &#8220;Older Posts&#8221; button that, when clicked, loads the next page of results and appends it. Super simple, great UI design, and a three year old can figure it out. My gripe is with how arriving posts are handled. It seems the app either polls for new posts on a timer, or there&#8217;s a push notification sent when a new post has been posted. If you&#8217;re three pages deep, the app&#8217;s UI will block/freeze and the list will completely reset to the first page of posts. So, I&#8217;m reading a post from my cousin about fist pumping to Jersey Shore and just when I&#8217;m about to hit the reply button to call him a dirty little hamster, the UI blocks and the list resets about 5 seconds later.</p>
<p>Why does the list have to reset itself? Basically the list is a collection of posts ordered by date and time descending. Since it&#8217;s either polling for new posts or using a push  notification to get new posts, why not just push the new results to the top of the stack rather than reset the whole list, so I don&#8217;t have to scroll down to the bottom of the list and click Older Posts three times to get back to where I was? If I close and re-open the app, the list can be reset then. I wouldn&#8217;t reset the list if the person closed or backgrounded the app within a few minutes. </p>
<p>The Facebook app is indispensable, and aside from these issues, is well designed. It just needs a little more polish to achieve greatness.</p>
<p>Summary:</p>
<p>Posts on phone do not adhere to ignore rules set up on the web site.<br />
There is no way to block posts, or unlike people from the phone app.<br />
When new posts arrive, the list resets itself to the first page, losing your current place.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/100/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=100&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/03/03/my-gripes-with-the-facebook-iphone-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding to a Checkbox List in XAML</title>
		<link>http://derreckdean.wordpress.com/2011/02/25/binding-to-a-checkbox-list-in-xaml/</link>
		<comments>http://derreckdean.wordpress.com/2011/02/25/binding-to-a-checkbox-list-in-xaml/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 14:58:57 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=96</guid>
		<description><![CDATA[This technique is useful outside of XAML bindings, too. I found myself working with a person object that can belong to 0 or more groups. The database spec is that it is a many-to-many relationship, something that RIA services chokes on at this time. Group - ID - GroupName - GroupDescription Person - ID - [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=96&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This technique is useful outside of XAML bindings, too. I found myself working with a person object that can belong to 0 or more groups. The database spec is that it is a many-to-many relationship, something that RIA services chokes on at this time.</p>
<p><code>Group<br />
- ID<br />
- GroupName<br />
- GroupDescription</p>
<p>Person<br />
- ID<br />
- FirstName<br />
- LastName</p>
<p>PersonXGroup<br />
- PersonID<br />
- GroupID<br />
- CreationTimeStamp // this is here because RIA doesn't play nice with *-* relationships<br />
</code></p>
<p>So, imagine here that there are two foreign keys set up on this model, you know where they go. You need to bind to two different things: The master list which contains all available groups, and the groups that this person has enabled. So, how would you go about binding this list to an ItemsControl filled with checkboxes that allow you to update the state? Use a CheckboxBinder object, which follows.</p>
<p><code><br />
	///<br />
<summary>
	/// Given a master list of items and an object containing a subset of these items,<br />
	/// such as a list of groups available and a person belonging to none, some, or all groups,<br />
	/// this class allows for binding this list to an itemscontrol with checkboxes to<br />
	/// turn on/off items by adding or removing the groups from the person.<br />
	/// Adding and removing the items once chnages are to be committed can be handled<br />
	/// in a couple ways: (a) By hand, looping through the collection and adding or removing<br />
	/// each one, using HasChanged() to see what items have changed, or<br />
	/// (b) assign a delegate action for the work to be done when the state changes.<br />
	/// </summary>
<p>	///<br />
	public class CheckboxBinder<br />
	{</p>
<p>		public T Item { get; set; }</p>
<p>		///<br />
<summary>
		/// Gets or sets the current checked state for this item.<br />
		/// If the ItemCheckedChanged delegate is not null, it is called when the state of the item<br />
		/// changes.<br />
		/// </summary>
<p>		public bool IsChecked {<br />
			get { return _isChecked; }<br />
			set {<br />
				if (_isChecked != value) {<br />
					_isChecked = value;<br />
					if (ItemCheckedChanged != null) { ItemCheckedChanged(Item, IsChecked); }<br />
				}<br />
			}<br />
		}<br />
		private bool _isChecked;</p>
<p>		///<br />
<summary>
		/// Optional delegate that is called when IsChecked has changed.<br />
		/// Returns the item and its current check state.<br />
		/// </summary>
<p>		public Action ItemCheckedChanged { get; set; }</p>
<p>		//////////////////////////////////////////////////////</p>
<p>		private bool InitiallyChecked { get; set; }</p>
<p>		//////////////////////////////////////////////////////</p>
<p>		public CheckboxBinder(T item, bool initiallyChecked) {<br />
			Item = item;<br />
			_isChecked = initiallyChecked;<br />
			InitiallyChecked = initiallyChecked;<br />
		}</p>
<p>		public bool HasChanged() {<br />
			return (IsChecked != InitiallyChecked);<br />
		}</p>
<p>	}<br />
</code></p>
<p>It&#8217;s a small class with a lot of power. On your viewmodel (you are using viewmodels, right?) define a collection of ObservableCollection&lt;CheckboxBinder&gt;. This is what you bind your ItemsControl to in your XAML code.</p>
<p><code>public ObservableCollection&lt;CheckboxBinder&gt; Groups { get; private set; }</code></p>
<p>When a Person object has been loaded for editing, I populate this list. The constructor for the CheckboxBinder object requires an instance of the item to be bound to, and the initial state as a boolean. The current state of the object is controlled by a bool property called HasChanges(), which compares the initial state to the current state. However, that would be used in a scenario where, when you press the Save button, your code would loop through the entries or use a LINQ statement to grab everything that has changes and then perform an action on it. However, that breaks up the functionality into multiple places throughout your code file, so I enabled another method of updating the collection with the use of an Action property called ItemCheckChanged:</p>
<p><code>		///<br />
<summary>
		/// Handles loading the groups and performing any changes, using the CheckboxBinder's<br />
		/// provided change delegate.<br />
		/// </summary>
<p>		private void loadGroups() {<br />
			Groups = new ObservableCollection&lt;CheckboxBinder&gt;();<br />
			foreach (Group group in Reference.PersonData.Groups) {<br />
				var cbgroup = new CheckboxBinder(group, CurrentPerson.PersonXGroups.Any(g =&gt; g.Group == group));<br />
				cbgroup.ItemCheckedChanged = (item, isChecked) =&gt; {<br />
					if (isChecked) {<br />
						CurrentPerson.PersonXGroups.Add(new PersonXGroup() { Group = item, Person = CurrentPerson });<br />
					} else {<br />
						PersonXGroup pxg = CurrentPerson.PersonXGroups.Single(px =&gt; px.Group == item);<br />
						//CurrentPerson.PersonXGroups.Remove(pxg);<br />
						Reference.PersonData.Delete(pxg);<br />
					}<br />
				};<br />
				Groups.Add(cbgroup);<br />
			}<br />
		}</code></p>
<p>You pass ItemCheckedChanged a void delegate with 2 parameters: The item being modified and its current state. It&#8217;s only called when the value actually changes (so if the current state is false and you change the value to false, this will not be called). The update code handles adding and removing items from the collection.</p>
<p><code>					if (isChecked) {<br />
						CurrentPerson.PersonXGroups.Add(new PersonXGroup() { Group = item, Person = CurrentPerson });<br />
					} else {<br />
						PersonXGroup pxg = CurrentPerson.PersonXGroups.Single(px =&gt; px.Group == item);<br />
						//CurrentPerson.PersonXGroups.Remove(pxg);<br />
						Reference.PersonData.Delete(pxg);<br />
					}</code></p>
<p>This way, you&#8217;re not iterating through a loop at the start of your Save routine. However, this is possible because I can just RejectChanges on my data context if I so desire &#8211; but the other aforementioned method works well if you don&#8217;t have the ability to roll back changes like you can on a data context.</p>
<p>Here&#8217;s the XAML used to bind to the checkbox list:<br />
<code>&lt;sdk:Label Content="Groups" Style="{StaticResource FormHeaderStyle}" Margin="5,10,5,0" /&gt;<br />
&lt;ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto"&gt;<br />
	&lt;ItemsControl ItemsSource="{Binding Path=Groups}" Height="130"&gt;<br />
		&lt;ItemsControl.ItemTemplate&gt;<br />
			&lt;DataTemplate&gt;<br />
				&lt;CheckBox Margin="2" Content="{Binding Path=Item.GroupName}" ToolTipService.ToolTip="{Binding Path=Item.GroupDescription}" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" /&gt;<br />
			&lt;/DataTemplate&gt;<br />
		&lt;/ItemsControl.ItemTemplate&gt;<br />
	&lt;/ItemsControl&gt;<br />
&lt;/ScrollViewer&gt;</code></p>
<p>Has this helped you? Do you know of a better way to accomplish the same task? Shout it out in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=96&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/02/25/binding-to-a-checkbox-list-in-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
		<item>
		<title>Building infrastructure to support one declaration of domain model for use with EF and RIA Services</title>
		<link>http://derreckdean.wordpress.com/2011/02/15/building-infrastructure-to-support-one-declaration-of-domain-model-for-use-with-ef-and-ria-services/</link>
		<comments>http://derreckdean.wordpress.com/2011/02/15/building-infrastructure-to-support-one-declaration-of-domain-model-for-use-with-ef-and-ria-services/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 04:53:12 +0000</pubDate>
		<dc:creator>derreckdean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://derreckdean.wordpress.com/?p=94</guid>
		<description><![CDATA[I&#8217;ve been working on a way to declare a domain model on the server, to be used on both the server and on the Silverlight client through RIA services. Believe me when I say that this has been no easy task! I tried to implement a single shared IDataRepository interface to both the client and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=94&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a way to declare a domain model on the server, to be used on both the server and on the Silverlight client through RIA services. Believe me when I say that this has been no easy task!</p>
<p>I tried to implement a single shared IDataRepository interface to both the client and server by marking the filename as .shared.cs. The data access methods would use a syntax similar to the following: repo.Get(string[] includeRelatedTables, Action&lt;IQueryable&gt; results), so when the data has been retrieved, it calls the callback with the results. With Silverlight, there is no synchronous database communication, so this syntax is the only one that works. However, that callback method won&#8217;t work when using the domain model with MVC&#8230; I can&#8217;t return a ViewResult to the anonymous function inside. </p>
<p>Another way of doing this would be to declare virtual methods that, on each side (client EF/server RIA) implements its own way of getting the data. Another better solution would be to declare these functions as Func&lt;IQueryable&gt; properties that can be get or set. However, I would run into the same problem as MVC on the server side, where the virtual method or Func would require me to return the results from the data source, and I can&#8217;t return from within an anonymous function&#8230; so, with this method, I&#8217;ve hit a brick wall.</p>
<p>I guess it&#8217;s time to install the Async CTP and see if I can make this work without using callbacks.  I know projects like CSLA have this covered, but I want to create (or find a good) solution that works right away with my EF entities and RIA entities. The Async CTP should allow me to write my async data call methods like I would with RIA services, so I should be able to get rid of all of the callbacks and have both interfaces return the list of objects directly.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/derreckdean.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/derreckdean.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/derreckdean.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=derreckdean.wordpress.com&amp;blog=4769965&amp;post=94&amp;subd=derreckdean&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://derreckdean.wordpress.com/2011/02/15/building-infrastructure-to-support-one-declaration-of-domain-model-for-use-with-ef-and-ria-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a74d1f14e83178780336595fe359b614?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">derreckdean</media:title>
		</media:content>
	</item>
	</channel>
</rss>
