Bug 43783

Summary: [WP8.1] Most Device Styles do not render correctly in Windows Phone 8.1 (RT) applications
Product: Forms Reporter: Neil McAlister <mcalistern>
Component: WindowsAssignee: Bugzilla <bugzilla>
Severity: normal CC: chris.king, ehart, jas, mcalistern, sahou
Priority: ---    
Version: 2.3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: ac Is this bug a regression?: ---
Last known good build:
Attachments: Screenshot of text rendering weirdness

Description Neil McAlister 2016-08-26 09:00:08 UTC
Created attachment 17218 [details]
Screenshot of text rendering weirdness

When running a Xamarin.Forms Windows Phone 8.1 RT project, the following Device Styles do not render correctly.
 - ListItemTextStyle
 - ListItemDetailTextStyle
 - CaptionStyle
 - BodyStyle

All Labels using these styles appears as very small, and is unstyled.

This has further ramifications for default unstyled Label, as it appears to use the BodyStyle.

To reproduce:
Create a new Xamarin.Forms (PCL or Shared project) solution with a Windows Phone 8.1 (RT) project. Add Labels to any page using any of the above-mentioned styles, like so:

<Label Text="I am some text." Style="{DynamicResource CaptionStyle}"/>


Label label = new Label();
label.Text = "I am some text.";
label.Style = Xamarin.Forms.Device.Styles.CaptionStyle;

Actual Results:
Using any of these styles, or a default, unstyled Label results in small, unstyled text. See the attached screenshot for a comparison of how it looks in Xamarin.Forms.iOS, Xamarin.Forms.WindowsPhone and a native Windows Phone application.

Expected Results:
The device styles render as they would on the native platform. Judging from the Xamarin.Forms source code, the mapping should be as follows:

Xamarin.Forms -> Native Style
 - ListItemTextStyle -> ListViewItemTextBlockStyle
 - ListItemDetailTextStyle -> ListViewItemContentTextBlockStyle
 - CaptionStyle -> BodyTextBlockStyle
 - BodyStyle -> BodyTextBlockStyle

Build date & Hardware:
August 26, 2016, on Windows 10, Anniversary Update.

Target platforms:
Windows Phone 8.1, and Windows 10 Mobile.

A potential place to start:
I spent some time digging around in the Xamarin.Forms source code, and I suspect the culprit is in fact in Xamarin.Forms.Platform.WinRT.WindowsPhoneResourcesProvider. When it's pulling the Setters out of the default Styles, it seems to fail when attempting to resolve ThemeResources. Instead of handing an actual, concrete value to the Xamarin.Forms.Style, it hands over a BindingExpressionBase. When Xamarin.Forms then attempts to apply that BindingExpressionBase to (for example) the Label's FontSize proprety, the cast fails, and the style's Setter silently fails.

I'm not sure how that might be solved, as it doesn't look like it's possible to actually _do_ anything with BindingExpressionBase, nor to get the key of the ThemeResource the Setter's Value is pointing at. Hopefully it's a place to start though.
Comment 1 Chris King 2016-10-05 18:35:20 UTC
Confirmed. The following all render the same on WP8.1:

      Text="Welcome to Xamarin Forms!"
      Style="{DynamicResource CaptionStyle}"
      Style="{DynamicResource BodyStyle}"
      Style="{DynamicResource ListItemDetailTextStyle}"
      Style="{DynamicResource ListItemTextStyle}"
Comment 2 Samantha Houts [MSFT] 2017-01-30 19:55:13 UTC
Should be fixed in 2.3.5-pre1. Thank you!