<?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>Dan Rigsby - Coding Up Style &#187; WPF</title>
	<atom:link href="http://www.danrigsby.com/blog/index.php/category/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danrigsby.com/blog</link>
	<description>Developer.Speaker.Blogger</description>
	<lastBuildDate>Tue, 17 Nov 2009 18:29:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Remove Icon from WPF Window</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/05/26/remove-icon-from-wpf-window/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/05/26/remove-icon-from-wpf-window/#comments</comments>
		<pubDate>Mon, 26 May 2008 17:07:55 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[Common Libraries]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/05/26/remove-icon-from-wpf-window/</guid>
		<description><![CDATA[In general, a window should always have an icon because it helps give context to the window.&#160; However, there are occasions when you may want a window with icon such as a custom tool window or some other dialog. In Windows Forms if you want a window without an icon, you could just simply set:
&#160;

this.ShowIcon [...]]]></description>
			<content:encoded><![CDATA[<div>In general, a window should always have an icon because it helps give context to the window.&#160; However, there are occasions when you may want a window with icon such as a custom tool window or some other dialog. In Windows Forms if you want a window without an icon, you could just simply set:</div>
<div>&#160;</div>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">this</span>.ShowIcon = <span style="color: #0000ff">false;</span></pre>
</div>
<div>&#160;</div>
<div>In WPF, there is no simple way to just remove the icon.&#160; If you try to just set the Icon to null, it will display the default windows icon.&#160; The only way to disable the icon is to use some interop code to remove the icon directly through the windows API:</div>
<div>&#160;</div>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Windows;
<span style="color: #0000ff">using</span> System.Windows.Interop;
<span style="color: #0000ff">using</span> System.Runtime.InteropServices;

<span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> WindowWithoutIcon : Window
{
    [DllImport(<span style="color: #006080">&quot;user32.dll&quot;</span>)]
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">int</span> GetWindowLong(IntPtr hwnd, <span style="color: #0000ff">int</span> index);

    [DllImport(<span style="color: #006080">&quot;user32.dll&quot;</span>)]
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">int</span> SetWindowLong(IntPtr hwnd, <span style="color: #0000ff">int</span> index, <span style="color: #0000ff">int</span> newStyle);

    [DllImport(<span style="color: #006080">&quot;user32.dll&quot;</span>)]
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">bool</span> SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, <span style="color: #0000ff">int</span> x, <span style="color: #0000ff">int</span> y, <span style="color: #0000ff">int</span> width, <span style="color: #0000ff">int</span> height, <span style="color: #0000ff">uint</span> flags);

    [DllImport(<span style="color: #006080">&quot;user32.dll&quot;</span>)]
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> IntPtr SendMessage(IntPtr hwnd, <span style="color: #0000ff">uint</span> msg, IntPtr wParam, IntPtr lParam);

    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> GWL_EXSTYLE = -20;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> WS_EX_DLGMODALFRAME = 0x0001;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> SWP_NOSIZE = 0x0001;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> SWP_NOMOVE = 0x0002;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> SWP_NOZORDER = 0x0004;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> SWP_FRAMECHANGED = 0x0020;
    <span style="color: #0000ff">const</span> <span style="color: #0000ff">uint</span> WM_SETICON = 0x0080;

    <span style="color: #0000ff">public</span> MainWindow()
    {
        InitializeComponent();
    }

    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnSourceInitialized(EventArgs e)
    {
        <span style="color: #0000ff">base</span>.OnSourceInitialized(e);

        <span style="color: #008000">// Get this window's handle</span>
        IntPtr hwnd = <span style="color: #0000ff">new</span> WindowInteropHelper(<span style="color: #0000ff">this</span>).Handle;

        <span style="color: #008000">// Change the extended window style to not show a window icon</span>
        <span style="color: #0000ff">int</span> extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);

        <span style="color: #008000">// Update the window's non-client area to reflect the changes</span>
        SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
    }
}</pre>
</div>
<div>&#160;</div>
<div><em>Source derived from: </em><a title="http://blogs.msdn.com/wpfsdk/archive/2007/08/02/a-wpf-window-without-an-window-icon-the-thing-you-click-to-get-the-system-menu.aspx" href="http://blogs.msdn.com/wpfsdk/archive/2007/08/02/a-wpf-window-without-an-window-icon-the-thing-you-click-to-get-the-system-menu.aspx"><em>http://blogs.msdn.com/wpfsdk/archive/2007/08/02/a-wpf-window-without-an-window-icon-the-thing-you-click-to-get-the-system-menu.aspx</em></a></div>
<div>&#160;</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/05/26/remove-icon-from-wpf-window/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Margins and Padding in WPF</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/05/20/margins-and-padding-in-wpf/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/05/20/margins-and-padding-in-wpf/#comments</comments>
		<pubDate>Tue, 20 May 2008 17:40:13 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/05/20/margins-and-padding-in-wpf/</guid>
		<description><![CDATA[Margins and padding WPF work much like margins and padding other paradigms such as windows forms or CSS.&#160; Margins give you space outside of the control, and padding gives you space inside the control.&#160; The amount of spacing is set by the number of pixels you want to represent.
 
Note: The padding always occurs inside [...]]]></description>
			<content:encoded><![CDATA[<p>Margins and padding WPF work much like margins and padding other paradigms such as windows forms or CSS.&nbsp; Margins give you space outside of the control, and padding gives you space inside the control.&nbsp; The amount of spacing is set by the number of pixels you want to represent.</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/05/boxdim.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="207" alt="boxdim" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/05/boxdim-thumb.png" width="374" border="0"></a> </p>
<p><em>Note: The padding always occurs inside the border. So if you have a border of 2 and padding of 10, the actual content of the control will be 12 pixels in.</em></p>
<p>In WPF, when you represent the spacing for these, you can set the values in line.&nbsp; For instance, if you want to place a 2 pixel margin around a control you could write it as Margin=&#8221;2&#8243;, Margin=&#8221;2, 2, 2, 2&#8243;, or Margin=&#8221;2 2 2 2&#8243;.&nbsp; This is very similar to CSS, but there is a big difference.&nbsp; In CSS, the values represent &#8220;Top, Right, Bottom, Left&#8221;, but in WPF, the values represent&#8221;Left, Top, Right, Bottom&#8221;.&nbsp; Why did WPF break the mold on this one?&nbsp;&nbsp; Even if the order made more sense (which it doesn&#8217;t), I still can&#8217;t agree with this change.&nbsp; CSS is a standard and has set a precedence.&nbsp; Designers and developers who are using WPF have probably worked with CSS in some context.&nbsp; This is going to throw a lot of people off.&nbsp; Especially if the are going back and forth between CSS and WPF. What about developers who are writing silverlight controls as well as the web pages that contains them?</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="137" alt="Clock" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/05/clock.jpg" width="136" align="right" border="0">The CSS format makes sense. What time is represented by the clock to the right?&nbsp; With no numbers visible, your eyes will probably start at the top (in the 12 position) and move around in clockwise motion to interpret each number.&nbsp; Our minds have been trained to look at the top and work around clockwise.&nbsp; There are exceptions to this, but it is a pattern that makes sense, and one that the CSS guys though was important enough to use in the order of sides.&nbsp; </p>
<p>Its too late to change WPF now, but I would really like to know what the rational behind this was.&nbsp; Maybe they chose to start with the Left side because we read Right to Left in most Western cultures.&nbsp; However, many cultures read Right to Left or Top to Bottom or some other format.&nbsp; It&#8217;s not a reliable paradigm to be based on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/05/20/margins-and-padding-in-wpf/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

