Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Controls.Issues"
x:Class="Xamarin.Forms.Controls.Issues.Issue5003">
<ContentPage.Resources>
<ResourceDictionary>
<local:StrikeThroughIfTrueConverter x:Key="StrikeThroughIfTrueConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Label Text="{Binding MyNullString}"
TextDecorations="{Binding SomeBoolean, Converter={StaticResource StrikeThroughIfTrueConverter}}"/>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Globalization;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 5003, "iOS StrikeThrough applied to null string throws error", PlatformAffected.iOS)]
public partial class Issue5003 : ContentPage
{

public Issue5003()
{
#if APP
InitializeComponent();
#endif
BindingContext = new VM();
}

[Preserve(AllMembers = true)]
class VM
{
public string MyNullString { get; set; }
public bool SomeBoolean { get; set; }
}
}

public class StrikeThroughIfTrueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool b)
{
if (b)
return TextDecorations.Strikethrough;
}

return TextDecorations.None;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4600.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5003.xaml.cs">
<DependentUpon>Issue5003.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)LegacyComponents\NonAppCompatSwitch.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MapsModalCrash.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModalActivityIndicatorTest.cs" />
Expand Down Expand Up @@ -1089,4 +1093,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue5003.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
10 changes: 9 additions & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
if (disposing)
{
if(Element != null)
if (Element != null)
{
Element.PropertyChanging -= ElementPropertyChanging;
}
Expand Down Expand Up @@ -216,6 +216,14 @@ void UpdateTextDecorations()
if (!Element.IsSet(Label.TextDecorationsProperty))
return;

#if __MOBILE__
if (!(Control.AttributedText?.Length > 0))
return;
#else
if (!(Control.AttributedStringValue?.Length > 0))
return;
#endif

var textDecorations = Element.TextDecorations;
#if __MOBILE__
var newAttributedText = new NSMutableAttributedString(Control.AttributedText);
Expand Down