зеркало из https://github.com/DeGsoft/maui-linux.git
[C] Binding can't convert to valueTypes (#4453)
Binding type coverter wasn't chacking for valuetypes on null inputs. - fixes #4446
This commit is contained in:
Родитель
4f789b9bda
Коммит
42b7c31bc8
|
@ -418,7 +418,7 @@ namespace Xamarin.Forms
|
|||
internal static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget)
|
||||
{
|
||||
if (value == null)
|
||||
return true;
|
||||
return !convertTo.GetTypeInfo().IsValueType;
|
||||
if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value)))
|
||||
return true;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.ComponentModel;
|
|||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Xamarin.Forms.Internals
|
||||
{
|
||||
|
@ -287,4 +288,4 @@ namespace Xamarin.Forms.Internals
|
|||
_handlers [i].Listener.Unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?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="using:Xamarin.Forms.Xaml.UnitTests"
|
||||
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh4446">
|
||||
<StackLayout>
|
||||
<Label x:Name="label" IsVisible="{Binding Text}" x:DataType="local:Gh4446Item" />
|
||||
</StackLayout>
|
||||
</ContentPage>
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Core.UnitTests;
|
||||
|
||||
namespace Xamarin.Forms.Xaml.UnitTests
|
||||
{
|
||||
public class Gh4446Item
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
public partial class Gh4446 : ContentPage
|
||||
{
|
||||
public Gh4446()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public Gh4446(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(true), TestCase(false)]
|
||||
public void BindingThrowsOnWrongConverterParameter(bool useCompiledXaml)
|
||||
{
|
||||
Assert.DoesNotThrow(() => new Gh4446(useCompiledXaml) { BindingContext = new Gh4446Item { Text = null } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче