<?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>MillieSoft Blog &#187; dialog</title>
	<atom:link href="http://blog.milliesoft.co.uk/tag/dialog/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.milliesoft.co.uk</link>
	<description>Blogging about Media Center development</description>
	<lastBuildDate>Mon, 14 Jun 2010 09:16:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Code based dialogs in media center</title>
		<link>http://blog.milliesoft.co.uk/2010/03/code-based-dialogs-in-media-center/</link>
		<comments>http://blog.milliesoft.co.uk/2010/03/code-based-dialogs-in-media-center/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:50:09 +0000</pubDate>
		<dc:creator>Martin Millmore</dc:creator>
				<category><![CDATA[Media Center]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[mcml]]></category>

		<guid isPermaLink="false">http://blog.milliesoft.co.uk/?p=216</guid>
		<description><![CDATA[I&#8217;ve written a few posts on how to implement dialog boxes in media center (Adding a version checker and Simpler popup dialog). They are both great examples of how to trigger a dialog box in mcml. Suppose though you want to do it all from within code, not within mcml. Why would you want to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a few posts on how to implement dialog boxes in media center (<a href="http://blog.milliesoft.co.uk/2009/02/adding-a-version-checker/">Adding a version checker</a> and <a href="http://blog.milliesoft.co.uk/2009/04/simpler-popup-dialog/">Simpler popup dialog</a>). They are both great examples of how to trigger a dialog box in mcml. Suppose though you want to do it all from within code, not within mcml. Why would you want to do that? Well, for one it means not having any AddIn calls in your mcml, and AddIn calls mean you can&#8217;t use the mcml preview tool &#8211; which significantly hampers development. For this example, I&#8217;m going to repeat the <a href="http://blog.milliesoft.co.uk/2009/02/adding-a-version-checker/">Adding a version checker</a> example, but all in code.</p>
<p>So, to trigger a dialog from your code, the first thing you need to do is to build some buttons;</p>
<pre><code>ArrayListDataSet dialogButtons = new ArrayListDataSet();
dialogButtons.Add("Download Now");
dialogButtons.Add("Remind me later");
dialogButtons.Add("Ignore");</code></pre>
<p>This adds 3 buttons to the dialog. Obviously add as many or as few as you like. The next thing you need to do is to add the call to open the dialog;</p>
<pre><code>String dialogText="There is a new version available";
String dialogTitle="New Version";
Microsoft.MediaCenter.Hosting.AddInHost.Current
.MediaCenterEnvironment.Dialog(dialogText</code></pre>
<pre><code>, "dialogTitle, dialogButtons, 30, true, null
, new Microsoft.MediaCenter.DialogClosedCallback(versionCallback));
</code></pre>
<p><code> </code></p>
<p>This will open a dialog as a modal dialog with a timeout of 30 seconds. When it is closed, the method <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">versionCallback <span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">will be called, so now we need to write that method;</span></span></p>
<pre><code>public void versionCallback(Microsoft.MediaCenter.DialogResult result)
{
    if (result.ToString() == "100")
    {
        InstallNewVersion();
    }
    if (result.ToString() == "101")
    {
        RemindLater();
    }
    if (result.ToString() == "102")
    {
        IgnoreNewVersion();
    }
}</code></pre>
<p><code> </code></p>
<p>And obviously fill in the appropriate actions for each method.</p>
<p>Finally, you may want to block this dialog from triggering when you are in the debugger (since it won&#8217;t work), so put an if statement round it to stop it running in debug mode;</p>
<pre><code>#if(!DEBUG)
<span style="color: #808080;">   String dialogText="There is a new version available";
   String dialogTitle="New Version";
   Microsoft.MediaCenter.Hosting.AddInHost.Current
.MediaCenterEnvironment.Dialog(dialogText
  , "dialogTitle, dialogButtons, 30, true, null
  , new Microsoft.MediaCenter.DialogClosedCallback(versionCallback));</span></code></pre>
<pre><code>#endif
</code></pre>
<p><code> </code></p>
<p>And that&#8217;s it &#8211; an mcml dialog operated entirely from your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milliesoft.co.uk/2010/03/code-based-dialogs-in-media-center/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simpler popup dialog</title>
		<link>http://blog.milliesoft.co.uk/2009/04/simpler-popup-dialog/</link>
		<comments>http://blog.milliesoft.co.uk/2009/04/simpler-popup-dialog/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 22:42:31 +0000</pubDate>
		<dc:creator>Martin Millmore</dc:creator>
				<category><![CDATA[Media Center]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[mcml]]></category>

		<guid isPermaLink="false">http://blog.milliesoft.co.uk/?p=105</guid>
		<description><![CDATA[In a previous post on adding a version checker to media center, I gave an example of how to write a popup dialog box for media center. There is also a simpler version of the Dialog if you don&#8217;t need to know anything about the response, e.g. if you are simply showing an information message. [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post on adding a <a href="http://blog.milliesoft.co.uk/2009/02/adding-a-version-checker/">version checker</a> to media center, I gave an example of how to write a popup dialog box for media center. There is also a simpler version of the <a href="http://msdn.microsoft.com/en-us/library/ms814612.aspx" target="_blank">Dialog</a> if you don&#8217;t need to know anything about the response, e.g. if you are simply showing an information message. This simpler version doesn&#8217;t require a callback to be defined, or any complex button definitions. It just needs a title, some text, a button name, a timeout and whether or not it is modal. Here&#8217;s an example;</p>
<pre><code>      &lt;Condition Source="[Preferences.TwitDialog]" SourceValue="true" ConditionOp="ChangedTo"&gt;
        &lt;Actions&gt;
          &lt;Set Target="[Preferences.TwitDialog]" Value="false"/&gt;
          &lt;Invoke Target="[AddInHost.MediaCenterEnvironment.Dialog]"
                  caption="Authorize Twitter"
                  text="Please authorize twitter."
                  buttons="Ok"
                  timeout="15"
                  isModal="true"/&gt;

        &lt;/Actions&gt;
      &lt;/Condition&gt;</code></pre>
<p>The buttons can only be ones from the list described in the <a href="http://msdn.microsoft.com/en-us/library/ms814612.aspx" target="_blank">documentation</a>. A modal window requires either the user or a timeout to close it before any other actions can be done, whereas a modeless window allows the user to continue with other things in the meanwhile.</p>
<p>The dialog is fired in this example by a property which is set in the code to true, and then set back to false when it is read. The condition only fires when the value is set to true in the first place by using the ConditionOp.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milliesoft.co.uk/2009/04/simpler-popup-dialog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
