<!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" lang="en-US">
<![endif]-->
<!--[if !(IE 7) & !(IE 8)]><!-->
<html lang="en-US">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Default focus in XAML | Discovering .NET</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="http://discoveringdotnet.alexeyev.org/xmlrpc.php" />
<!--[if lt IE 9]>
<script src="http://discoveringdotnet.alexeyev.org/wp-content/themes/twentytwelve/js/html5.js" type="text/javascript"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="Discovering .NET &raquo; Feed" href="http://discoveringdotnet.alexeyev.org/feed" />
<link rel="alternate" type="application/rss+xml" title="Discovering .NET &raquo; Comments Feed" href="http://discoveringdotnet.alexeyev.org/comments/feed" />
<link rel="alternate" type="application/rss+xml" title="Discovering .NET &raquo; Default focus in XAML Comments Feed" href="http://discoveringdotnet.alexeyev.org/2011/01/default-focus-in-xaml.html/feed" />
		<script type="text/javascript">
			window._wpemojiSettings = {"baseUrl":"http:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"http:\/\/discoveringdotnet.alexeyev.org\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.2.12"}};
			!function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
		</script>
		<style type="text/css">
img.wp-smiley,
img.emoji {
	display: inline !important;
	border: none !important;
	box-shadow: none !important;
	height: 1em !important;
	width: 1em !important;
	margin: 0 .07em !important;
	vertical-align: -0.1em !important;
	background: none !important;
	padding: 0 !important;
}
</style>
<link rel='stylesheet' id='twentytwelve-fonts-css'  href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700&#038;subset=latin,latin-ext' type='text/css' media='all' />
<link rel='stylesheet' id='twentytwelve-style-css'  href='http://discoveringdotnet.alexeyev.org/wp-content/themes/twentytwelve/style.css?ver=4.2.12' type='text/css' media='all' />
<!--[if lt IE 9]>
<link rel='stylesheet' id='twentytwelve-ie-css'  href='http://discoveringdotnet.alexeyev.org/wp-content/themes/twentytwelve/css/ie.css?ver=20121010' type='text/css' media='all' />
<![endif]-->
<script type='text/javascript' src='http://discoveringdotnet.alexeyev.org/wp-includes/js/jquery/jquery.js?ver=1.11.2'></script>
<script type='text/javascript' src='http://discoveringdotnet.alexeyev.org/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://discoveringdotnet.alexeyev.org/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://discoveringdotnet.alexeyev.org/wp-includes/wlwmanifest.xml" /> 
<link rel='prev' title='Working with TFS process templates' href='http://discoveringdotnet.alexeyev.org/2011/01/working-with-tfs-process-templates.html' />
<link rel='next' title='The power of DataTemplate.DataType property' href='http://discoveringdotnet.alexeyev.org/2011/02/power-of-datatemplatedatatype-property.html' />
<meta name="generator" content="WordPress 4.2.12" />
<link rel='canonical' href='http://discoveringdotnet.alexeyev.org/2011/01/default-focus-in-xaml.html' />
<link rel='shortlink' href='http://discoveringdotnet.alexeyev.org/?p=18' />
<script type="text/javascript">
            var appInsights=window.appInsights||function(config){
                function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e="script",o=r.createElement(e),i,u;for(o.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t["_"+i](config,r,f,e,o),s}),t
            }({
                instrumentationKey:"bbf6b4fe-2b41-4882-8c08-fcab7845aca9"
            });
    
            window.appInsights=appInsights;
            appInsights.trackPageView("Default focus in XAML", window.location.origin);
        </script><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1575761-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<style type="text/css" id="syntaxhighlighteranchor"></style>
</head>

<body class="single single-post postid-18 single-format-standard custom-font-enabled single-author">
<div id="page" class="hfeed site">
	<header id="masthead" class="site-header" role="banner">
		<hgroup>
			<h1 class="site-title"><a href="http://discoveringdotnet.alexeyev.org/" title="Discovering .NET" rel="home">Discovering .NET</a></h1>
			<h2 class="site-description">Problems I have seen in my .NET development</h2>
		</hgroup>

		<nav id="site-navigation" class="main-navigation" role="navigation">
			<button class="menu-toggle">Menu</button>
			<a class="assistive-text" href="#content" title="Skip to content">Skip to content</a>
			<div class="nav-menu"><ul><li ><a href="http://discoveringdotnet.alexeyev.org/">Home</a></li><li class="page_item page-item-2"><a href="http://discoveringdotnet.alexeyev.org/about">About me</a></li></ul></div>
		</nav><!-- #site-navigation -->

			</header><!-- #masthead -->

	<div id="main" class="wrapper">
	<div id="primary" class="site-content">
		<div id="content" role="main">

			
				
	<article id="post-18" class="post-18 post type-post status-publish format-standard hentry category-wpf">
				<header class="entry-header">
			
						<h1 class="entry-title">Default focus in XAML</h1>
										<div class="comments-link">
					<a href="http://discoveringdotnet.alexeyev.org/2011/01/default-focus-in-xaml.html#respond"><span class="leave-reply">Leave a reply</span></a>				</div><!-- .comments-link -->
					</header><!-- .entry-header -->

				<div class="entry-content">
			<p>Very simple task, you open window and you want some text box to have focus. And since it&#8217;s common and simple task I thought it should be possible using XAML. To do this, you should use FocusManager. However, you should pay attention where you put it. I had to use it right in the Grid where I placed my TextBox. Which is logical, if you think about it. How else TextBox can be found.</p>
<p>Here is the xaml:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ -->
<pre><br /><span><</span><span>UserControl</span> <span>x:Class</span><span>="Actsoft.CometTracker.Layouts.AddViewView"</span><br /><span>xmlns</span><span>="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><br /><span>xmlns:x</span><span>="http://schemas.microsoft.com/winfx/2006/xaml"</span><br /><span>xmlns:mc</span><span>="http://schemas.openxmlformats.org/markup-compatibility/2006"</span> <br /><span>xmlns:d</span><span>="http://schemas.microsoft.com/expression/blend/2008"</span> <br /><span>mc:Ignorable</span><span>="d"</span> <br /><span>d:DesignHeight</span><span>="40"</span> <span>d:DesignWidth</span><span>="300"</span><br /><span>></span><br /><span><</span><span>Grid</span><br /><span>FocusManager</span>.<span>FocusedElement</span><span>="{Binding ElementName=textBox}"</span><span>></span><br /><span><</span><span>Grid.ColumnDefinitions</span><span>></span><br /><span><</span><span>ColumnDefinition</span> <span>Width</span><span>="Auto"</span><span>/></span><br /><span><</span><span>ColumnDefinition</span><span>/></span><br /><span></</span><span>Grid.ColumnDefinitions</span><span>></span><br /><span><</span><span>Label</span> <br /><span>Margin</span><span>="4"</span><span>></span>View Name:<span></</span><span>Label</span><span>></span><br /><span><</span><span>TextBox</span> <span>Grid</span>.<span>Column</span><span>="1"</span> <span>x:Name</span><span>="textBox"</span><br /><span>Margin</span><span>="4"</span> <span>Text</span><span>="{Binding Path=ViewName}"</span><span>/></span><br /><span></</span><span>Grid</span><span>></span><br /><span></</span><span>UserControl</span><span>></span><br /></pre>
					</div><!-- .entry-content -->
		
		<footer class="entry-meta">
			This entry was posted in <a href="http://discoveringdotnet.alexeyev.org/category/wpf" rel="category tag">WPF</a> on <a href="http://discoveringdotnet.alexeyev.org/2011/01/default-focus-in-xaml.html" title="9:59 pm" rel="bookmark"><time class="entry-date" datetime="2011-01-21T21:59:00+00:00">January 21, 2011</time></a><span class="by-author"> by <span class="author vcard"><a class="url fn n" href="http://discoveringdotnet.alexeyev.org/author/maxal" title="View all posts by maxal" rel="author">maxal</a></span></span>.								</footer><!-- .entry-meta -->
	</article><!-- #post -->

				<nav class="nav-single">
					<h3 class="assistive-text">Post navigation</h3>
					<span class="nav-previous"><a href="http://discoveringdotnet.alexeyev.org/2011/01/working-with-tfs-process-templates.html" rel="prev"><span class="meta-nav">&larr;</span> Working with TFS process templates</a></span>
					<span class="nav-next"><a href="http://discoveringdotnet.alexeyev.org/2011/02/power-of-datatemplatedatatype-property.html" rel="next">The power of DataTemplate.DataType property <span class="meta-nav">&rarr;</span></a></span>
				</nav><!-- .nav-single -->

				
<div id="comments" class="comments-area">

	
	
							<div id="respond" class="comment-respond">
				<h3 id="reply-title" class="comment-reply-title">Leave a Reply <small><a rel="nofollow" id="cancel-comment-reply-link" href="/2011/01/default-focus-in-xaml.html#respond" style="display:none;">Cancel reply</a></small></h3>
									<form action="http://discoveringdotnet.alexeyev.org/wp-comments-post.php" method="post" id="commentform" class="comment-form">
																			<p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p>							<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" aria-required='true' required='required' /></p>
<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="text" value="" size="30" aria-describedby="email-notes" aria-required='true' required='required' /></p>
<p class="comment-form-url"><label for="url">Website</label> <input id="url" name="url" type="text" value="" size="30" /></p>
												<p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true" required="required"></textarea></p>						<p class="form-allowed-tags" id="form-allowed-tags">You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:  <code>&lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;cite&gt; &lt;code&gt; &lt;del datetime=&quot;&quot;&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=&quot;&quot;&gt; &lt;s&gt; &lt;strike&gt; &lt;strong&gt; </code></p>
						<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment" /> <input type='hidden' name='comment_post_ID' value='18' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</p><p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="91a796d2a7" /></p><p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="113"/></p>					</form>
							</div><!-- #respond -->
			
</div><!-- #comments .comments-area -->
			
		</div><!-- #content -->
	</div><!-- #primary -->


			<div id="secondary" class="widget-area" role="complementary">
			<aside id="search-2" class="widget widget_search"><form role="search" method="get" id="searchform" class="searchform" action="http://discoveringdotnet.alexeyev.org/">
				<div>
					<label class="screen-reader-text" for="s">Search for:</label>
					<input type="text" value="" name="s" id="s" />
					<input type="submit" id="searchsubmit" value="Search" />
				</div>
			</form></aside>		<aside id="recent-posts-2" class="widget widget_recent_entries">		<h3 class="widget-title">Recent Posts</h3>		<ul>
					<li>
				<a href="http://discoveringdotnet.alexeyev.org/2014/08/simple-explanation-of-bearer-authentication-for-web-api-2.html">Simple explanation of bearer authentication for Web Api 2</a>
						</li>
					<li>
				<a href="http://discoveringdotnet.alexeyev.org/2014/07/registration-for-azure-notification-hub.html">Registration for Azure Notification Hub</a>
						</li>
					<li>
				<a href="http://discoveringdotnet.alexeyev.org/2014/06/application-settings-in-azure-roles.html">Application settings in Azure roles</a>
						</li>
					<li>
				<a href="http://discoveringdotnet.alexeyev.org/2014/05/latin-local-was-not-supported-by-windows-server-2012.html">Latin local was not supported by Windows Server 2012</a>
						</li>
					<li>
				<a href="http://discoveringdotnet.alexeyev.org/2014/05/logging-in-azure-part-2-trace-in-azure-roles.html">Logging in Azure (Part 2 &#8211; Trace in Azure roles)</a>
						</li>
				</ul>
		</aside><aside id="recent-comments-2" class="widget widget_recent_comments"><h3 class="widget-title">Recent Comments</h3><ul id="recentcomments"><li class="recentcomments"><span class="comment-author-link">maxal</span> on <a href="http://discoveringdotnet.alexeyev.org/2014/08/simple-explanation-of-bearer-authentication-for-web-api-2.html#comment-182681">Simple explanation of bearer authentication for Web Api 2</a></li><li class="recentcomments"><span class="comment-author-link">maxal</span> on <a href="http://discoveringdotnet.alexeyev.org/2014/08/simple-explanation-of-bearer-authentication-for-web-api-2.html#comment-182661">Simple explanation of bearer authentication for Web Api 2</a></li><li class="recentcomments"><span class="comment-author-link">Adi</span> on <a href="http://discoveringdotnet.alexeyev.org/2014/08/simple-explanation-of-bearer-authentication-for-web-api-2.html#comment-177191">Simple explanation of bearer authentication for Web Api 2</a></li><li class="recentcomments"><span class="comment-author-link">Thiago Silva</span> on <a href="http://discoveringdotnet.alexeyev.org/2014/08/simple-explanation-of-bearer-authentication-for-web-api-2.html#comment-147161">Simple explanation of bearer authentication for Web Api 2</a></li></ul></aside><aside id="categories-2" class="widget widget_categories"><h3 class="widget-title">Categories</h3>		<ul>
	<li class="cat-item cat-item-11"><a href="http://discoveringdotnet.alexeyev.org/category/architecture" >Architecture</a>
</li>
	<li class="cat-item cat-item-91"><a href="http://discoveringdotnet.alexeyev.org/category/azure" >Azure</a>
</li>
	<li class="cat-item cat-item-21"><a href="http://discoveringdotnet.alexeyev.org/category/book" >book</a>
</li>
	<li class="cat-item cat-item-31"><a href="http://discoveringdotnet.alexeyev.org/category/sql" >SQL</a>
</li>
	<li class="cat-item cat-item-41"><a href="http://discoveringdotnet.alexeyev.org/category/tfs" >TFS</a>
</li>
	<li class="cat-item cat-item-1"><a href="http://discoveringdotnet.alexeyev.org/category/uncategorized" >Uncategorized</a>
</li>
	<li class="cat-item cat-item-51"><a href="http://discoveringdotnet.alexeyev.org/category/wcf" >WCF</a>
</li>
	<li class="cat-item cat-item-61"><a href="http://discoveringdotnet.alexeyev.org/category/winforms" >WinForms</a>
</li>
	<li class="cat-item cat-item-71"><a href="http://discoveringdotnet.alexeyev.org/category/wpf" >WPF</a>
</li>
		</ul>
</aside><aside id="meta-2" class="widget widget_meta"><h3 class="widget-title">Meta</h3>			<ul>
						<li><a href="http://discoveringdotnet.alexeyev.org/wp-login.php">Log in</a></li>
			<li><a href="http://discoveringdotnet.alexeyev.org/feed">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li>
			<li><a href="http://discoveringdotnet.alexeyev.org/comments/feed">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li>
<li><a href="https://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress.org</a></li>			</ul>
</aside><aside id="archives-2" class="widget widget_archive"><h3 class="widget-title">Archives</h3>		<ul>
	<li><a href='http://discoveringdotnet.alexeyev.org/2014/08'>August 2014</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2014/07'>July 2014</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2014/06'>June 2014</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2014/05'>May 2014</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2014/04'>April 2014</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2013/10'>October 2013</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2013/08'>August 2013</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2011/11'>November 2011</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2011/05'>May 2011</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2011/03'>March 2011</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2011/02'>February 2011</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2011/01'>January 2011</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2010/11'>November 2010</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2010/08'>August 2010</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2010/06'>June 2010</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2010/04'>April 2010</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2010/02'>February 2010</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/11'>November 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/06'>June 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/05'>May 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/04'>April 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/03'>March 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/02'>February 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2009/01'>January 2009</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/12'>December 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/10'>October 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/09'>September 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/08'>August 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/05'>May 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/04'>April 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/03'>March 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/02'>February 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2008/01'>January 2008</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2007/12'>December 2007</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2007/10'>October 2007</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2007/09'>September 2007</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2007/08'>August 2007</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2006/09'>September 2006</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2006/01'>January 2006</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2005/07'>July 2005</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2005/06'>June 2005</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2005/03'>March 2005</a></li>
	<li><a href='http://discoveringdotnet.alexeyev.org/2005/02'>February 2005</a></li>
		</ul>
</aside>		</div><!-- #secondary -->
		</div><!-- #main .wrapper -->
	<footer id="colophon" role="contentinfo">
		<div class="site-info">
						<a href="http://wordpress.org/" title="Semantic Personal Publishing Platform">Proudly powered by WordPress</a>
		</div><!-- .site-info -->
	</footer><!-- #colophon -->
</div><!-- #page -->

<script type='text/javascript' src='http://discoveringdotnet.alexeyev.org/wp-content/plugins/akismet/_inc/form.js?ver=3.1.5'></script>
<script type='text/javascript' src='http://discoveringdotnet.alexeyev.org/wp-includes/js/comment-reply.min.js?ver=4.2.12'></script>
<script type='text/javascript' src='http://discoveringdotnet.alexeyev.org/wp-content/themes/twentytwelve/js/navigation.js?ver=20140711'></script>
</body>
</html>