Shawn

Shawn Wildermuth

Stories

Tagged with XAML


Forcing Orientation in WinRT

7d703de7-03a1-4a9b-8425-841ae065c30fI am working with a client on an enterprise Win8 app that is for order taking. They have a specific page that they require to be only in Portrait mode while the rest of the app can support any orientation. Since I've done so much Windows Phone 7/8 work I thought this would be simple. Just specify the value on the Page. But this didn't work…

Digging through the docs I found a probable solution: DisplayProperties.AutoRotationPreferences (in the Windows.Graphics.Display namespace). The docs specify that this property can be set with the DisplayOrientations enumeration to specify which of the four orientations to support. The enumeration is a flag so you can combine them too:

// All orientations
DisplayProperties.AutoRotationPreferences = DisplayOrientations.None;

// Portrait only
DisplayProperties.AutoRotationPreferences = DisplayOrientations.Portrait;

// Landscape only
DisplayProperties.AutoRotationPreferences = DisplayOrientations.Landscape;

// Landscape and upside down landscape only
DisplayProperties.AutoRotationPreferences = DisplayOrientations.Landscape | 
                                            DisplayOrientations.LandscapeFlipped;

Using these options should work, right? I tested it in a bunch of different places in my code and it didn't seem to have any effect. I was baffled.

Read...


Why Am I Excited about Windows Phone 8 SDK?

event_wp8_heroToday Microsoft is finally releasing the new Windows Phone 8 SDK. As I've been updating my Windows Phone book for this new incarnation of the device, I am excited that the SDK is finally going to be available for public consumption.

Even though the new phone has completely changed the underlying operation system to use the same WinRT sub-system that powers Windows 8, the basics of how to build apps on the phone is primarily the same. This means if you have experience building XAML-based projects, you should be right at home with Windows Phone 8.

A lot has been talked about the new Operating System and it's new tile layout and other features. But what I want to explain are the new developer features that I am excited about (in no specific order):

Read...


CSS for the XAML Guy - Positional Selectors

AngleBracketsI got into a longish, public discussion last night about XAML versus the HTML/CSS stack last night. I think they both have merit and pros and cons but it made me decide to add a short series of posts that highlight some of the CSS things that surprised me most (like my JavaScript for the C# Guy posts - and yes, more of those are coming too).

The first topic I am covering is some subtleties of the selector syntax. CSS selectors allow you to pick children, descendants and adjacent siblings. I found that I used descendant selector quite a lot:

#main h1 /* descendant */
{
  color: Red;
}

This syntax effectively says, any h1 inside an element named "main". I see people assume this actually means, *directly* inside the "main" element. So if you had some HTML like this, all h1's inside "main" would be colored red:

Read...


I've been Deep Fried...Again!

So I've done it again.  I survived another 30 minutes with Woody and Keith. Whew. We had a good conversation about the current state of Web Development and the future of XAML development.

I also got to discuss fried foods and make fun of Keith. Couldn't have been a better time. Go listen now:

Read...


Does Silverlight Matter to Windows Phone 8?

right-HERO_MANGO_062411A lot has been made since a report from Microsoft late last week (http://shawnw.me/HPEh0R) that seemed to say that Silverlight on the phone was going away in Windows Phone 8 (Apollo). I liked a lot of what this article had to say (from e-week):

http://shawnw.me/IwMgR2

So it got me thinking that much of the Silverlight community would be jumping out of windows (lower case and not TM) this week due to the news. But of course, if that's the case for you, I'd urge you not to panic. Why? Let me tell you.

Read...


Quick Tip: Show WinRT XAML Binding Errors

I saw a tip by Tim Heuer on a StackOverflow question about how to show binding errors in the Output window of managed WinRT (e.g. Metro-style) XAML projects. Tim mentioned that:

You get this automatically for C++ applications and for managed applications you have to turn on unmanaged debugging to see them.

Since I had a hard time finding it, I thought I'd drop a quick image to help you find it. You have to go to your project properties and look at the Debug tab:

Read...


Blend for Developers Course Now Available!

If you're a XAML developer and have proudly stated that you hand-code all your markup, it’s time to learn how to be more productive. I’ve authored a new course for PluralSight. If you have a subscription, you can view it my new “Blend for Developers” course now:

Hope you enjoy the course!

Read...


I am Coming to Washington DC for 2 Classes

If you are in the Washington, DC area (or are close enough to fly), I am coming to teach two courses just after Thanksgiving.

The Silverlight Tour

Read...


HTML5, XAML and Declarative User Interfaces

Hrmph!

At the suggestion of Tim Heuer this week, I took a break from writing my Windows Phone 7 book to delve into HTML5 a bit. I wanted to see what was different and how it would possibly impact Rich Internet Applications (RIA).

I did a couple of HTML5 tutorials which include the new tags that I think will be really cool (like <nav/>, <article/>, etc.) for traditional web design. I think the <datagrid /> and <datatemplate /> tags are interesting but unsure about how they'll be implemented. I also very interested in the local storage story, but it feels a long way from full implementation.  But I don't want to talk about the entire HTML5 stack as I am just scratching the surface. 

Read...


I am on .NET Rocks Talking about Declarative UI's

Url: http://www.dotnetrocks.com/default.aspx?ShowNum...

.NET Rocks

Before I left for Europe, I had a chance to sit down with Richard and Carl and espouse my views on views. Specifically we discussed how the separation of UIs (in declarative UI's like XAML and JavaScript templating) may help developers know specifically when they are in or out of the user interface part of their project. Hopefully this will make it easier to keep our code from getting tangled.  Watch out for the bad pizza/spagetti code reference...

Read...


Mike Swanson's XAML Plugin for Illustrator Updated

Url: http://blogs.msdn.com/mswanson/archive/2009/01/...

Silverlight Logo

Mike Swanson has updated his excellent plugin to address some issues with the output to make the XAML smaller as well as fix some issues with the way that PathGeometries are created that makes them more Blend friendly. In case you haven't been watching closely (and I wasn't), the plugin now supports export of Silverlight XAML which means that Expression Design isn't the only way to get Illustrator files to Silverlight XAML!

Read...


XAML Control Design

Silverlight LogoI've been digging into some of the open source and 3rd party controls that are becoming available for Silverlight 2. While running into some odd issues with some of them it occurred to me that there are some design guidelines that haven't been well communicated. Back in the early days of WPF I learned (though exactly where is unclear) that every control should support an empty constructor and that all properties (e.g. XAML Attributes) should have a default value. I knew this to be true but I couldn't document where it came from.

So as usual when I am stuck, I contacted Chris Sells as he was my mentor in early XAML usage. He was at MSDN at the time gathering content and helped me get the Data Binding articles as well into the Software Design Review for WPF (then Avalon). If anyone could help me figure out where I learned this, he'd know. He reminded me of the language they use internally: "Create-Set-Use". Essentially this means that the design pattern for controls is that they should work without requiring any properties:

<Grid ...>
  <Rectangle />
</Grid>

You can see that the Rectangle doesn't require any properties to be valid. Of course this Rectangle has no fill brush and no stroke brush which means it will likely not be visible.  But that's OK because it is valid XAML and doesn't break.  The XAML for a control doesn't have to read the mind of the user, but should behave (e.g. not throw exceptions). One of the most egregious was a control that threw an exception if I failed to set the Width and Height. Worse yet, when it did throw these exceptions, it didn't tell me what *all* the properties I needed therefore it was painful to use.  Width and Height are particularly problematic in this way in that by not defaulting to "Auto", showing the control in a non-Canvas container meant I needed to set "Auto" to the values which is what they should *always* be defaulted to.

Read...


Changing the "Selected" Style of ListBox's in XAML

I use ListBox's and DataTemplates a lot to show data in different ways in WPF. One of the problems I've faced is how to change the look of the "Selected" element. All the examples I could find assumed you were not using a DataTemplate.  Luckily Chris Sells came to my rescue and pointed me at the ItemContainerStyle.  Using a Template for the ListBoxItem in the ItemContainerStyle let me control the look and feel of the Selected element (or disabled items) easily.

What I wanted was a nice glow effect instead of the default blue background:

Read...


Silverlight in Print

Url: http://www.oreilly.com/catalog/9780596510381/

If you want to know more about Silverlight now, you can pick up Chris Sells and Ian Griffith's book, "Programming WPF: Second Edition".  The rough cut edition is available now from O'Reilly with the final print edition coming soon.  I wrote the Silverlight Appendix for that book.  The Rough Cut includes the Appendix (as well as a great WPF) with its old WPF/E moniker, but the release will include the fully silver-lit version.

In addition, i'll have a "Silverlight Short Cut" available soon from O'Reilly in time for MIX (By end of April).  I'll let you know in this space when that is available for download! If you're unfamilliar with Short Cuts, here's O'Reilly description from their website:

Read...


BamlViewer Reflector Addin

Url: http://www.codeplex.com/reflectoraddins/Release...

I've been digging a bit into how themes work for a new article.  In doing that I wanted to see how WPF used their theme files.  Their theme files are stored as BAML in the PresentationUI assembly.  As usual reflector came to the rescue with a BamlViewer plugin (available as part of the ReflectorAddIn's CodePlex Project). 

I downloaded it and started to look at the generic.xaml file that WPF uses.  Unfortunately the XAML window in the add-in was hard to navigate and didn't support searching.  What I really wanted was a way to support select/copy in the XAML viewer and a way to actually save the XAML files so I could do more in depth investigating.  Since the add-in didn't support, I volunteered to add it:

Read...


Nice "WPF/E" Egg Timer Sample

Url: http://www.interfacett.com/wpfe/eggtimer/defaul...

Read...