This commit is contained in:
ShaneN 2018-08-02 15:55:15 -06:00
Родитель 1ee8e7d577 7045d80843
Коммит 1049a65056
14 изменённых файлов: 204 добавлений и 10 удалений

Просмотреть файл

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 3333, "[UWP] with ListView on page, Navigation.PopAsync() throws exception",
PlatformAffected.UWP)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.ListView)]
[NUnit.Framework.Category(UITestCategories.Navigation)]
#endif
public class Issue3333 : TestNavigationPage
{
const string kSuccess = "If you're reading this the test has passed";
protected override void Init()
{
var testPage = new TestPage();
this.Navigation.PushAsync(testPage);
}
[Preserve(AllMembers = true)]
public partial class TestPage : ContentPage
{
Label content = new Label();
public TestPage()
{
Title = "Page 1";
Navigation.PushAsync(new TestPage2());
Content = content;
}
protected override void OnAppearing()
{
if (content.Text == string.Empty)
{
content.Text = "Hold Please";
}
else
{
content.Text = kSuccess;
}
}
}
[Preserve(AllMembers = true)]
public class TestPage2 : ContentPage
{
public List<string> Items
{
get { return new List<string> { "Test1", "Test2", "Test3" }; }
}
public TestPage2()
{
BindingContext = this;
ListView listView = new ListView();
listView.SetBinding(ListView.ItemsSourceProperty, "Items");
Content =
new StackLayout()
{
Children =
{
new ScrollView()
{
Content = listView
}
}
};
Device.BeginInvokeOnMainThread(async () =>
{
BindingContext = null;
await Navigation.PopAsync();
});
}
}
#if UITEST
[Test]
public void SettingBindingContextToNullBeforingPoppingPageCrashes()
{
RunningApp.WaitForElement(kSuccess);
}
#endif
}
}

Просмотреть файл

@ -9,6 +9,7 @@
<Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Issue3333.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60045.xaml.cs">
<DependentUpon>Bugzilla60045.xaml</DependentUpon>

Просмотреть файл

@ -0,0 +1,8 @@
namespace Xamarin.Forms
{
interface IStyleElement
{
//note to implementor: implement this property publicly
Style Style { get; }
}
}

Просмотреть файл

@ -1,8 +1,12 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.StyleSheets;
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: InternalsVisibleTo("iOSUnitTests")]
[assembly: InternalsVisibleTo("Xamarin.Forms.Controls")]
[assembly: InternalsVisibleTo("Xamarin.Forms.Core.Design")]

Просмотреть файл

@ -11,10 +11,12 @@ namespace Xamarin.Forms
{
if (value != null)
{
double x, y, w, h;
string[] xywh = value.Split(',');
if (xywh.Length == 4 && double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) && double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) &&
double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out w) && double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out h))
if ( xywh.Length == 4
&& double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double x)
&& double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double y)
&& double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out double w)
&& double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out double h))
return new Rectangle(x, y, w, h);
}

Просмотреть файл

@ -6,6 +6,7 @@ using System.Globalization;
namespace Xamarin.Forms
{
[DebuggerDisplay("Width={Width}, Height={Height}")]
[TypeConverter(typeof(SizeTypeConverter))]
public struct Size
{
double _width;

Просмотреть файл

@ -0,0 +1,22 @@
using System;
using System.Globalization;
namespace Xamarin.Forms
{
[Xaml.TypeConversion(typeof(Size))]
public class SizeTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
string[] wh = value.Split(',');
if (wh.Length == 2
&& double.TryParse(wh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double w)
&& double.TryParse(wh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double h))
return new Size(w, h);
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Size)));
}
}
}

Просмотреть файл

@ -4,7 +4,7 @@ using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
[ContentProperty("Text")]
public sealed class Span : GestureElement, IFontElement, ITextElement, ILineHeightElement, IDecorableTextElement
public sealed class Span : GestureElement, IFontElement, IStyleElement, ITextElement, ILineHeightElement, IDecorableTextElement
{
internal readonly MergedStyle _mergedStyle;
@ -145,4 +145,4 @@ namespace Xamarin.Forms
{
}
}
}
}

Просмотреть файл

@ -157,7 +157,7 @@ namespace Xamarin.Forms
static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue)
{
Style style = (bindable as VisualElement).Style;
Style style = (bindable as IStyleElement).Style;
if (style == null)
return;
style.UnApplyCore(bindable, (Style)oldValue);

Просмотреть файл

@ -5,7 +5,7 @@ using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
public partial class VisualElement : Element, IAnimatable, IVisualElementController, IResourcesProvider, IFlowDirectionController
public partial class VisualElement : Element, IAnimatable, IVisualElementController, IResourcesProvider, IStyleElement, IFlowDirectionController
{
internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(VisualElement), default(INavigation));
@ -291,7 +291,6 @@ namespace Xamarin.Forms
set { SetValue(StyleProperty, value); }
}
[TypeConverter(typeof(ListStringTypeConverter))]
public IList<string> StyleClass
{

Просмотреть файл

@ -154,7 +154,7 @@ namespace Xamarin.Forms.Platform.UWP
break;
}
Device.BeginInvokeOnMainThread(() => List.UpdateLayout());
Device.BeginInvokeOnMainThread(() => List?.UpdateLayout());
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)

Просмотреть файл

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.Gh3280" Foo="15,25">
</ContentPage>

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
public partial class Gh3280 : ContentPage
{
public Gh3280()
{
InitializeComponent();
}
public Size Foo { get; set; }
public Gh3280(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
class Tests
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
}
[TestCase(false), TestCase(true)]
public void SizeHasConverter(bool useCompiledXaml)
{
Gh3280 layout = null;
Assert.DoesNotThrow(() => layout = new Gh3280(useCompiledXaml));
Assert.That(layout.Foo, Is.EqualTo(new Size(15, 25)));
}
}
}
}

Просмотреть файл

@ -631,6 +631,9 @@
<Compile Include="Issues\Gh3260.xaml.cs">
<DependentUpon>Gh3260.xaml</DependentUpon>
</Compile>
<Compile Include="Issues\Gh3280.xaml.cs">
<DependentUpon>Gh3280.xaml</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" Condition="'$(BuildingInsideVisualStudio)' == 'true' AND Exists('..\.nuspec\Xamarin.Forms.Build.Tasks.dll')" />
@ -1145,6 +1148,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Issues\Gh3280.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
@ -1198,4 +1205,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>