<?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/"
	>

<channel>
	<title>batteryslave &#187; wpf</title>
	<atom:link href="http://www.batteryslave.com/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.batteryslave.com</link>
	<description>minor thoughts about gadgets, code, podcasts and other technical stuff...</description>
	<lastBuildDate>Sat, 20 Feb 2010 18:41:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>itemtemplate selection by type in xaml only</title>
		<link>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/</link>
		<comments>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 17:29:23 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=136</guid>
		<description><![CDATA[some days ago i found my self in need to change the itemtemplate in a listbox according to their type. and if with less code as possible. i had done this in a treeview but i couldnt find the code again. so i needed to figure it out again and with some help from a [...]]]></description>
			<content:encoded><![CDATA[<p>some days ago i found my self in need to change the itemtemplate in a listbox according to their type. and if with less code as possible. i had done this in a treeview but i couldnt find the code again. so i needed to figure it out again and with some help from a collegue we ended with this:</p>
<pre class="brush: xml; ">

&lt;!-- more xaml here --&gt;

&lt;ItemsControl ItemsSource=&quot;{Binding Items}&quot;&gt;
  &lt;ItemsControl.Resources&gt;
    &lt;DataTemplate DataType=&quot;{x:Type MyNameSpace:MyType1}&quot;&gt;
      &lt;RadioButton /&gt;
    &lt;/DataTemplate&gt;
    &lt;DataTemplate DataType=&quot;{x:Type MyNameSpace:MyType2}&quot;&gt;
      &lt;ComboBox  /&gt;
    &lt;/DataTemplate&gt;
    &lt;DataTemplate DataType=&quot;{x:Type MyNameSpace:MyType3}&quot;&gt;
      &lt;TextBox /&gt;
    &lt;/DataTemplate&gt;
  &lt;/ItemsControl.Resources&gt;
&lt;/ItemsControl&gt;

&lt;!-- more xaml here --&gt;
</pre>
<p><strong>remark</strong>: you arent allowed to give a key to that resources. i suppose the type is kind of key here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what is wrong with focus in wpf</title>
		<link>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/</link>
		<comments>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/#comments</comments>
		<pubDate>Thu, 14 May 2009 18:13:20 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=114</guid>
		<description><![CDATA[lately we wanted to set the initial focus on a window in wpf to improve the  keyboard experience in our app. what we want to achieve is just the initial  focus. so when one opens the window he can type or push the most meaningful  button instantly. unfortunately we encountered several problems. [...]]]></description>
			<content:encoded><![CDATA[<p>lately we wanted to set the initial focus on a window in wpf to improve the  keyboard experience in our app. what we want to achieve is just the initial  focus. so when one opens the window he can type or push the most meaningful  button instantly. unfortunately we encountered several problems. at first lets  see what wpf offers to set the focus. there are at least 4 possibilities:</p>
<ul>
<li>FocusManager</li>
<li>Keyboard.Focus</li>
<li>InputElement.Focus</li>
<li>InputElement.MoveFocus</li>
</ul>
<p>what i understand from <a href="http://msdn.microsoft.com/en-us/library/aa969768.aspx">msdn</a> is that  the best way to set the initial focus is the focusmanager. but we encountered  two problems where that wont work:</p>
<ul>
<li>set initial focus to a button with a commandbinding</li>
<li>set initial focus to an element defined through a contenttemplate</li>
</ul>
<p>i did not understand why that is. but i found two strange things: when  setting a breakpoint in the ContentRendered-Event you can see the button is  visible, but it is disabled. so i understand that i doesnt make sense to set the  focus to a disabled element. this seems like a bug to me. another thing i could  not understand is when the content of the control is set through a  ContentTemplate the Method FrameworkElement.FindName(string elementName) wouldnt  find the element. isnt that a bug too? when you inspect the window on screen  with scoop u can see all the elements of course.<br />
i tried to use the other  focus-methods in various events but none worked. funny thing: if you set the  focus and have a breakpoint in the Loaded-Event and just go on after stopping  there the focus is correct. Racecondition?</p>
<p>so is there someone who had similar problems? am i wrong with my feeling that  these are bugs?</p>
<p>i added an example <a href="http://www.batteryslave.com/wp-content/focustests.zip">solution</a> where you can see the sourcecode.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
