summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-08-30 13:47:09 -0500
committerJason Smith <jason.smith@xamarin.com>2016-08-30 11:47:09 -0700
commitd8f9444ddb3e49b408a5431acf6fa43a226c434e (patch)
treee4fc7bcde77cac87834a79c49d32b193605207b5
parent88b15d7d1f40a19d35ed5daed16bdfe2a32adc76 (diff)
downloadxamarin-forms-d8f9444ddb3e49b408a5431acf6fa43a226c434e.tar.gz
xamarin-forms-d8f9444ddb3e49b408a5431acf6fa43a226c434e.tar.bz2
xamarin-forms-d8f9444ddb3e49b408a5431acf6fa43a226c434e.zip
[Win] Fix FontAttributes unexpectedly changing a label's size (#325)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43516.cs56
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.WinRT/LabelRenderer.cs5
3 files changed, 61 insertions, 1 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43516.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43516.cs
new file mode 100644
index 00000000..615f5a09
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43516.cs
@@ -0,0 +1,56 @@
+using System;
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 43516, "Changing FontAttributes on a label to None changes its font size")]
+ public class Bugzill43516 : TestContentPage
+ {
+ protected override void Init()
+ {
+ var label = new Label
+ {
+ FontAttributes = FontAttributes.Bold
+ };
+ label.BindingContext = label;
+ label.SetBinding(Label.TextProperty, "FontAttributes");
+
+ Content = new StackLayout
+ {
+ Children =
+ {
+ label,
+ new Button
+ {
+ Text = "Click to set FontAttributes.None",
+ Command = new Command(() =>
+ {
+ label.FontAttributes = FontAttributes.None;
+ })
+ },
+ new Button
+ {
+ Text = "Click to set FontAttributes.Bold",
+ Command = new Command(() =>
+ {
+ label.FontAttributes = FontAttributes.Bold;
+ })
+ },
+ new Button
+ {
+ Text = "Click to set Font.SystemFontOfSize to NamedSize.Medium",
+ Command = new Command(() => label.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)))
+ }
+ }
+ };
+ }
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index c0f5d33a..adf173df 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -123,6 +123,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42329.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42364.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42519.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
diff --git a/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs b/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs
index 1f2f861d..3997e7e4 100644
--- a/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs
@@ -34,6 +34,7 @@ namespace Xamarin.Forms.Platform.WinRT
public class LabelRenderer : ViewRenderer<Label, TextBlock>
{
bool _fontApplied;
+ bool _isInitiallyDefault;
protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize)
{
@@ -71,6 +72,8 @@ namespace Xamarin.Forms.Platform.WinRT
SetNativeControl(new TextBlock());
}
+ _isInitiallyDefault = Element.IsDefault();
+
UpdateText(Control);
UpdateColor(Control);
UpdateAlign(Control);
@@ -134,7 +137,7 @@ namespace Xamarin.Forms.Platform.WinRT
return;
#pragma warning disable 618
- Font fontToApply = label.IsDefault() ? Font.SystemFontOfSize(NamedSize.Medium) : label.Font;
+ Font fontToApply = label.IsDefault() && _isInitiallyDefault ? Font.SystemFontOfSize(NamedSize.Medium) : label.Font;
#pragma warning restore 618
textBlock.ApplyFont(fontToApply);