public bool StopOnResourceDictionary { get; }
public bool VisitNodeOnDataTemplate => true;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
public void Visit(ValueNode node, INode parentNode)
{
#if NETSTANDARD1_0
var bindableFieldInfo = elementType.GetFields().FirstOrDefault(fi => fi.Name == localName + "Property");
#else
- var bindableFieldInfo = elementType.GetFields(BindingFlags.Static | BindingFlags.Public|BindingFlags.FlattenHierarchy).FirstOrDefault(fi => fi.Name == localName + "Property");
+ var bindableFieldInfo = elementType.GetFields(BindingFlags.Static | BindingFlags.NonPublic|BindingFlags.FlattenHierarchy).FirstOrDefault(fi => fi.Name == localName + "Property");
+
+ if (null == bindableFieldInfo)
+ {
+ bindableFieldInfo = elementType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).FirstOrDefault(fi => fi.Name == localName + "Property");
+ }
#endif
Exception exception = null;
if (exception == null && bindableFieldInfo == null) {
//If it's an attached BP, update elementType and propertyName
var bpOwnerType = xamlelement.GetType();
var attached = GetRealNameAndType(ref bpOwnerType, propertyName.NamespaceURI, ref localName, context, lineInfo);
+
var property = GetBindableProperty(bpOwnerType, localName, lineInfo, false);
//If the target is an event, connect
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => false;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
public void Visit(ValueNode node, INode parentNode)
{
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => true;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => false;
public void Visit(ValueNode node, INode parentNode)
{
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => false;
+ public bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
+
public void Visit(ValueNode node, INode parentNode)
{
if (!typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode)]))
return true;
return false;
}
-
}
}
\ No newline at end of file
--- /dev/null
+namespace Tizen.NUI.Xaml
+{
+ internal interface IReferenceProvider
+ {
+ object FindByName(string name);
+ }
+}
\ No newline at end of file
[AcceptEmptyServiceProvider]
internal sealed class BindingExtension : IMarkupExtension<BindingBase>
{
- public BindingExtension()
- {
- Mode = BindingMode.Default;
- Path = Tizen.NUI.Binding.Binding.SelfPath;
- }
-
- public string Path { get; set; }
-
- public BindingMode Mode { get; set; }
+ public string Path { get; set; } = Binding.Binding.SelfPath;
+ public BindingMode Mode { get; set; } = BindingMode.Default;
public IValueConverter Converter { get; set; }
public string UpdateSourceEventName { get; set; }
+ public object TargetNullValue { get; set; }
+
+ public object FallbackValue { get; set; }
+
public TypedBindingBase TypedBinding { get; set; }
BindingBase IMarkupExtension<BindingBase>.ProvideValue(IServiceProvider serviceProvider)
{
if (TypedBinding == null)
- return new Tizen.NUI.Binding.Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source) { UpdateSourceEventName = UpdateSourceEventName };
+ return new Tizen.NUI.Binding.Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source)
+ {
+ UpdateSourceEventName = UpdateSourceEventName,
+ FallbackValue = FallbackValue,
+ TargetNullValue = TargetNullValue,
+ };
TypedBinding.Mode = Mode;
TypedBinding.Converter = Converter;
TypedBinding.StringFormat = StringFormat;
TypedBinding.Source = Source;
TypedBinding.UpdateSourceEventName = UpdateSourceEventName;
+ TypedBinding.FallbackValue = FallbackValue;
+ TypedBinding.TargetNullValue = TargetNullValue;
return TypedBinding;
}
namespace Tizen.NUI.Xaml
{
- // [ProvideCompiled("Tizen.NUI.Build.Tasks.NullExtension")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.NullExtension")]
[AcceptEmptyServiceProvider]
internal class NullExtension : IMarkupExtension
{
namespace Tizen.NUI.Xaml
{
[ContentProperty(nameof(Member))]
- // [ProvideCompiled("Tizen.NUI.Build.Tasks.StaticExtension")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.StaticExtension")]
internal class StaticExtension : IMarkupExtension
{
public string Member { get; set; }
namespace Tizen.NUI.Xaml
{
[ContentProperty(nameof(Style))]
- // [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
internal sealed class StyleSheetExtension : IValueProvider
{
public string Style { get; set; }
namespace Tizen.NUI.Xaml
{
[ContentProperty(nameof(TypeName))]
- // [ProvideCompiled("Tizen.NUI.Build.Tasks.TypeExtension")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.TypeExtension")]
internal class TypeExtension : IMarkupExtension<Type>
{
public string TypeName { get; set; }
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => true;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => false;
public void Visit(ValueNode node, INode parentNode)
{
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => true;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => false;
public void Visit(ElementNode node, INode parentNode)
{
continue;
if (!propertyName.Equals(XamlParser.McUri, "Ignorable"))
continue;
- (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string>()))?.AddRange(propertyValue.Split(','));
+ (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string>())).AddRange(propertyValue.Split(','));
}
foreach (var propertyKvp in node.Properties.ToList())
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal static class ReflectionExtensions
{
public static FieldInfo GetField(this Type type, Func<FieldInfo, bool> predicate)
{
public RegisterXNamesVisitor(HydrationContext context)
{
+ Context = context;
Values = context.Values;
}
Dictionary<INode, object> Values { get; }
-
+ HydrationContext Context { get; }
public TreeVisitingMode VisitingMode => TreeVisitingMode.TopDown;
public bool StopOnDataTemplate => true;
public bool StopOnResourceDictionary => false;
public bool VisitNodeOnDataTemplate => false;
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
public void Visit(ValueNode node, INode parentNode)
{
return value.ConvertTo(toType, getConverter, serviceProvider);
}
+ private delegate void ParseValueFunc(string s, IFormatProvider provider);
+
+ static private Dictionary<Type, ParseValueFunc> typeToParseValueFunc = null;
+
+ static private void BuildParseValueFunc()
+ {
+ if (null == typeToParseValueFunc)
+ {
+ typeToParseValueFunc = new Dictionary<Type, ParseValueFunc>();
+
+ }
+ }
+
internal static object ConvertTo(this object value, Type toType, Func<object> getConverter,
IServiceProvider serviceProvider)
{
{
//If there's a [TypeConverter], use it
object converter = getConverter?.Invoke();
- var xfTypeConverter = converter as TypeConverter;
- var xfExtendedTypeConverter = xfTypeConverter as IExtendedTypeConverter;
- if (xfExtendedTypeConverter != null)
- return value = xfExtendedTypeConverter.ConvertFromInvariantString(str, serviceProvider);
- if (xfTypeConverter != null)
- return value = xfTypeConverter.ConvertFromInvariantString(str);
- var converterType = converter?.GetType();
- if (converterType != null)
+ if (null != converter)
{
- var convertFromStringInvariant = converterType.GetRuntimeMethod("ConvertFromInvariantString",
- new[] { typeof (string) });
- if (convertFromStringInvariant != null)
- return value = convertFromStringInvariant.Invoke(converter, new object[] { str });
+ var xfTypeConverter = converter as TypeConverter;
+ var xfExtendedTypeConverter = xfTypeConverter as IExtendedTypeConverter;
+ if (xfExtendedTypeConverter != null)
+ return value = xfExtendedTypeConverter.ConvertFromInvariantString(str, serviceProvider);
+ if (xfTypeConverter != null)
+ return value = xfTypeConverter.ConvertFromInvariantString(str);
+ var converterType = converter?.GetType();
+ if (converterType != null)
+ {
+ var convertFromStringInvariant = converterType.GetRuntimeMethod("ConvertFromInvariantString",
+ new[] { typeof(string) });
+ if (convertFromStringInvariant != null)
+ return value = convertFromStringInvariant.Invoke(converter, new object[] { str });
+ }
}
+
var ignoreCase = (serviceProvider?.GetService(typeof(IConverterOptions)) as IConverterOptions)?.IgnoreCase ?? false;
//If the type is nullable, as the value is not null, it's safe to assume we want the built-in conversion
//Obvious Built-in conversions
if (toType.GetTypeInfo().IsEnum)
return Enum.Parse(toType, str, ignoreCase);
+
if (toType == typeof(SByte))
return SByte.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Int16))
using Tizen.NUI;
using Tizen.NUI.Xaml;
-// [assembly:Dependency(typeof(ValueConverterProvider))]
namespace Tizen.NUI.Xaml
{
internal class ValueConverterProvider : IValueConverterProvider
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml;
+using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
using Tizen.NUI.Binding.Internals;
namespace Tizen.NUI.Xaml
{
- static class XamlLoader
+ static internal class XamlLoader
{
public static void Load(object view, Type callingType)
{
- var xaml = GetXamlForType(callingType);
- if (string.IsNullOrEmpty(xaml))
- throw new XamlParseException(string.Format("No embeddedresource found for {0}", callingType), new XmlLineInfo());
- Console.WriteLine("============= Got xaml text is {0} ===========", xaml);
- Load(view, xaml);
- }
-
- public static Transition LoadTransition(string animationXamlPath)
- {
- var xaml = GetAnimationXaml(animationXamlPath);
- if (string.IsNullOrEmpty(xaml))
- throw new XamlParseException(string.Format("No embeddedresource found for {0}", animationXamlPath), new XmlLineInfo());
- Transition animation = new Transition();
- using (var textReader = new StringReader(xaml))
- using (var reader = XmlReader.Create(textReader))
+ try
{
- while (reader.Read())
- {
- //Skip until element
- if (reader.NodeType == XmlNodeType.Whitespace)
- continue;
- if (reader.NodeType == XmlNodeType.XmlDeclaration)
- continue;
- if (reader.NodeType != XmlNodeType.Element)
- {
- Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value);
- continue;
- }
-
- var rootnode = new RuntimeRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), animation, (IXmlNamespaceResolver)reader);
- XamlParser.ParseXaml(rootnode, reader);
- Visit(rootnode, new HydrationContext
- {
- RootElement = animation,
-#pragma warning disable 0618
- ExceptionHandler = ResourceLoader.ExceptionHandler ?? (Internals.XamlLoader.DoNotThrowOnExceptions ? e => { } : (Action<Exception>)null)
-#pragma warning restore 0618
- });
- break;
- }
+ var xaml = GetXamlForType(callingType);
+ if (string.IsNullOrEmpty(xaml))
+ throw new XamlParseException(string.Format("Can't get xaml from type {0}", callingType), new XmlLineInfo());
+ Load(view, xaml);
+ }
+ catch (XamlParseException e)
+ {
+ Tizen.Log.Fatal("NUI", "XamlParseException e.Message: " + e.Message);
+ Console.WriteLine("\n[FATAL] XamlParseException e.Message: {0}\n", e.Message);
}
- return animation;
}
- public static Animation LoadAnimation(string animationXamlPath)
+ public static T LoadObject<T>(string path)
{
- var xaml = GetAnimationXaml(animationXamlPath);
+ var xaml = GetAnimationXaml(path);
if (string.IsNullOrEmpty(xaml))
- throw new XamlParseException(string.Format("No embeddedresource found for {0}", animationXamlPath), new XmlLineInfo());
- Animation animation = new Animation();
+ throw new XamlParseException(string.Format("No embeddedresource found for {0}", path), new XmlLineInfo());
+ Type type = typeof(T);
+ T ret = (T)type.Assembly.CreateInstance(type.FullName);
+
+ NameScopeExtensions.PushElement(ret);
+
using (var textReader = new StringReader(xaml))
using (var reader = XmlReader.Create(textReader))
{
continue;
}
- var rootnode = new RuntimeRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), animation, (IXmlNamespaceResolver)reader);
+ var rootnode = new RuntimeRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), ret, (IXmlNamespaceResolver)reader);
XamlParser.ParseXaml(rootnode, reader);
Visit(rootnode, new HydrationContext
{
- RootElement = animation,
+ RootElement = ret,
#pragma warning disable 0618
ExceptionHandler = ResourceLoader.ExceptionHandler ?? (Internals.XamlLoader.DoNotThrowOnExceptions ? e => { } : (Action<Exception>)null)
#pragma warning restore 0618
break;
}
}
- return animation;
+
+ NameScopeExtensions.PopElement();
+ return ret;
}
public static void Load(object view, string xaml)
return false;
}
- bool IsResourceDictionary() => XmlType.Name == "ResourceDictionary";
-
protected bool SkipChildren(IXamlNodeVisitor visitor, INode node, INode parentNode) =>
(visitor.StopOnDataTemplate && IsDataTemplate(parentNode))
- || (visitor.StopOnResourceDictionary && IsResourceDictionary())
+ || (visitor.StopOnResourceDictionary && visitor.IsResourceDictionary(this))
|| visitor.SkipChildren(node, parentNode);
protected bool SkipVisitNode(IXamlNodeVisitor visitor, INode parentNode) =>
void Visit(RootNode node, INode parentNode);
void Visit(ListNode node, INode parentNode);
bool SkipChildren(INode node, INode parentNode);
+ bool IsResourceDictionary(ElementNode node);
}
internal enum TreeVisitingMode {
public void Visit(RootNode node, INode parentNode) => action(node, parentNode);
public void Visit(ListNode node, INode parentNode) => action(node, parentNode);
public bool SkipChildren(INode node, INode parentNode) => false;
+ public bool IsResourceDictionary(ElementNode node) => false;
}
}
\ No newline at end of file
using System;
+using System.Diagnostics;
+using System.Text;
using System.Xml;
namespace Tizen.NUI.Xaml
{
readonly string _unformattedMessage;
- public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message, xmlInfo), innerException)
+ static private StringBuilder GetStackInfo()
+ {
+ StringBuilder ret = new StringBuilder("\nStack:\n");
+
+ StackTrace st = new StackTrace();
+
+ for (int i = 2; i < st.FrameCount; i++)
+ {
+ StackFrame sf = st.GetFrame(i);
+ ret.AppendFormat("File:{0}, Method:{1}, Line:{2}\n", sf.GetFileName(), sf.GetMethod().Name, sf.GetFileLineNumber());
+ }
+
+ return ret;
+ }
+
+ public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException)
{
_unformattedMessage = message;
XmlInfo = xmlInfo;
{
internal static class XamlParser
{
- public const string XFUri = "http://xamarin.com/schemas/2014/forms";
+ public const string XFUri = "http://tizen.org/Tizen.NUI/2018/XAML";
public const string NUI2018Uri = "http://tizen.org/Tizen.NUI/2018/XAML";
public const string X2006Uri = "http://schemas.microsoft.com/winfx/2006/xaml";
public const string X2009Uri = "http://schemas.microsoft.com/winfx/2009/xaml";
if (_appIndexProvider == null)
throw new ArgumentException("No IAppIndexingProvider was provided");
if (_appIndexProvider.AppLinks == null)
- throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Xamarin.Forms.AppLinks");
+ throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Tizen.NUI.Binding.AppLinks");
return _appIndexProvider.AppLinks;
}
}
{
{ typeof(Uri), new UriTypeConverter() },
{ typeof(Color), new ColorTypeConverter() },
+ { typeof(Size2D), new Size2DTypeConverter() },
+ { typeof(Position2D), new Position2DTypeConverter() },
+ { typeof(Size), new SizeTypeConverter() },
+ { typeof(Position), new PositionTypeConverter() },
+ { typeof(Rectangle), new RectangleTypeConverter() },
+ { typeof(Rotation), new RotationTypeConverter() },
+ { typeof(Thickness), new ThicknessTypeConverter() },
+ { typeof(Vector2), new Vector2TypeConverter() },
+ { typeof(Vector3), new Vector3TypeConverter() },
+ { typeof(Vector4), new Vector4TypeConverter() },
+ { typeof(RelativeVector2), new RelativeVector2TypeConverter() },
+ { typeof(RelativeVector3), new RelativeVector3TypeConverter() },
+ { typeof(RelativeVector4), new RelativeVector4TypeConverter() },
};
// more or less the encoding of this, without the need to reflect
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.BindablePropertyConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindablePropertyConverter")]
[Xaml.TypeConversion(typeof(BindableProperty))]
internal sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter
{
if (propertyGetter == null)
throw new ArgumentNullException("propertyGetter");
- string path = GetBindingPath(propertyGetter);
- return new Binding(path, mode, converter, converterParameter, stringFormat);
- }
+ return new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat);
+ }
internal override void Apply(bool fromTarget)
{
BindingMode _mode = BindingMode.Default;
string _stringFormat;
+ object _targetNullValue;
+ object _fallbackValue;
internal BindingBase()
{
}
}
- internal bool AllowChaining { get; set; }
+ public object TargetNullValue
+ {
+ get { return _targetNullValue; }
+ set {
+ ThrowIfApplied();
+ _targetNullValue = value;
+ }
+ }
+
+ public object FallbackValue {
+ get => _fallbackValue;
+ set {
+ ThrowIfApplied();
+ _fallbackValue = value;
+ }
+ }
+
+ internal bool AllowChaining { get; set; }
internal object Context { get; set; }
SynchronizedCollections.Remove(collection);
}
- internal static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
+ public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
internal virtual object GetSourceValue(object value, Type targetPropertyType)
{
+ if (value == null && TargetNullValue != null)
+ return TargetNullValue;
if (StringFormat != null)
return string.Format(StringFormat, value);
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.BindingTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindingTypeConverter")]
[Xaml.TypeConversion(typeof(Binding))]
internal sealed class BindingTypeConverter : TypeConverter
{
using System;
-using System.Linq;
-using System.Reflection;
-
-using Tizen.NUI;
+using System.Globalization;
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Tizen.NUI.XamlC.ColorTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ColorTypeConverter")]
[Xaml.TypeConversion(typeof(Color))]
internal class ColorTypeConverter : TypeConverter
{
}
else if (parts.Length == 4) //like 0.5,0.5,0.5,0.5
{
- return new Color(float.Parse(parts[0].Trim()), float.Parse(parts[1].Trim()), float.Parse(parts[2].Trim()), float.Parse(parts[3].Trim()));
+ return new Color(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
+ Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
+ Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
+ Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
}
}
get
{
// if (info == null)
- // throw new InvalidOperationException("You MUST call Xamarin.Forms.Init(); prior to using it.");
+ // throw new InvalidOperationException("You MUST call Tizen.NUI.Xaml.Init(); prior to using it.");
return info;
}
set { info = value; }
using System;
+using System.Globalization;
using System.Linq;
using System.Reflection;
string[] parts = value.Split(',');
if (parts.Length == 4)
{
- return new Extents(ushort.Parse(parts[0].Trim()), ushort.Parse(parts[1].Trim()), ushort.Parse(parts[2].Trim()), ushort.Parse(parts[3].Trim()));
+ return new Extents(ushort.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
+ ushort.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
+ ushort.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
+ ushort.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
}
}
namespace Tizen.NUI.Binding
{
- // [ProvideCompiled("Xamarin.Forms.Core.XamlC.PassthroughValueProvider")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
[AcceptEmptyServiceProvider]
internal sealed class BindingCondition : Condition, IValueProvider
{
namespace Tizen.NUI.Binding
{
[ContentProperty("Setters")]
- // [ProvideCompiled("Xamarin.Forms.Core.XamlC.PassthroughValueProvider")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
[AcceptEmptyServiceProvider]
internal sealed class DataTrigger : TriggerBase, IValueProvider
{
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Reflection;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Xaml
+{
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
+ [AcceptEmptyServiceProvider]
+ internal sealed class PropertyCondition : Condition, IValueProvider
+ {
+ readonly BindableProperty _stateProperty;
+
+ BindableProperty _property;
+ object _triggerValue;
+
+ public PropertyCondition()
+ {
+ _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), false, propertyChanged: OnStatePropertyChanged);
+ }
+
+ public BindableProperty Property
+ {
+ get { return _property; }
+ set
+ {
+ if (_property == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
+ _property = value;
+
+ //convert the value
+ if (_property != null && s_valueConverter != null)
+ {
+ Func<MemberInfo> minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName);
+ Value = s_valueConverter.Convert(Value, Property.ReturnType, minforetriever, null);
+ }
+ }
+ }
+
+ public object Value
+ {
+ get { return _triggerValue; }
+ set
+ {
+ if (_triggerValue == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
+
+ //convert the value
+ if (_property != null && s_valueConverter != null)
+ {
+ Func<MemberInfo> minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName);
+ value = s_valueConverter.Convert(value, Property.ReturnType, minforetriever, null);
+ }
+ _triggerValue = value;
+ }
+ }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ //This is no longer required
+ return this;
+ }
+
+ internal override bool GetState(BindableObject bindable)
+ {
+ return (bool)bindable.GetValue(_stateProperty);
+ }
+
+ static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
+
+ internal override void SetUp(BindableObject bindable)
+ {
+ object newvalue = bindable.GetValue(Property);
+ bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
+ bindable.SetValue(_stateProperty, newState);
+ bindable.PropertyChanged += OnAttachedObjectPropertyChanged;
+ }
+
+ internal override void TearDown(BindableObject bindable)
+ {
+ bindable.ClearValue(_stateProperty);
+ bindable.PropertyChanged -= OnAttachedObjectPropertyChanged;
+ }
+
+ void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ var bindable = (BindableObject)sender;
+ var oldState = (bool)bindable.GetValue(_stateProperty);
+
+ if (Property == null)
+ return;
+ if (e.PropertyName != Property.PropertyName)
+ return;
+ object newvalue = bindable.GetValue(Property);
+ bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
+ if (oldState != newstate)
+ bindable.SetValue(_stateProperty, newstate);
+ }
+
+ void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
+ {
+ if ((bool)oldValue == (bool)newValue)
+ return;
+
+ ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);
+ }
+ }
+}
\ No newline at end of file
namespace Tizen.NUI.Binding
{
[ContentProperty("Setters")]
- // [ProvideCompiled("Xamarin.Forms.Core.XamlC.PassthroughValueProvider")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
[AcceptEmptyServiceProvider]
internal sealed class Trigger : TriggerBase, IValueProvider
{
namespace Tizen.NUI.Binding
{
- // [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")]
[AcceptEmptyServiceProvider]
internal sealed class XamlPropertyCondition : Condition, IValueProvider
{
return;
if (IsSealed)
throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
-
_property = value;
//convert the value
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal class DynamicResource
{
public DynamicResource(string key)
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal interface IDataTemplate
{
Func<object> LoadTemplate { get; set; }
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal interface IDeserializer
{
Task<IDictionary<string, object>> DeserializePropertiesAsync();
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal interface IDynamicResourceHandler
{
void SetDynamicResource(BindableProperty property, string key);
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal interface INameScope
{
object FindByName(string name);
namespace Tizen.NUI.Binding.Internals
{
[Flags]
- [EditorBrowsable(EditorBrowsableState.Never)]
internal enum InvalidationTrigger
{
Undefined = 0,
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal class NameScope : INameScope
{
public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope));
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal static class NumericExtensions
{
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ [AttributeUsage(AttributeTargets.All)]
+ internal class PreserveAttribute : Attribute
+ {
+ public bool AllMembers;
+ public bool Conditional;
+
+ public PreserveAttribute(bool allMembers, bool conditional)
+ {
+ AllMembers = allMembers;
+ Conditional = conditional;
+ }
+
+ public PreserveAttribute()
+ {
+ }
+ }
+}
\ No newline at end of file
namespace Tizen.NUI.Binding.Internals
{
- [EditorBrowsable(EditorBrowsableState.Never)]
internal abstract class Ticker
{
static Ticker s_ticker;
namespace Tizen.NUI.Binding.Internals
{
//FIXME: need a better name for this, and share with Binding, so we can share more unittests
- [EditorBrowsable(EditorBrowsableState.Never)]
internal abstract class TypedBindingBase : BindingBase
{
IValueConverter _converter;
}
}
- [EditorBrowsable(EditorBrowsableState.Never)]
internal sealed class TypedBinding<TSource, TProperty> : TypedBindingBase
{
readonly Func<TSource, TProperty> _getter;
public static readonly BindableProperty CascadeInputTransparentProperty = BindableProperty.Create(
nameof(CascadeInputTransparent), typeof(bool), typeof(Layout), true);
- public new static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
+ public static new readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
static IList<KeyValuePair<Layout, int>> s_resolutionList = new List<KeyValuePair<Layout, int>>();
static bool s_relayoutInProgress;
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.LayoutOptionsConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.LayoutOptionsConverter")]
[Xaml.TypeConversion(typeof(LayoutOptions))]
internal sealed class LayoutOptionsConverter : TypeConverter
{
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Tizen.NUI.Core.XamlC.ListStringTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Core.XamlC.ListStringTypeConverter")]
[Xaml.TypeConversion(typeof(List<string>))]
internal class ListStringTypeConverter : TypeConverter
{
/// The title of the back button for the specified page.
/// </summary>
/// <param name="page">The Page whose back-button's title is being requested.</param>
- /// <returns>The title of the back button that would be shown if the specified page were the Xamarin.Forms.CurrentPage.</returns>
+ /// <returns>The title of the back button that would be shown if the specified page were the Tizen.NUI.Xaml.CurrentPage.</returns>
public static string GetBackButtonTitle(BindableObject page)
{
return (string)page.GetValue(BackButtonTitleProperty);
/// </summary>
public event EventHandler<NavigationEventArgs> Popped;
+ /// <summary>
+ /// Event that is raised when the last nonroot element is popped from this NavigationPage element.
+ /// </summary>
+ public event EventHandler<NavigationEventArgs> PoppedToRoot;
+
/// <summary>
/// Pops all but the root Page off the navigation stack.
/// </summary>
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.RectangleTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.RectangleTypeConverter")]
[Xaml.TypeConversion(typeof(Rectangle))]
internal class RectangleTypeConverter : TypeConverter
{
using System;
-using System.Linq;
-using System.Reflection;
-
-using Tizen.NUI;
+using System.Globalization;
namespace Tizen.NUI.Binding
{
{
public override object ConvertFromInvariantString(string value)
{
+ /// public Rotation(Radian radian(float), Vector3 vector3)
+ /// Default: <View Orientation="45.0,12,13,0" />
+ /// Oritation="D:23, 0, 0, 1"
+ /// Oritation="R:23, 0, 0, 1"
if (value != null)
{
string[] parts = value.Split(',');
if (parts.Length == 4)
{
- Radian radian = new Radian(float.Parse(parts[0].Trim()));
- Vector3 vector3 = new Vector3( float.Parse(parts[1].Trim()), float.Parse(parts[2].Trim()), float.Parse(parts[3].Trim()) );
- //Ex: <View Orientation="45.0,12,13,0" />
- // public Rotation(Radian radian(float), Vector3 vector3)
- return new Rotation( radian, vector3 );
+ bool useDefault = true;
+ Radian radian = null;
+ string[] head = parts[0].Trim().Split(':');
+ if (head.Length == 2)
+ {
+ useDefault = false;
+ string radianOrDegree = head[0].Trim().ToLowerInvariant();
+ if(radianOrDegree == "d" || radianOrDegree == "degree")
+ {
+ /// Oritation="D:23, 0, 0, 1"
+ radian = new Radian( new Degree( Single.Parse( head[1].Trim(), CultureInfo.InvariantCulture ) ) );
+ }
+ else if (radianOrDegree == "r" || radianOrDegree == "radian")
+ {
+ /// Oritation="R:23, 0, 0, 1"
+ radian = new Radian( Single.Parse( head[1].Trim(), CultureInfo.InvariantCulture ) );
+ }
+ else
+ {
+ throw new InvalidOperationException($"Cannot convert the first parameter \"{value}\" into Radian of {typeof(Rotation)}");
+ }
+ }
+
+ if (useDefault)
+ {
+ ///Default: <View Orientation="45.0,12,13,0" />
+ radian = new Radian( Single.Parse( parts[0].Trim(), CultureInfo.InvariantCulture ) );
+ }
+
+ Vector3 vector3 = new Vector3(Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
+ Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
+ Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
+ return new Rotation(radian, vector3);
}
}
namespace Tizen.NUI.Binding
{
[ContentProperty("Value")]
- // [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")]
internal sealed class Setter : IValueProvider
{
readonly ConditionalWeakTable<BindableObject, object> _originalValues = new ConditionalWeakTable<BindableObject, object>();
using System.Globalization;
using Tizen.NUI;
+using Tizen.NUI.Xaml;
namespace Tizen.NUI.Binding
{
+ [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
internal class SizeTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
}
}
+ [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
internal class Size2DTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
[ContentProperty("Setters")]
internal sealed class Style : IStyle
{
- internal const string StyleClassPrefix = "Xamarin.Forms.StyleClass.";
+ internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass.";
readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style),
propertyChanged: OnBasedOnResourceChanged);
}
}
- public IList<Behavior> Behaviors
+ internal IList<Behavior> Behaviors
{
get { return _behaviors ?? (_behaviors = new AttachedCollection<Behavior>()); }
}
public IList<Setter> Setters { get; }
- public IList<TriggerBase> Triggers
+ internal IList<TriggerBase> Triggers
{
get { return _triggers ?? (_triggers = new AttachedCollection<TriggerBase>()); }
}
public IEnumerator<T> GetEnumerator()
{
- lock (_list)
+ ReadOnlyCollection<T> snap = _snapshot;
+ if (snap == null)
{
- ReadOnlyCollection<T> snap = _snapshot;
- if (snap == null)
- {
+ lock (_list)
_snapshot = snap = new ReadOnlyCollection<T>(_list.ToList());
- }
- return snap?.GetEnumerator();
}
+
+ return snap?.GetEnumerator();
}
public int IndexOf(T item)
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.ThicknessTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ThicknessTypeConverter")]
[Xaml.TypeConversion(typeof(Thickness))]
internal class ThicknessTypeConverter : TypeConverter
{
if (refAsm != null)
{
RegisterAssemblyRecursively(refAsm);
- if (refName.Name == "Xamarin.Forms.Core")
+ if (refName.Name == "Tizen.NUI.Xaml.Core")
{
- if (refAsm.GetType("Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement") != null)
+ if (refAsm.GetType("Tizen.NUI.Xaml.PlatformConfiguration.TizenSpecific.VisualElement") != null)
{
IsTizenSpecificAvailable = true;
}
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.TypeTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.TypeTypeConverter")]
[Xaml.TypeConversion(typeof(Type))]
internal sealed class TypeTypeConverter : TypeConverter, IExtendedTypeConverter
{
namespace Tizen.NUI.Binding
{
- // [Xaml.ProvideCompiled("Tizen.NUI.Core.XamlC.UriTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Core.XamlC.UriTypeConverter")]
[Xaml.TypeConversion(typeof(Uri))]
internal class UriTypeConverter : TypeConverter
{
--- /dev/null
+using System;
+
+namespace Tizen.NUI.Xaml
+{
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
+ sealed class ProvideCompiledAttribute : Attribute
+ {
+ public string CompiledVersion { get; }
+
+ public ProvideCompiledAttribute (string compiledVersion)
+ {
+ CompiledVersion = compiledVersion;
+ }
+ }
+}
\ No newline at end of file
using System;
using System.Reflection;
using System.ComponentModel;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.Xaml
{
/// <summary>
- /// Extension class for View defining Xamarin.Forms.Xaml.Extensions.LoadFromXaml{TView} method.
+ /// Extension class for View defining Tizen.NUI.Xaml.Extensions.LoadFromXaml{TView} method.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class Extensions
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public static Transition LoadTransition(string animationXamlPath)
+ public static T LoadObject<T>(string path)
{
- return XamlLoader.LoadTransition(animationXamlPath);
+ return XamlLoader.LoadObject<T>(path);
}
- }
+ }
}
\ No newline at end of file
/// <summary>
/// Implements the bound property whose interface is provided by the BindingContext property.
/// </summary>
- internal static readonly BindableProperty BindingContextProperty =
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty BindingContextProperty =
BindableProperty.Create("BindingContext", typeof(object), typeof(BindableObject), default(object),
BindingMode.OneWay, null, BindingContextPropertyChanged, null, null, BindingContextPropertyBindingChanging);
}
/// <summary>
- /// Clears any value set by Xamarin.Forms.BindableObject.SetValue.
+ /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue.
/// </summary>
/// <param name="property">The BindableProperty to clear</param>
internal void ClearValue(BindableProperty property)
}
/// <summary>
- /// Clears any value set by Xamarin.Forms.BindableObject.SetValue for the property that is identified by propertyKey.
+ /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue for the property that is identified by propertyKey.
/// </summary>
/// <param name="propertyKey">The BindablePropertyKey that identifies the BindableProperty to clear.</param>
internal void ClearValue(BindablePropertyKey propertyKey)
[EditorBrowsable(EditorBrowsableState.Never)]
public View Root {get; internal set;}
- internal static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPage), null, propertyChanged: (bindable, oldValue, newValue) =>
+ /// <summary>
+ /// The contents of ContentPage can be added into it.
+ /// </summary>
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPage), null, propertyChanged: (bindable, oldValue, newValue) =>
{
- // var self = (IControlTemplated)bindable;
- // var newElement = (Element)newValue;
- // if (self.ControlTemplate == null)
- // {
- // while (self.InternalChildren.Count > 0)
- // {
- // self.InternalChildren.RemoveAt(self.InternalChildren.Count - 1);
- // }
-
- // if (newValue != null)
- // self.InternalChildren.Add(newElement);
- // }
- // else
- // {
- // if (newElement != null)
- // {
- // BindableObject.SetInheritedBindingContext(newElement, bindable.BindingContext);
- // }
- // }
var self = (ContentPage)bindable;
if (newValue != null)
{
IsCreateByXaml = true;
Root = new View();
- Root.Size2D = new Size2D(win.WindowSize.Width, win.WindowSize.Height);
- Root.ParentOrigin = ParentOrigin.TopLeft;
- Root.PivotPoint = PivotPoint.TopLeft;
- Root.PositionUsesPivotPoint = true;
+ Root.WidthResizePolicy = ResizePolicyType.FillToParent;
+ Root.HeightResizePolicy = ResizePolicyType.FillToParent;
win.Add(Root);
}
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public Animation CreateAnimation(string animationType)
+ public Transition GetTransition(string transitionName)
{
- Animation ani = null;
Transition trans = null;
- transDictionary.TryGetValue(animationType, out trans);
-
- ani = trans?.CreateAnimation();
- return ani;
+ transDictionary.TryGetValue(transitionName, out trans);
+ return trans;
}
- private void CreateAnimationFactory()
+ private void LoadTransitions()
{
- foreach (string str in transitionType)
+ foreach (string str in transitionNames)
{
string resourceName = str + ".xaml";
Transition trans = null;
if (File.Exists(likelyResourcePath))
{
- trans = Extensions.LoadTransition(likelyResourcePath);
+ trans = Extensions.LoadObject<Transition>(likelyResourcePath);
}
if (trans)
{
}
}
- private string[] transitionType;
+ private string[] transitionNames;
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public string[] TransitionType
+ public string[] TransitionNames
{
get
{
- return transitionType;
+ return transitionNames;
}
set
{
- transitionType = value;
- CreateAnimationFactory();
+ transitionNames = value;
+ LoadTransitions();
}
}
}
{
INameScope namescope = GetNameScope();
if (namescope == null)
- throw new InvalidOperationException("this element is not in a namescope");
- return namescope.FindByName(name);
+ {
+ return null;
+ }
+ else
+ {
+ return namescope.FindByName(name);
+ }
}
void INameScope.RegisterName(string name, object scopedElement)
object value;
if (this.TryGetResource(key, out value))
OnResourceChanged(property, value);
+
+ Tizen.NUI.Application.AddResourceChangedCallback(this, (this as Element).OnResourcesChanged);
}
internal event EventHandler ParentSet;
/// Check if resources created.
/// </summary>
bool IsResourcesCreated { get; }
+
/// <summary>
/// Saved xaml resources.
/// </summary>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
object Convert(object value, Type targetType, object parameter, CultureInfo culture);
+
/// <summary>
/// Converts a value.
/// </summary>
+using System.Collections.Generic;
using System.ComponentModel;
using Tizen.NUI.Binding.Internals;
{
return (T)namescope.FindByName(name);
}
+
+ private static Stack<Element> elementStack = new Stack<Element>();
+
+ internal static void PushElement(object element)
+ {
+ elementStack.Push((Element)element);
+ }
+
+ internal static void PopElement()
+ {
+ elementStack.Pop();
+ }
+
+ /// <summary>
+ /// Used to find the object defined in Xaml file.
+ /// </summary>
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static T FindByNameInCurrentNameScope<T>(string name)
+ {
+ return FindByName<T>(elementStack.Peek(), name);
+ }
}
}
\ No newline at end of file
event EventHandler<ResourcesChangedEventArgs> ValuesChanged;
- // [Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.RDSourceTypeConverter")]
+ [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.RDSourceTypeConverter")]
internal class RDSourceTypeConverter : TypeConverter, IExtendedTypeConverter
{
object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
+using System.Collections.Generic;
using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Xaml;
using static Tizen.NUI.Animation;
namespace Tizen.NUI
{
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public class Transition : BaseHandle
+ public class AnimationBehavior
{
- private string name;
-
+ private string _key = null;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
-
- public string Name
+ public string Key
{
get
{
- return name;
+ return _key;
}
set
{
- name = value;
+ _key = value;
}
}
- private int duration;
+ private string _property = null;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public int Duration
+ public string Property
{
get
{
- return duration;
+ return _property;
}
set
{
- duration = value;
+ _property = value;
}
}
- private int loopCount;
+ private string _destValue = null;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public int LoopCount
+ public string DestValue
{
get
{
- return loopCount;
+ return _destValue;
}
set
{
- loopCount = value;
+ _destValue = value;
}
}
- private EndActions endAction;
+ private int _startTime = -1;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public EndActions EndAction
+ public int StartTime
{
get
{
- return endAction;
+ return _startTime;
}
set
{
- endAction = value;
+ _startTime = value;
}
}
- private string[] _properties = null;
+ private int _endTime = -1;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public string[] Properties
+ public int EndTime
{
get
{
- return _properties;
+ return _endTime;
}
set
{
- _properties = value;
+ _endTime = value;
}
}
+ }
- private string[] _destValue = null;
+ /// <since_tizen> 5 </since_tizen>
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class Transition : Animation
+ {
+ private string name;
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public string[] DestValue
+ public string Name
{
get
{
- return _destValue;
+ return name;
}
set
{
- _destValue = value;
+ name = value;
}
}
- private int[] _startTime = null;
+ private Dictionary<string, AnimationBehavior> behaviors = new Dictionary<string, AnimationBehavior>();
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public int[] StartTime
+ public AnimationBehavior[] Behaviors
{
- get
- {
- return _startTime;
- }
set
{
- _startTime = value;
+ if (null != value)
+ {
+ foreach (AnimationBehavior behavior in value)
+ {
+ behaviors.Add(behavior.Key, behavior);
+ }
+ }
}
}
- private int[] _endTime = null;
-
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public int[] EndTime
+ public void AnimateTo(View instance, string behaviorKey)
{
- get
+ AnimationBehavior behavior = null;
+ behaviors.TryGetValue(behaviorKey, out behavior);
+
+ if (null != behavior)
{
- return _endTime;
+ var elementType = instance.GetType();
+ PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == behavior.Property);
+
+ if (propertyInfo != null)
+ {
+ object destinationValue = ConvertTo(behavior.DestValue, propertyInfo.PropertyType);
+
+ if (destinationValue != null)
+ {
+ if (0 <= behavior.StartTime)
+ {
+ AnimateTo(instance, behavior.Property, destinationValue, behavior.StartTime, behavior.EndTime);
+ }
+ else
+ {
+ AnimateTo(instance, behavior.Property, destinationValue);
+ }
+ }
+ }
}
- set
+ else
{
- _endTime = value;
+ throw new XamlParseException(string.Format("Behaviors don't have key {0}", behaviorKey), new XmlLineInfo());
}
}
+ /// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public Animation CreateAnimation()
+ public void AnimateBy(View instance, string behaviorKey)
{
- Animation ani = new Animation();
+ AnimationBehavior behavior = null;
+ behaviors.TryGetValue(behaviorKey, out behavior);
- ani.Duration = Duration;
- ani.LoopCount = LoopCount;
- ani.EndAction = EndAction;
+ if (null != behavior)
+ {
+ var elementType = instance.GetType();
+ PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == behavior.Property);
- ani.Properties = Properties;
- ani.DestValue = DestValue;
- ani.StartTime = StartTime;
- ani.EndTime = EndTime;
+ if (propertyInfo != null)
+ {
+ object destinationValue = ConvertTo(behavior.DestValue, propertyInfo.PropertyType);
- return ani;
+ if (destinationValue != null)
+ {
+ if (0 <= behavior.StartTime)
+ {
+ AnimateBy(instance, behavior.Property, destinationValue, behavior.StartTime, behavior.EndTime);
+ }
+ else
+ {
+ AnimateBy(instance, behavior.Property, destinationValue);
+ }
+ }
+ }
+ }
+ else
+ {
+ throw new XamlParseException(string.Format("Behaviors don't have key {0}", behaviorKey), new XmlLineInfo());
+ }
}
}
}
\ No newline at end of file