<?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>Eclipsed4utoo&#039;s Blog&#187; modal dialog</title>
	<atom:link href="http://eclipsed4utoo.com/blog/tag/modal-dialog/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsed4utoo.com/blog</link>
	<description>Not Your Ordinary Programmer</description>
	<lastBuildDate>Thu, 08 Sep 2011 17:09:19 +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>Silverlight 4 &#8211; Creating a Custom Modal Dialog</title>
		<link>http://eclipsed4utoo.com/blog/silverlight-4-creating-custom-modal-dialog/</link>
		<comments>http://eclipsed4utoo.com/blog/silverlight-4-creating-custom-modal-dialog/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 06:30:26 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[blend]]></category>
		<category><![CDATA[modal dialog]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=380</guid>
		<description><![CDATA[For a Silverlight application I did recently, I wanted to do a custom modal dialog box for showing informational messages, error messages, or other messages to the user.  This dialog box would have no title bar or &#8220;X&#8221; button, and would have rounded corners. For this tutorial, we will use Blend 4 to accomplish our [...]]]></description>
			<content:encoded><![CDATA[<p>For a Silverlight application I did recently, I wanted to do a custom modal dialog box for showing informational messages, error messages, or other messages to the user.  This dialog box would have no title bar or &#8220;X&#8221; button, and would have rounded corners.</p>
<p>For this tutorial, we will use Blend 4 to accomplish our task.</p>
<p>First, create a new Silverlight 4 application.  I named mine <strong>CustomDialog</strong>.</p>
<p><img class="alignnone size-full wp-image-381" title="Image1" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image1.png" alt="Image1" width="548" height="468" /></p>
<p>Once the project has been created, we are going to add a new item to our Silverlight project.  This item will be a <strong>ChildWindow</strong>.  I named mine <strong>DialogPopup</strong>.</p>
<p><img class="alignnone size-full wp-image-382" title="Image2" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image2.png" alt="Image2" width="390" height="427" /></p>
<p>The <strong>ChildWindow </strong>will handle the modal dialog part of our window.  However, there are parts of the <strong>ChildWindow </strong>that I didn&#8217;t like and wanted to remove/change, such as the window chrome.  I also wanted to round the corners of the window.   To do this, we need to edit the template for the window.  In the <strong>Objects and Timeline</strong> window, right-click on the <strong>ChildWindow </strong>parent &#8211;&gt; <strong>Edit Template</strong> &#8211;&gt; <strong>Edit a Copy</strong>&#8230;</p>
<p><img class="alignnone size-full wp-image-383" title="Image3" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image3.png" alt="Image3" width="457" height="495" /></p>
<p>We are going to keep it simple and save the new style to the ChildWindow document.</p>
<p><img class="alignnone size-full wp-image-384" title="Image4" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image4.png" alt="Image4" width="459" height="249" /></p>
<p>So first, we are just going to delete the window chrome from the window.  The window chrome is the title bar and the &#8220;X&#8221; used to close the window.  Drill-down in the treeview until you find the <strong>Chrome </strong>entry.  Right-click, and choose <strong>Delete</strong>.</p>
<p><img class="alignnone size-full wp-image-385" title="Image5" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image5.png" alt="Image5" width="437" height="391" /></p>
<p>Next, we need to delete some of the Borders.  These give the window a grey border that I didn&#8217;t want.</p>
<p><img class="alignnone size-full wp-image-402" title="Image11" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image11.png" alt="Image11" width="431" height="373" /></p>
<p>Next, we are going to round the corners of the window.  Drill-down and click on the <strong>Border </strong>shown below.</p>
<p><img class="alignnone size-full wp-image-405" title="Image12" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image12.png" alt="Image12" width="290" height="244" /></p>
<p>In the <strong>Properties </strong>window, set the <strong>CornerRadius </strong>to <strong>20</strong>.</p>
<p><img class="alignnone size-full wp-image-387" title="Image7" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image7.png" alt="Image7" width="275" height="192" /></p>
<p>Move down to the next <strong>Border</strong>,</p>
<p><img class="alignnone size-full wp-image-406" title="Image13" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image13.png" alt="Image13" width="302" height="249" /></p>
<p>And set it&#8217;s <strong>CornerRadius </strong>to <strong>20</strong>.</p>
<p><img class="alignnone size-full wp-image-389" title="Image9" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image9.png" alt="Image9" width="271" height="177" /></p>
<p>With the same <strong>Border </strong>selected, in the Properties window, set the <strong>Background Brush</strong> to a color of your choice.</p>
<p><img class="alignnone size-full wp-image-390" title="Image10" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image10.png" alt="Image10" width="270" height="391" /></p>
<p>The window &#8220;jazz&#8221; is now complete.  Next, we are going to move to the XAML.</p>
<p>First, we need to give our window a name so we can handle binding.  I named mine <strong>myCustomPopup</strong>.</p>
<pre class="brush: xml;">
&lt;sdk:ChildWindow
   xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
   xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
   xmlns:sdk=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk&quot;
   x:Class=&quot;CustomDialog.DialogPopup&quot;
   x:Name=&quot;myCustomPopup&quot;
   Title=&quot;DialogPopup&quot;
   Width=&quot;400&quot; Height=&quot;300&quot;&gt;
</pre>
<p>Now we need to add a <strong>TextBlock </strong>to the window to hold our message.</p>
<pre class="brush: xml;">
&lt;TextBlock
    Text=&quot;{Binding Message, ElementName=myCustomPopup}&quot;
    Margin=&quot;51,88,57,113&quot;
    TextWrapping=&quot;Wrap&quot;
    Foreground=&quot;#FF1D1515&quot;
    FontWeight=&quot;Bold&quot;
    TextAlignment=&quot;Center&quot;/&gt;
</pre>
<p>You may notice that we are binding to a property called <strong>Message</strong>.  This is a custom <strong>DependencyProperty </strong>that will correspond to a public property that we will set when we create an instance of the window.</p>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// Creates a public property for the TextBlock to bind to
/// &lt;/summary&gt;
public static DependencyProperty MessageProperty = DependencyProperty.Register(&quot;Message&quot;, typeof(string), typeof(DialogPopup), new PropertyMetadata(&quot;&quot;));
public string Message
{
     get { return (string)GetValue(MessageProperty); }
     set { SetValue(MessageProperty, value); }
}
</pre>
<p>This will complete our work for the window.  To show off the new window, lets add a <strong>Button </strong>to the <strong>MainPage.xaml</strong>, create an <strong>EventHandler </strong>for the <strong>Click </strong>event.</p>
<pre class="brush: xml;">
&lt;Grid
   x:Name=&quot;LayoutRoot&quot;
   Background=&quot;White&quot;&gt;

     &lt;Button
        x:Name=&quot;btnShowMessage&quot;
        Content=&quot;Click Me&quot;
        Click=&quot;btnShowMessage_Click&quot;
        Margin=&quot;251,207,289,236&quot;  /&gt;
&lt;/Grid&gt;
</pre>
<p>And the code for the <strong>Click </strong>event&#8230;</p>
<pre class="brush: csharp;">
private void btnShowMessage_Click(object sender, System.Windows.RoutedEventArgs e)
{
     DialogPopup dialog = new DialogPopup();
     dialog.Message = &quot;Our message&quot;;
     dialog.Show();
}
</pre>
<p>And that will complete our tutorial.  Run the application from Blend using <strong>F5</strong>, and you should see this..</p>
<p><img class="alignnone size-full wp-image-408" title="Image14" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2010/07/Image14.png" alt="Image14" width="489" height="364" /></p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/silverlight-4-creating-custom-modal-dialog/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

