The Power of the One Line Demo

The Power of the One Line Demo

  • Comments 22

Sometimes the simplest demos can be the best.

Catherine Heller is our team expert on the myriad of new Windows Vista unmanaged APIs, but she also knows how to get people excited about WPF with less than 100 bytes of code. This is what she typed into a blank file:

<InkCanvas Background="Yellow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

Click here to see the results if you've got a Beta 2 or more recent build of WPF. This shows off loose XAML running locally in the browser, along with demonstrating how easy it is to add ink support to your WPF application.

Another one line demo I like to do is this (alright, I confess, I've wrapped it onto multiple lines to make it easier to show on this blog):

<RichTextBox FontFamily="Palatino Linotype" FontSize="72"
             SpellCheck.IsEnabled
="True" Typography.NumeralStyle="OldStyle"
             Typography.HistoricalLigatures
="True" Typography.DiscretionaryLigatures="True"
             xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

Click here to see the results, and try typing a sentence like this: "The affliction started in 1776 and spread. Quickly!" You'll notice cool effects like the swash on the Qu, ct, st and sp pairs, as well as the book-style numerals. If you're particularly eagle-eyed, you might catch the subtle Th ligature that prevents the rightmost descender from the T clashing with the serif of the h, as well as the ffl ligature. If you misspell a word, you'll see the red wiggly line underneath it - evidence that you get spell checking for "free" with WPF.

What's the most impressive WPF demo you can construct in a single line of XAML? Can you improve on these?

  • It's more demo of controls,that feels more like separate application,than control.You can't arbitrary modify behavior of control or it'll be genuine difficult task-that's main drawback of current WPF implementation.Binding/templating is nice but very constrained-look at any serious project at MS itself,imperative code is still ~70% and only ~30% for XAML.That means declarative part is draft/blueprint of "real" app.
    It's opposite to HTML,for example,where JS code plays supporting role for HTML&CSS.For every serious changing in some control's behavior I must go imperative code path-that's OK(in most cases),BUT every control has it's own "closed" API and that's not really nice from learning perspective.I need to investigate each of controls separately in each and every "not standard" case I encounter,and only HOPE I can find some workaround for my situation-that's troublesome.In contrary HTML has well defined BOM of base elements-building blocks,which quantity are minimal.And it seems "by design"-I can really easy inject small portions of code(behavior) in any place(declarative/structure part) I see fit.The more behavior/logic control incorporates more rigid it becomes-that's my feeling.It looks as big "black box" in you application,and binding/templating dosen't help much+both require long journey into internals of control for any successful "non cliche" implementation.In HTML land I know that any non-trivial control has the same building blocks,so I can understand HOW it works and modify behavior by my desire-not resorting to some kind of "Reflector";-)I can say,CSS sometimes  create genuine new controls,but declarative by nature(paradox)-some kind of meta-behavior,and WPF dosen't seems to have something like this-big omission in my eyes.CSS is not only styling to me,if you ask,it's something more,and this "something" makes the game really interesting.

    So,what you think about that?
  • Tim,
        It's cool to see this stuff in one line of code.  The presentation aspects of WPF and ALL that is built in is something that I think people just need to spend more time on discovering.  Thanks for demos that continue to keep people engaged.
  • Charles Petzold seems to have taken this as a personal challenge - check out http://www.charlespetzold.com/blog/2006/08/170855.html
  • It seems Charles Petzold took up the challenge and put some one-liners on his blog: http://www.charlespetzold.com/blog/blog.xml
  • I like this one:

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     Clip="M 100,100 L 100,300 120,300 130,150 140,200 160,200 170,150 170,300 300,300 300,180 240,180 240,120 300,120 300,100 220,100 220,200 280,200 280,280 190,280 190,100 170,100 150,150 120,100"
     Opacity="0.5"  AllowsTransparency="true" WindowStyle="None" Background="Blue"
    />  

    The following one can match your functionality:

    <Frame xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1000" Height="1000" Source="http://www.live.com"/>

    and this one can annoy users:

    <Popup IsOpen="true" StaysOpen="true" Placement="Absolute" HorizontalOffset="0" VerticalOffset="0" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="2000" Height="2000"/>

  • What exactly is your definition of a "single line"? Any XAML file can be placed on one line. Just like most C-style programming languages can have everything placed on a single line. Perhaps you mean to say "single element with no children"?
  • Wow, up to nine entrants already, counting the three from digitalnetbizz and six from Charles Petzold. Some more malicious than others!

    Frank, yes, I think that's a fair interpretation.
  • So why do I always get security exceptions any time that I try to run anyone's demos except for Petzold's? Does he know something that the actual Microsofties don't? Or is it that he is just using an older version of WPF.

    I'm not looking for you to debug my issue but I'm getting a little worried about the fact that I can't view 99% of the WPF stuff out there. Are "normal" users going to experience this or is this just a Beta thing? If it is the former then all these demos don't mean squat.

    I'm on Vista Beta2 and get the following error:

    Startup URI: http://www.sneath.org/tim/rtb.xaml
    Application Identity: file:///C:/Windows/WinFX/v3.0/WPF/XamlViewer/XamlViewer_v0300.xbap#XamlViewer_v0300.application, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ed9f9a6c9f3a9db8, processorArchitecture=msil/XamlViewer_v0300.exe, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ed9f9a6c9f3a9db8, processorArchitecture=msil, type=win32

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
      at System.Security.CodeAccessPermission.Demand()
      at MS.Internal.PresentationFramework.SecurityHelper.DemandUnmanagedCode()
      at MS.Internal.AppModel.AppSecurityManager.SafeLaunchBrowserDemandWhenUnsafe(Uri originatingUri, Uri destinationUri, Boolean fIsTopLevel)
      at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
      at System.Windows.Navigation.NavigationService.HandleWebResponse(IAsyncResult ar)
  • Hi Matt, you ought to be able to see this, certainly. You're right that if this experience were typical of the RTM version then it wouldn't be good, but I'm pretty confident there's just something spurious about your machine or this build. (I tested these demos on a near-RC1 drop, but they ought to work unchanged on Beta 2.) Let me loop in one of my colleagues and see if we can figure out what's going wrong here.
  • Hi Tim

    I'm getting the exact same error as Matt. Many WPF samples I can't view in my IE6; I get the same security error.

    Some WPF samples work; for example, Charles Petzold's keyhole clip thing worked. But yours didn't work, neither did the Ink Canvas one you linked to.

    I've got XP Pro, IE6, beta 2 of the WinFX/.NET 3 runtime. I've got so many dev components installed though (VC6, VS2k3, VS2k5, LINQ, and many, many others) perhaps there is some conflict. I dunno. I just hope this is a known bug and gets fixed before releease.
  • For what it's worth, I can copy this exact file locally and it runs just fine. I can't imagine what could cause the security issue. It's just a rich text box. The only thing suspect in the file is automatic spell checking. Nothing else seems out of the oridinary.

    Oh well. Thanks anyway.
    Matt
  • Just wanted to update this thread to say that we're still investigating what's causing Matt and Judah's problem, but all indications are that it's a bug that's only present in Beta 2 under certain conditions. Clearly this is a sub-optimal experience and one that we wouldn't ship in a released product. As you say, Matt, running this in full trust will work fine.

    Sorry for the inconvenience - on the positive side, RC1 is just around the corner!
  • I really missing about <style>somelement{behavior:url() url()}</style> dynamic behaviors,it Makes any element anything you want without any overhead.Yes,I miss AOP style programming in WPF-dependency properties is not enough,it's only beginning.I believe AOP is cornerstone of successful declarative model.
  • Thanks Tim!

    I've pre-ordered Charles Petzold's new WPF book and will be waiting for RC1 before really getting rolling with WPF anyway. So no big deal.

    Keep up the great work.
    Matt  
  • Yeah, same here, saving the file to disk and opening it up in IE6 works.
Page 1 of 2 (22 items) 12