Category - XAML

  1. Upgrading Apps to Windows 8.1 – Deprecated Methods

    In upgrading NOOK from Windows 8 to Windows 8.1 there are four methods/properties that we were using that have been deprecated since Windows 8. Here they are and the replacement:

    1) ScrollViewer.ScrollToVerticalOffset and ScrollViewer.ScrollToHorizontalOffset have been replaced with ScrollViewer.ChangeView(OffsetX, OffsetY, ZoomLevel)

    2) ApplicationView.View has been replaced with ApplicationView.GetForCurrentView().Orientation which is an ApplicationViewOrientation

    3) DisplayProperties.LogicalDpi has been replaced with DisplayInformation.GetForCurrentView().LogicalDpi

    The first one has a catch though. Previously if the horizontal scroll width was smaller than the requested position it would fail silently. Using ChangeView though it will throw an exception. What I’ve had to do in this case is wait until the GridView is loaded then I use an anonymous method to do the horizontal scroll.

    The second one also has some interesting properties to it. Previously we were interested in if we were in snap view, but snap view is no longer used in Windows 8.1 so you need to stop looking for it. We use the Orientation to detect portrait versus landscape only. Width of the screen is detected with a size changed event.

    Let me know if you have any more methods that are deprecated that are useful to know.

  2. Difference in Margin Between HTML and XAML

    The Margin attribute of XAML elements acts different than in HTML. There are still the three ways of describing this information. The first way is simply, make all sides the same. These are identical in HTML and XAML (except that margin is capitalized in XAML).



    margin: 10px Margin=”10”

    XAML only allows you to work in pixels. So you do not need to mark the 10 with a "px" as you do in HTML. This will give the object a nice 10 pixel margin on all sides.

    What if you wanted the top and bottom to have one margin and the left and right to have a different one? Well to do that will describe the first difference between HTML and XAML:



    margin: 10px 20px; Margin-“40,20”

    Wait... What?!?

    There are a couple of things going on here. The first is that you describe the left/right margin first in XAML and you describe top/bottom first in HTML. The second thing to notice is that in XAML you add the left to the right or the top to the bottom and enter that value. The HTML and XAML will both produce 10 pixels of margin at the top, 10 pixels of margin at the bottom, 20 pixels of margin on the right, and 20 pixels on the left. But keep in mind that XAML lists the left/right first and you add the two together.

    Think you got it? Well now for the final element of twist:



    margin: 5px 10px 15px 20px; Margin="20,5,10,15"

    I bet you had it all figured out didn't you? Well this is also simple, but you need to keep it in mind when doing Silverlight. XAML expects Margin to be listed as Left, Top, Right, Bottom. HTML is Top, Right, Bottom, Left. They both go clockwise around the box, but HTML starts on the top and XAML starts on the left.

    I hope this helps anyone out there.