<?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>FormatException &#187; WPF</title>
	<atom:link href="http://www.formatexception.com/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.formatexception.com</link>
	<description>Ramblings on developing in the Windows World</description>
	<lastBuildDate>Fri, 23 Sep 2011 15:34:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WP7, ApplicationBar, ImageUri and the Icon not showing up</title>
		<link>http://www.formatexception.com/2010/11/wp7-applicationbar-imageuri-and-the-icon-not-showing-up/</link>
		<comments>http://www.formatexception.com/2010/11/wp7-applicationbar-imageuri-and-the-icon-not-showing-up/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 17:25:06 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[WP7]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=286</guid>
		<description><![CDATA[I know this may sound stupid but when working with the WP7 ApplicationBar make sure the images you are using have the following properties: Build Action: Content Copy to Output: Copy always (or &#8216;Copy if newer&#8217;, either should work) I spent a half an hour trying to figure out why my application bar was showing [...]]]></description>
			<content:encoded><![CDATA[<p>I know this may sound stupid but when working with the WP7 ApplicationBar make sure the images you are using have the following properties:</p>
<blockquote><p><a href="http://www.formatexception.com/wp-content/uploads/2010/11/Build_Action.png"><img src="http://www.formatexception.com/wp-content/uploads/2010/11/Build_Action-300x182.png" alt="Build Action: Content" title="Build_Action" width="300" height="182" class="alignnone size-medium wp-image-311" /></a><br/>Build Action: Content<br />
Copy to Output: Copy always (or &#8216;Copy if newer&#8217;, either should work)</p></blockquote>
<p>I spent a half an hour trying to figure out why my application bar was showing an &#8220;X&#8221; instead of the image I was putting in IconUri.  When first adding images the properties default to:</p>
<blockquote><p>Build Action: Resource<br />
Copy to Output: Do not copy</p></blockquote>
<p>Since the application bar is referencing the image by Uri it can&#8217;t seem to find it embedded in the application.</p>
<p>My xaml looks like:</p>
<pre name="code" class="xml">&lt;phone:PhoneApplicationPage.ApplicationBar&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;shell:ApplicationBarIconButton
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IconUri="/Images/appbar.feature.settings.rest.png"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text="Settings"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/shell:ApplicationBar&gt;
&lt;/phone:PhoneApplicationPage.ApplicationBar&gt;</pre>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F11%2Fwp7-applicationbar-imageuri-and-the-icon-not-showing-up%2F&amp;t=WP7%2C%20ApplicationBar%2C%20ImageUri%20and%20the%20Icon%20not%20showing%20up" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F11%2Fwp7-applicationbar-imageuri-and-the-icon-not-showing-up%2F&amp;t=WP7%2C%20ApplicationBar%2C%20ImageUri%20and%20the%20Icon%20not%20showing%20up" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2010/11/wp7-applicationbar-imageuri-and-the-icon-not-showing-up/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WPF &#8211; ContentProperty, it&#8217;s that simple</title>
		<link>http://www.formatexception.com/2008/09/wpf-contentproperty-its-that-simple/</link>
		<comments>http://www.formatexception.com/2008/09/wpf-contentproperty-its-that-simple/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 15:06:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=32</guid>
		<description><![CDATA[So there I am, creating a custom control called &#8220;RequiredLabel&#8221; that interestingly enough is a label that has a cool icon in it to show that whatever it is being used for is required. The control has two properties, Text that is the text of the label and Style that is the style of the [...]]]></description>
			<content:encoded><![CDATA[<p>So there I am, creating a custom control called &#8220;RequiredLabel&#8221; that<br />
interestingly enough is a label that has a cool icon in it to show that<br />
whatever it is being used for is required. The control has two<br />
properties, Text that is the text of the label and Style that is the<br />
style of the label. Both are registered as dependency properties so<br />
that they can be set in the xaml. I suppose it would have been fine to<br />
simply leave good enough as good enough but I wanted it so that in the<br />
xaml you can put the text for the label between the start and end tag<br />
for required label. It is simply expected behavior the the content of<br />
your control can be put in that way.</p>
<p>After much soul searching (i.e. Googling) I still couldn&#8217;t find the<br />
answer. How do I make one of my dependency properties the content that<br />
is between the tags? Well, thankfully I had an epiphany and remembered<br />
that somewhere deep in one of my WPF books the answer was held. It is<br />
as simple as putting the attribute above the class declaration with the<br />
dependency property name.</p>
<p>[ContentProperty("Text")]<br />
public partial class RequiredLabel : UserControl<br />
{</p>
<p>This makes it so that when I use my custom control it will look like:</p>
<p>&lt;customControls:RequiredLabel x:Name=&#8221;lblType&#8221; Style=&#8221;{StaticResource<br />
LabelGradient}&#8221;&gt;<br />
                            Defendant&#8217;s Name:<br />
 &lt;/customControls:RequiredLabel&gt;</p>
<p>It also makes it so that if I decide to extend the content to support<br />
user controls instead of just text really easy since I can switch out<br />
the TextBlock that makes up the user control to a panel.</p>
<p>Also if you want to get a glimmer of using dependency properties see<br />
attached code.</p>
<p><a href="http://www.formatexception.com/post_attachments/contentproperty/RequiredLabel.xaml">RequiredLabel.xaml</a><br />
<a href="http://www.formatexception.com/post_attachments/contentproperty/RequiredLabel.xaml.cs">RequiredLabel.xaml.cs</a></p>
<p>Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-contentproperty-its-that-simple%2F&amp;t=WPF%20-%20ContentProperty%2C%20it%27s%20that%20simple" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-contentproperty-its-that-simple%2F&amp;t=WPF%20-%20ContentProperty%2C%20it%27s%20that%20simple" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2008/09/wpf-contentproperty-its-that-simple/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WPF and Silverlight</title>
		<link>http://www.formatexception.com/2008/09/wpf-and-silverlight/</link>
		<comments>http://www.formatexception.com/2008/09/wpf-and-silverlight/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 15:00:07 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=30</guid>
		<description><![CDATA[ Check out the link below.  It is a bunch of tutorials on everything you could want to know about Silverlight plus a whole bunch of cool WPF stuff. http://channel9.msdn.com/posts/Dan/Mike-Taulty-44-Silverlight-20-Screencasts/ Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><!--StartFragment --> Check out the link below.  It is a bunch of tutorials on everything you could want to know about Silverlight plus a whole bunch of cool WPF stuff.</p>
<p><a class="moz-txt-link-freetext" href="http://channel9.msdn.com/posts/Dan/Mike-Taulty-44-Silverlight-20-Screencasts/">http://channel9.msdn.com/posts/Dan/Mike-Taulty-44-Silverlight-20-Screencasts/</a></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-and-silverlight%2F&amp;t=WPF%20and%20Silverlight" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-and-silverlight%2F&amp;t=WPF%20and%20Silverlight" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2008/09/wpf-and-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF and MousePosition</title>
		<link>http://www.formatexception.com/2008/09/wpf-and-mouseposition/</link>
		<comments>http://www.formatexception.com/2008/09/wpf-and-mouseposition/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 14:57:55 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=27</guid>
		<description><![CDATA[The way I thought it should be done (but it&#8217;s wrong): Point mousePoint = Mouse.GetPosition(this); MyWindow win = new MyWindow(); win.Left = mousePoint.X; win.Top = mousePoint.Y; win.ShowDialog(); &#8220;Mama Freeda! Dang window won&#8217;t go where I put it!&#8221; Okay, maybe I didn&#8217;t say &#8220;Mama Freeda&#8221; nor &#8220;Dang&#8221; but none the less it seems like when getting [...]]]></description>
			<content:encoded><![CDATA[<p>The way I thought it should be done (but it&#8217;s wrong):</p>
<pre name="code" class="csharp">Point mousePoint = Mouse.GetPosition(this);
MyWindow win = new MyWindow();
win.Left = mousePoint.X;
win.Top = mousePoint.Y;
win.ShowDialog();</pre>
<p>&#8220;Mama Freeda! Dang window won&#8217;t go where I put it!&#8221;</p>
<p>Okay, maybe I didn&#8217;t say &#8220;Mama Freeda&#8221; nor &#8220;Dang&#8221; but none the less it<br />
seems like when getting a mouse position in WPF and trying to open a new<br />
window relative to the mouse click is a pain.</p>
<p>Ah Luigi, but I have the solution <img src='http://www.formatexception.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>When setting the left and top properties in a wpf window they relate to<br />
the desktop coordinates. The new window could careless that it&#8217;s being<br />
popped up from a control underneath it.</p>
<p>The problem is that Mouse.GetPosition(this) returns the position<br />
relative to the &#8220;this&#8221; which is most likely the control that is trying<br />
to open the new window. Now if the control is the only control in the<br />
window, there is only one screen, the application is running on the<br />
primary screen and the application is maximized then your golden.</p>
<p>But screw that.</p>
<p>Well, how about using Mouse.GetPosition(Window.GetWindow(this))?</p>
<p>That returns the point relative to the window of the control (this).<br />
That should work won&#8217;t it? That only eliminates a single concern of<br />
ours, if the control is the only control in the window. There is still<br />
that the application must be only one screen, the application is running<br />
on the primary screen and the application must be maximized.</p>
<p>Brian, cut the Brother Stuart and just give us the simple answer!</p>
<p>Um, who&#8217;s Brother Stuart?</p>
<p>And why am I talking to myself like this?</p>
<p>The great thing about wpf controls is that they have the ability given a<br />
point to convert that point to screen (i.e. desktop) coordinates.</p>
<p>So here is easy answer (The way it should be done):</p>
<pre name="code" class="csharp">Point mousePoint = this.PointToScreen(Mouse.GetPosition(this));
MyWindow win = new MyWindow();
win.Left = mousePoint.X;
win.Top = mousePoint.Y;
win.ShowDialog();</pre>
<p>Basically get the mouse position relative to this control and then<br />
convert it out to the desktop coordinates so I can then use it when<br />
setting the left and top properties of a new window. This is great for<br />
pop-up windows that need to be close to a mouse click. The great thing<br />
about this is that since the mouse click position is now relative to the<br />
desktop this works on multi-screen monitors regardless of which monitor<br />
you have the application running on.</p>
<p>Later &#8216;yall,<br />
Brian</p>
<p>ref:<br />
Visual.PointToScreen<br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.visual.pointtoscreen.aspx">http://msdn.microsoft.com/en-us/library/system.windows.media.visual.pointtoscreen.aspx</a><br />
Mouse.GetPosition<br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.getposition.aspx">http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.getposition.aspx</a><br />
Window.Top<br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.window.top.aspx">http://msdn.microsoft.com/en-us/library/system.windows.window.top.aspx</a></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-and-mouseposition%2F&amp;t=WPF%20and%20MousePosition" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fwpf-and-mouseposition%2F&amp;t=WPF%20and%20MousePosition" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2008/09/wpf-and-mouseposition/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

