10 changed files with 99 additions and 66 deletions
@ -1,33 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Globalization; |
|||
using Perspex; |
|||
using Perspex.Markup; |
|||
|
|||
namespace XamlTestApplication |
|||
{ |
|||
public class StringNullOrEmpty : IValueConverter |
|||
{ |
|||
public static readonly StringNullOrEmpty Instance = new StringNullOrEmpty(); |
|||
|
|||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
var s = value as string; |
|||
return s != null ? string.IsNullOrEmpty(s) : PerspexProperty.UnsetValue; |
|||
} |
|||
} |
|||
|
|||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Globalization; |
|||
using Perspex.Utilities; |
|||
|
|||
namespace Perspex.Markup |
|||
{ |
|||
/// <summary>
|
|||
/// A general purpose <see cref="IValueConverter"/> that uses a <see cref="Func{T1, TResult}"/>
|
|||
/// to provide the converter logic.
|
|||
/// </summary>
|
|||
/// <typeparam name="TIn"></typeparam>
|
|||
/// <typeparam name="TOut"></typeparam>
|
|||
public class FuncValueConverter<TIn, TOut> : IValueConverter |
|||
{ |
|||
private Func<TIn, TOut> _convert; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FuncValueConverter{TIn, TOut}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="convert">The convert function.</param>
|
|||
public FuncValueConverter(Func<TIn, TOut> convert) |
|||
{ |
|||
_convert = convert; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
if (value is TIn || (value == null && TypeUtilities.AcceptsNull(typeof(TIn)))) |
|||
{ |
|||
return _convert((TIn)value); |
|||
} |
|||
else |
|||
{ |
|||
return PerspexProperty.UnsetValue; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,32 +1,10 @@ |
|||
using System.Resources; |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.Reflection; |
|||
using Perspex.Metadata; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Markup")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Markup")] |
|||
[assembly: AssemblyCopyright("Copyright © 2015")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
[assembly: NeutralResourcesLanguage("en")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
|
|||
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup")] |
|||
[assembly: InternalsVisibleTo("Perspex.Markup.UnitTests")] |
|||
@ -0,0 +1,21 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Globalization; |
|||
using Perspex.Utilities; |
|||
|
|||
namespace Perspex.Markup |
|||
{ |
|||
/// <summary>
|
|||
/// Provides a set of useful <see cref="IValueConverter"/>s for working with string values.
|
|||
/// </summary>
|
|||
public static class StringConverters |
|||
{ |
|||
/// <summary>
|
|||
/// A value converter that returns true if the input string is null or an empty string.
|
|||
/// </summary>
|
|||
public static readonly IValueConverter NullOrEmpty = |
|||
new FuncValueConverter<string, bool>(x => string.IsNullOrEmpty(x)); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue