}
}
- internal class Application : BaseHandle, IResourcesProvider, IApplicationController, IElementConfiguration<Application>
+ internal class Application : BaseHandle, IResourcesProvider, IElementConfiguration<Application>
{
static Application s_current;
- Task<IDictionary<string, object>> _propertiesTask;
- readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry;
-
- IAppIndexingProvider _appIndexProvider;
ReadOnlyCollection<Element> _logicalChildren;
- Page _mainPage;
-
static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
- public IAppLinks AppLinks
- {
- get
- {
- 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");
- return _appIndexProvider.AppLinks;
- }
- }
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetCurrentApplication(Application value) => Current = value;
}
}
- public Page MainPage
- {
- get { return _mainPage; }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
-
- if (_mainPage == value)
- return;
-
- OnPropertyChanging();
- if (_mainPage != null)
- {
- InternalChildren.Remove(_mainPage);
- _mainPage.Parent = null;
- }
-
- _mainPage = value;
-
- if (_mainPage != null)
- {
- _mainPage.Parent = this;
- _mainPage.NavigationProxy.Inner = NavigationProxy;
- InternalChildren.Add(_mainPage);
- }
- OnPropertyChanged();
- }
- }
-
- public IDictionary<string, object> Properties
- {
- get
- {
- if (_propertiesTask == null)
- {
- _propertiesTask = GetPropertiesAsync();
- }
-
- return _propertiesTask.Result;
- }
- }
-
internal override ReadOnlyCollection<Element> LogicalChildrenInternal
{
get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
}
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new NavigationProxy NavigationProxy { get; }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int PanGestureId { get; set; }
-
internal IResourceDictionary SystemResources { get; }
ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SetAppIndexingProvider(IAppIndexingProvider provider)
- {
- _appIndexProvider = provider;
- }
-
ResourceDictionary _resources;
public bool IsResourcesCreated => _resources != null;
}
}
- public event EventHandler<ModalPoppedEventArgs> ModalPopped;
-
- public event EventHandler<ModalPoppingEventArgs> ModalPopping;
-
- public event EventHandler<ModalPushedEventArgs> ModalPushed;
-
- public event EventHandler<ModalPushingEventArgs> ModalPushing;
-
- public event EventHandler<Page> PageAppearing;
-
- public event EventHandler<Page> PageDisappearing;
-
-
- async void SaveProperties()
- {
- try
- {
- await SetPropertiesAsync();
- }
- catch (Exception exc)
- {
- Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}");
- }
- }
-
- public async Task SavePropertiesAsync()
- {
- if (Device.IsInvokeRequired)
- {
- Device.BeginInvokeOnMainThread(SaveProperties);
- }
- else
- {
- await SetPropertiesAsync();
- }
- }
-
- // Don't use this unless there really is no better option
- internal void SavePropertiesAsFireAndForget()
- {
- if (Device.IsInvokeRequired)
- {
- Device.BeginInvokeOnMainThread(SaveProperties);
- }
- else
- {
- SaveProperties();
- }
- }
-
- public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform
- {
- return _platformConfigurationRegistry.Value.On<T>();
- }
-
- protected virtual void OnAppLinkRequestReceived(Uri uri)
- {
- }
-
protected override void OnParentSet()
{
throw new InvalidOperationException("Setting a Parent on Application is invalid.");
}
- protected virtual void OnResume()
- {
- }
-
- protected virtual void OnSleep()
- {
- }
-
- protected virtual void OnStart()
- {
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void ClearCurrent()
- {
- s_current = null;
- }
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool IsApplicationOrNull(Element element)
{
OnResourcesChanged(changedResources);
}
- internal event EventHandler PopCanceled;
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendOnAppLinkRequestReceived(Uri uri)
- {
- OnAppLinkRequestReceived(uri);
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendResume()
- {
- s_current = this;
- OnResume();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendSleep()
- {
- OnSleep();
- SavePropertiesAsFireAndForget();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Task SendSleepAsync()
- {
- OnSleep();
- return SavePropertiesAsync();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendStart()
- {
- OnStart();
- }
-
- async Task<IDictionary<string, object>> GetPropertiesAsync()
- {
- var deserializer = DependencyService.Get<IDeserializer>();
- if (deserializer == null)
- {
- Console.WriteLine("Startup", "No IDeserialzier was found registered");
- return new Dictionary<string, object>(4);
- }
-
- IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
- if (properties == null)
- properties = new Dictionary<string, object>(4);
-
- return properties;
- }
-
- internal void OnPageAppearing(Page page)
- => PageAppearing?.Invoke(this, page);
-
- internal void OnPageDisappearing(Page page)
- => PageDisappearing?.Invoke(this, page);
-
- void OnModalPopped(Page modalPage)
- => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage));
-
- bool OnModalPopping(Page modalPage)
- {
- var args = new ModalPoppingEventArgs(modalPage);
- ModalPopping?.Invoke(this, args);
- return args.Cancel;
- }
-
- void OnModalPushed(Page modalPage)
- => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage));
-
- void OnModalPushing(Page modalPage)
- => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage));
-
- void OnPopCanceled()
- => PopCanceled?.Invoke(this, EventArgs.Empty);
-
- async Task SetPropertiesAsync()
- {
- await SaveSemaphore.WaitAsync();
- try
- {
- await DependencyService.Get<IDeserializer>()?.SerializePropertiesAsync(Properties);
- }
- finally
- {
- SaveSemaphore.Release();
- }
-
- }
-
- class NavigationImpl : NavigationProxy
- {
- readonly Application _owner;
-
- public NavigationImpl(Application owner)
- {
- _owner = owner;
- }
-
- protected override async Task<Page> OnPopModal(bool animated)
- {
- Page modal = ModalStack[ModalStack.Count - 1];
- if (_owner.OnModalPopping(modal))
- {
- _owner.OnPopCanceled();
- return null;
- }
- Page result = await base.OnPopModal(animated);
- result.Parent = null;
- _owner.OnModalPopped(result);
- return result;
- }
-
- protected override async Task OnPushModal(Page modal, bool animated)
- {
- _owner.OnModalPushing(modal);
-
- modal.Parent = _owner;
-
- if (modal.NavigationProxy.ModalStack.Count == 0)
- {
- modal.NavigationProxy.Inner = this;
- await base.OnPushModal(modal, animated);
- }
- else
- {
- await base.OnPushModal(modal, animated);
- modal.NavigationProxy.Inner = this;
- }
-
- _owner.OnModalPushed(modal);
- }
- }
-
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn)
{
- NavigationProxy = new NavigationImpl(this);
SetCurrentApplication(this);
- _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
- SendResume();
+ s_current = this;
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
{
Application ret = new Application(Interop.Application.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- ret.SendResume();
+ s_current = ret;
return ret;
}
var elementType = element.GetType();
var binding = value.ConvertTo(typeof(BindingBase),pinfoRetriever:null,serviceProvider:null) as BindingBase;
var bindable = element as BindableObject;
- var nativeBindingService = DependencyService.Get<INativeBindingService>();
if (binding == null)
return false;
return true;
}
- if (nativeBindingService != null && property != null && nativeBindingService.TrySetBinding(element, property, binding))
- return true;
-
- if (nativeBindingService != null && nativeBindingService.TrySetBinding(element, localName, binding))
- return true;
-
if (property != null)
exception = new XamlParseException($"{elementType.Name} is not a BindableObject or does not support native bindings", lineInfo);
var elementType = element.GetType();
var bindable = element as BindableObject;
- var nativeBindingService = DependencyService.Get<INativeBindingService>();
if (property == null)
return false;
return TryAddValue(bindable, property, value, serviceProvider);
}
- if (nativeBindingService != null && nativeBindingService.TrySetValue(element, property, convertedValue))
- return true;
-
exception = new XamlParseException($"{elementType.Name} is not a BindableObject or does not support setting native BindableProperties", lineInfo);
return false;
}
if (!node.Properties.ContainsKey(XmlName.xFactoryMethod))
{
//non-default ctor
- object ret = Activator.CreateInstance(nodeType, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, null, arguments, CultureInfo.CurrentCulture); ;
+ object ret = Activator.CreateInstance(nodeType, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, null, arguments, CultureInfo.CurrentCulture);
if (ret is Element)
{
if (null != Application.Current)
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml
-{
- internal interface IMarkupExtension<out T> : IMarkupExtension
- {
- new T ProvideValue(IServiceProvider serviceProvider);
- }
-
- internal interface IMarkupExtension
- {
- object ProvideValue(IServiceProvider serviceProvider);
- }
-
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- internal sealed class AcceptEmptyServiceProviderAttribute : Attribute
- {
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml.Internals
-{
- internal interface INativeValueConverterService
- {
- bool ConvertTo(object value, Type toType, out object nativeValue);
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Xaml
-{
- internal interface IProvideValueTarget
- {
- object TargetObject { get; }
- object TargetProperty { get; }
- }
-}
\ 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
+++ /dev/null
-namespace Tizen.NUI.Xaml
-{
- internal interface IRootObjectProvider
- {
- object RootObject { get; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml
-{
- internal interface IValueProvider
- {
- object ProvideValue(IServiceProvider serviceProvider);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml
-{
- internal interface IXamlTypeResolver
- {
- Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider = null);
- bool TryResolve(string qualifiedTypeName, out Type type);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Xml;
-
-namespace Tizen.NUI.Xaml
-{
- internal interface IXmlLineInfoProvider
- {
- IXmlLineInfo XmlLineInfo { get; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Items")]
- [AcceptEmptyServiceProvider]
- internal class ArrayExtension : IMarkupExtension<Array>
- {
- public ArrayExtension()
- {
- Items = new List<object>();
- }
-
- public IList Items { get; }
-
- public Type Type { get; set; }
-
- public Array ProvideValue(IServiceProvider serviceProvider)
- {
- if (Type == null)
- throw new InvalidOperationException("Type argument mandatory for x:Array extension");
-
- if (Items == null)
- return null;
-
- var array = Array.CreateInstance(Type, Items.Count);
- for (var i = 0; i < Items.Count; i++)
- ((IList)array)[i] = Items[i];
-
- return array;
- }
-
- object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
- {
- return (this as IMarkupExtension<Array>).ProvideValue(serviceProvider);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Path")]
- [AcceptEmptyServiceProvider]
- internal sealed class BindingExtension : IMarkupExtension<BindingBase>
- {
- public string Path { get; set; } = Binding.Binding.SelfPath;
- public BindingMode Mode { get; set; } = BindingMode.Default;
-
- public IValueConverter Converter { get; set; }
-
- public object ConverterParameter { get; set; }
-
- public string StringFormat { get; set; }
-
- public object Source { 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,
- FallbackValue = FallbackValue,
- TargetNullValue = TargetNullValue,
- };
-
- TypedBinding.Mode = Mode;
- TypedBinding.Converter = Converter;
- TypedBinding.ConverterParameter = ConverterParameter;
- TypedBinding.StringFormat = StringFormat;
- TypedBinding.Source = Source;
- TypedBinding.UpdateSourceEventName = UpdateSourceEventName;
- TypedBinding.FallbackValue = FallbackValue;
- TypedBinding.TargetNullValue = TargetNullValue;
- return TypedBinding;
- }
-
- object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
- {
- return (this as IMarkupExtension<BindingBase>).ProvideValue(serviceProvider);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Key")]
- internal sealed class DynamicResourceExtension : IMarkupExtension<DynamicResource>
- {
- public string Key { get; set; }
-
- public object ProvideValue(IServiceProvider serviceProvider)
- {
- return ((IMarkupExtension<DynamicResource>)this).ProvideValue(serviceProvider);
- }
-
- DynamicResource IMarkupExtension<DynamicResource>.ProvideValue(IServiceProvider serviceProvider)
- {
- if (Key == null)
- {
- var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
- throw new XamlParseException("DynamicResource markup require a Key", lineInfo);
- }
- return new DynamicResource(Key);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml
-{
- [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.NullExtension")]
- [AcceptEmptyServiceProvider]
- internal class NullExtension : IMarkupExtension
- {
- public object ProvideValue(IServiceProvider serviceProvider)
- {
- return null;
- }
- }
-}
+++ /dev/null
-using System;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Xaml.Internals;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Name")]
- internal class ReferenceExtension : IMarkupExtension
- {
- public string Name { get; set; }
-
- public object ProvideValue(IServiceProvider serviceProvider)
- {
- if (serviceProvider == null)
- throw new ArgumentNullException(nameof(serviceProvider));
- var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues;
- if (valueProvider == null)
- throw new ArgumentException("serviceProvider does not provide an IProvideValueTarget");
- var namescopeprovider = serviceProvider.GetService(typeof (INameScopeProvider)) as INameScopeProvider;
- if (namescopeprovider != null && namescopeprovider.NameScope != null)
- {
- var value = namescopeprovider.NameScope.FindByName(Name);
- if (value != null)
- return value;
- }
-
- foreach (var target in valueProvider.ParentObjects)
- {
- var ns = target as INameScope;
- if (ns == null)
- continue;
- var value = ns.FindByName(Name);
- if (value != null)
- return value;
- }
-
- var lineInfo = (serviceProvider?.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo ?? new XmlLineInfo();
- throw new XamlParseException($"Can not find the object referenced by `{Name}`", lineInfo);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Linq;
-using System.Reflection;
-using System.Xml;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty(nameof(Member))]
- [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.StaticExtension")]
- internal class StaticExtension : IMarkupExtension
- {
- public string Member { get; set; }
-
- public object ProvideValue(IServiceProvider serviceProvider)
- {
- IXmlLineInfoProvider lineInfoProvider;
- IXmlLineInfo lineInfo;
-
- if (serviceProvider == null)
- throw new ArgumentNullException(nameof(serviceProvider));
- var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver;
- if (typeResolver == null)
- throw new ArgumentException("No IXamlTypeResolver in IServiceProvider");
-
- if (string.IsNullOrEmpty(Member) || !Member.Contains("."))
- {
- lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
- throw new XamlParseException("Syntax for x:Static is [Member=][prefix:]typeName.staticMemberName", lineInfo);
- }
-
- var dotIdx = Member.LastIndexOf('.');
- var typename = Member.Substring(0, dotIdx);
- var membername = Member.Substring(dotIdx + 1);
-
- var type = typeResolver.Resolve(typename, serviceProvider);
-
- var pinfo = type.GetRuntimeProperties().FirstOrDefault(pi => pi.GetMethod != null && pi.Name == membername && pi.GetMethod.IsStatic);
- if (pinfo != null)
- return pinfo.GetMethod?.Invoke(null, Array.Empty<object>());
-
- var finfo = type.GetRuntimeFields().FirstOrDefault(fi => fi.Name == membername && fi.IsStatic);
- if (finfo != null)
- return finfo.GetValue(null);
-
- lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
- throw new XamlParseException($"No static member found for {Member}", lineInfo);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Xml;
-using System.Reflection;
-using System.Linq;
-using Tizen.NUI.Binding;
-
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Key")]
- internal sealed class StaticResourceExtension : IMarkupExtension
- {
- public string Key { get; set; }
-
- public object ProvideValue(IServiceProvider serviceProvider)
- {
- if (serviceProvider == null)
- throw new ArgumentNullException(nameof(serviceProvider));
- if (Key == null) {
- var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
- throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo);
- }
- var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
- if (valueProvider == null)
- throw new ArgumentException();
- var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null;
- object resource = null;
-
- foreach (var p in valueProvider.ParentObjects) {
- var irp = p as IResourcesProvider;
- var resDict = irp != null && irp.IsResourcesCreated ? irp.XamlResources : p as ResourceDictionary;
- if (resDict == null)
- continue;
- if (resDict.TryGetValue(Key, out resource))
- break;
- }
- resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo);
-
- var bp = valueProvider.TargetProperty as BindableProperty;
- var pi = valueProvider.TargetProperty as PropertyInfo;
- var propertyType = bp?.ReturnType ?? pi?.PropertyType;
- if (propertyType == null) {
- if (resource != null) {
- if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) {
- // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty
- var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() });
- if (method != null) {
- resource = method.Invoke(null, new[] { resource });
- }
- }
- }
- return resource;
- }
- if (propertyType.IsAssignableFrom(resource?.GetType()))
- return resource;
- var implicit_op = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType)
- ?? propertyType.GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType);
- if (implicit_op != null)
- return implicit_op.Invoke(resource, new [] { resource });
-
- if (resource != null) {
- //Special case for https://bugzilla.xamarin.com/show_bug.cgi?id=59818
- //On OnPlatform, check for an opImplicit from the targetType
- if ( Device.Flags != null
- && Device.Flags.Contains("xamlDoubleImplicitOpHack")
- && resource.GetType().GetTypeInfo().IsGenericType
- && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>))) {
- var tType = resource.GetType().GenericTypeArguments[0];
- var opImplicit = tType.GetImplicitConversionOperator(fromType: tType, toType: propertyType)
- ?? propertyType.GetImplicitConversionOperator(fromType: tType, toType: propertyType);
-
- if (opImplicit != null) {
- //convert the OnPlatform<T> to T
- var opPlatformImplicitConversionOperator = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: tType);
- resource = opPlatformImplicitConversionOperator?.Invoke(null, new[] { resource });
-
- //and convert to toType
- resource = opImplicit.Invoke(null, new[] { resource });
- return resource;
- }
- }
- }
- return resource;
- }
-
- internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo)
- {
- object resource = null;
- if (Application.Current == null || !((IResourcesProvider)Application.Current).IsResourcesCreated || !Application.Current.XamlResources.TryGetValue(Key, out resource))
- throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
- return resource;
- }
- }
-}
+++ /dev/null
-using System;
-using System.Xml;
-using Tizen.NUI.StyleSheets;
-using System.Reflection;
-using System.IO;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty(nameof(Style))]
- [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
- internal sealed class StyleSheetExtension : IValueProvider
- {
- public string Style { get; set; }
- public Uri Source { get; set; }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- IXmlLineInfo lineInfo;
-
- if (!string.IsNullOrEmpty(Style) && Source != null) {
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo);
- }
-
- if (Source != null) {
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- if (Source.IsAbsoluteUri)
- throw new XamlParseException($"Source only accepts Relative URIs", lineInfo);
-
- var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType();
- if (rootObjectType == null)
- return null;
- var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
- var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath);
- var resString = DependencyService.Get<IResourcesLoader>()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
- return StyleSheet.FromString(resString);
- }
-
- if (!string.IsNullOrEmpty(Style)) {
- using (var reader = new StringReader(Style))
- return StyleSheet.FromReader(reader);
- }
-
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty("Path")]
- [AcceptEmptyServiceProvider]
- internal sealed class TemplateBindingExtension : IMarkupExtension<BindingBase>
- {
- internal TemplateBindingExtension()
- {
- Mode = BindingMode.Default;
- Path = Tizen.NUI.Binding.Binding.SelfPath;
- }
-
- public string Path { get; set; }
-
- public BindingMode Mode { get; set; }
-
- public IValueConverter Converter { get; set; }
-
- public object ConverterParameter { get; set; }
-
- public string StringFormat { get; set; }
-
- BindingBase IMarkupExtension<BindingBase>.ProvideValue(IServiceProvider serviceProvider)
- {
- return new TemplateBinding(Path, Mode, Converter, ConverterParameter, StringFormat);
- }
-
- object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
- {
- return (this as IMarkupExtension<BindingBase>).ProvideValue(serviceProvider);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Xaml
-{
- [ContentProperty(nameof(TypeName))]
- [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.TypeExtension")]
- internal class TypeExtension : IMarkupExtension<Type>
- {
- public string TypeName { get; set; }
-
- public Type ProvideValue(IServiceProvider serviceProvider)
- {
- if (string.IsNullOrEmpty(TypeName))
- throw new InvalidOperationException("TypeName isn't set.");
- if (serviceProvider == null)
- throw new ArgumentNullException(nameof(serviceProvider));
- var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver;
- if (typeResolver == null)
- throw new ArgumentException("No IXamlTypeResolver in IServiceProvider");
-
- return typeResolver.Resolve(TypeName, serviceProvider);
- }
-
- object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
- {
- return (this as IMarkupExtension<Type>).ProvideValue(serviceProvider);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Xaml
-{
- [System.AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
- internal sealed class TypeConversionAttribute : Attribute
- {
- public Type TargetType { get; private set; }
-
- public TypeConversionAttribute(Type targetType)
- {
- TargetType = targetType;
- }
- }
-}
\ No newline at end of file
}
}
- var nativeValueConverterService = DependencyService.Get<INativeValueConverterService>();
-
- object nativeValue = null;
- if (nativeValueConverterService != null && nativeValueConverterService.ConvertTo(value, toType, out nativeValue))
- return nativeValue;
-
return value;
}
+++ /dev/null
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace Tizen.NUI.Xaml
-{
- [Flags]
- internal enum XamlCompilationOptions
- {
- Skip = 1 << 0,
- Compile = 1 << 1
- }
-
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class, Inherited = false)]
- internal sealed class XamlCompilationAttribute : Attribute
- {
- public XamlCompilationAttribute(XamlCompilationOptions xamlCompilationOptions)
- {
- XamlCompilationOptions = xamlCompilationOptions;
- }
-
- public XamlCompilationOptions XamlCompilationOptions { get; set; }
- }
-
- internal static class XamlCExtensions
- {
- public static bool IsCompiled(this Type type)
- {
- var attr = type.GetTypeInfo().GetCustomAttribute<XamlCompilationAttribute>();
- if (attr != null)
- return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
- attr = type.GetTypeInfo().Module.GetCustomAttribute<XamlCompilationAttribute>();
- if (attr != null)
- return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
- attr = type.GetTypeInfo().Assembly.GetCustomAttribute<XamlCompilationAttribute>();
- if (attr != null)
- return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
-
- return false;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Tizen.NUI.Xaml
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
- internal sealed class XamlFilePathAttribute : Attribute
- {
- public XamlFilePathAttribute([CallerFilePath] string filePath = "")
- {
- }
- }
-}
\ No newline at end of file
namespace Tizen.NUI.Xaml.Internals
{
- [Obsolete("Replaced by ResourceLoader")]
- internal static class XamlLoader
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete ("Replaced by ResourceLoader")]
+ public static class XamlLoader
{
static Func<Type, string> xamlFileProvider;
- public static Func<Type, string> XamlFileProvider
- {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static Func<Type, string> XamlFileProvider {
get { return xamlFileProvider; }
internal set
{
+++ /dev/null
-using System;
-using System.Diagnostics;
-using System.Text;
-using System.Xml;
-
-namespace Tizen.NUI.Xaml
-{
- internal class XamlParseException : Exception
- {
- readonly string _unformattedMessage;
-
- 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;
- }
-
- public IXmlLineInfo XmlInfo { get; private set; }
-
- internal string UnformattedMessage
- {
- get { return _unformattedMessage ?? Message; }
- }
-
- static string FormatMessage(string message, IXmlLineInfo xmlinfo)
- {
- if (xmlinfo == null || !xmlinfo.HasLineInfo())
- return message;
- return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message);
- }
- }
-}
\ No newline at end of file
foreach (var kvp in xmlns) {
var prefix = kvp.Key;
- string typeName = null, ns = null, asm = null, targetPlatform = null;
- XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm, out targetPlatform);
- if (targetPlatform == null)
- continue;
- try {
- if (targetPlatform != Device.RuntimePlatform)
- {
- // Special case for Windows backward compatibility
- if (targetPlatform == "Windows" && Device.RuntimePlatform == Device.UWP)
- continue;
-
- prefixes.Add(prefix);
- }
- } catch (InvalidOperationException) {
- prefixes.Add(prefix);
- }
+ string typeName = null, ns = null, asm = null;
+ XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm);
}
return prefixes;
}
if (lookupAssemblies.Count == 0) {
string ns, asmstring, _;
- XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring, out _);
+ XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring);
lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns) {
AssemblyName = asmstring ?? currentAssembly.FullName
});
+++ /dev/null
-using System;
-using System.Reflection;
-
-namespace Tizen.NUI.Xaml
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
- internal sealed class XamlResourceIdAttribute : Attribute
- {
- public string ResourceId { get; set; }
- public string Path { get; set; }
- public Type Type { get; set; }
-
- public XamlResourceIdAttribute(string resourceId, string path, Type type)
- {
- ResourceId = resourceId;
- Path = path;
- Type = type;
- }
-
- internal static string GetResourceIdForType(Type type)
- {
- var assembly = type.GetTypeInfo().Assembly;
- foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
- if (xria.Type == type)
- return xria.ResourceId;
- }
- return null;
- }
-
- internal static string GetPathForType(Type type)
- {
- var assembly = type.GetTypeInfo().Assembly;
- foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
- if (xria.Type == type)
- return xria.Path;
- }
- return null;
- }
-
- internal static string GetResourceIdForPath(Assembly assembly, string path)
- {
- foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
- if (xria.Path == path)
- return xria.ResourceId;
- }
- return null;
- }
-
- internal static Type GetTypeForResourceId(Assembly assembly, string resourceId)
- {
- foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
- if (xria.ResourceId == resourceId)
- return xria.Type;
- }
- return null;
- }
-
- internal static Type GetTypeForPath(Assembly assembly, string path)
- {
- foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
- if (xria.Path == path)
- return xria.Type;
- }
- return null;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Xml;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Xaml
-{
- internal class XamlServiceProvider : IServiceProvider
- {
- readonly Dictionary<Type, object> services = new Dictionary<Type, object>();
-
- internal XamlServiceProvider(INode node, HydrationContext context)
- {
- object targetObject;
- if (node != null && node.Parent != null && context.Values.TryGetValue(node.Parent, out targetObject))
- IProvideValueTarget = new XamlValueTargetProvider(targetObject, node, context, null);
- if (context != null)
- IRootObjectProvider = new XamlRootObjectProvider(context.RootElement);
- if (node != null)
- {
- IXamlTypeResolver = new XamlTypeResolver(node.NamespaceResolver, XamlParser.GetElementType,
- context?.RootElement.GetType().GetTypeInfo().Assembly);
-
- var enode = node;
- while (enode != null && !(enode is IElementNode))
- enode = enode.Parent;
- if (enode != null)
- INameScopeProvider = new NameScopeProvider { NameScope = (enode as IElementNode).Namescope };
- }
-
- var xmlLineInfo = node as IXmlLineInfo;
- if (xmlLineInfo != null)
- IXmlLineInfoProvider = new XmlLineInfoProvider(xmlLineInfo);
-
- IValueConverterProvider = new ValueConverterProvider();
- }
-
- public XamlServiceProvider()
- {
- IValueConverterProvider = new ValueConverterProvider();
- }
-
- internal IProvideValueTarget IProvideValueTarget
- {
- get { return (IProvideValueTarget)GetService(typeof (IProvideValueTarget)); }
- set { services[typeof (IProvideValueTarget)] = value; }
- }
-
- internal IXamlTypeResolver IXamlTypeResolver
- {
- get { return (IXamlTypeResolver)GetService(typeof (IXamlTypeResolver)); }
- set { services[typeof (IXamlTypeResolver)] = value; }
- }
-
- internal IRootObjectProvider IRootObjectProvider
- {
- get { return (IRootObjectProvider)GetService(typeof (IRootObjectProvider)); }
- set { services[typeof (IRootObjectProvider)] = value; }
- }
-
- internal IXmlLineInfoProvider IXmlLineInfoProvider
- {
- get { return (IXmlLineInfoProvider)GetService(typeof (IXmlLineInfoProvider)); }
- set { services[typeof (IXmlLineInfoProvider)] = value; }
- }
-
- internal INameScopeProvider INameScopeProvider
- {
- get { return (INameScopeProvider)GetService(typeof (INameScopeProvider)); }
- set { services[typeof (INameScopeProvider)] = value; }
- }
-
- internal IValueConverterProvider IValueConverterProvider
- {
- get { return (IValueConverterProvider)GetService(typeof (IValueConverterProvider)); }
- set { services[typeof (IValueConverterProvider)] = value; }
- }
-
- public object GetService(Type serviceType)
- {
- object service;
- return services.TryGetValue(serviceType, out service) ? service : null;
- }
-
- public void Add(Type type, object service)
- {
- services.Add(type, service);
- }
- }
-
- internal class XamlValueTargetProvider : IProvideParentValues, IProvideValueTarget
- {
- public XamlValueTargetProvider(object targetObject, INode node, HydrationContext context, object targetProperty)
- {
- Context = context;
- Node = node;
- TargetObject = targetObject;
- TargetProperty = targetProperty;
- }
-
- INode Node { get; }
-
- HydrationContext Context { get; }
- public object TargetObject { get; }
- public object TargetProperty { get; internal set; } = null;
-
- IEnumerable<object> IProvideParentValues.ParentObjects
- {
- get
- {
- if (Node == null || Context == null)
- yield break;
- var n = Node;
- object obj = null;
- var context = Context;
- while (n.Parent != null && context != null)
- {
- if (n.Parent is IElementNode)
- {
- if (context.Values.TryGetValue(n.Parent, out obj))
- yield return obj;
- else
- {
- context = context.ParentContext;
- continue;
- }
- }
- n = n.Parent;
- }
- }
- }
- }
-
- internal class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget
- {
- readonly object[] objectAndParents;
- readonly object targetProperty;
-
- [Obsolete("SimpleValueTargetProvider(object[] objectAndParents) is obsolete as of version 2.3.4. Please use SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) instead.")]
- public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null)
- {
- }
-
- public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty)
- {
- if (objectAndParents == null)
- throw new ArgumentNullException(nameof(objectAndParents));
- if (objectAndParents.Length == 0)
- throw new ArgumentException();
-
- this.objectAndParents = objectAndParents;
- this.targetProperty = targetProperty;
- }
-
- IEnumerable<object> IProvideParentValues.ParentObjects
- {
- get { return objectAndParents; }
- }
-
- object IProvideValueTarget.TargetObject
- {
- get { return objectAndParents[0]; }
- }
-
- object IProvideValueTarget.TargetProperty
- {
- get { return targetProperty; }
- }
- }
-
- internal class XamlTypeResolver : IXamlTypeResolver
- {
- readonly Assembly currentAssembly;
- readonly GetTypeFromXmlName getTypeFromXmlName;
- readonly IXmlNamespaceResolver namespaceResolver;
-
- public XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, Assembly currentAssembly)
- : this(namespaceResolver, XamlParser.GetElementType, currentAssembly)
- {
- }
-
- internal XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, GetTypeFromXmlName getTypeFromXmlName,
- Assembly currentAssembly)
- {
- this.currentAssembly = currentAssembly;
- if (namespaceResolver == null)
- throw new ArgumentNullException();
- if (getTypeFromXmlName == null)
- throw new ArgumentNullException();
-
- this.namespaceResolver = namespaceResolver;
- this.getTypeFromXmlName = getTypeFromXmlName;
- }
-
- Type IXamlTypeResolver.Resolve(string qualifiedTypeName, IServiceProvider serviceProvider)
- {
- XamlParseException e;
- var type = Resolve(qualifiedTypeName, serviceProvider, out e);
- if (e != null)
- throw e;
- return type;
- }
-
- bool IXamlTypeResolver.TryResolve(string qualifiedTypeName, out Type type)
- {
- XamlParseException exception;
- type = Resolve(qualifiedTypeName, null, out exception);
- return exception == null;
- }
-
- Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider, out XamlParseException exception)
- {
- exception = null;
- var split = qualifiedTypeName.Split(':');
- if (split.Length > 2)
- return null;
-
- string prefix, name;
- if (split.Length == 2)
- {
- prefix = split[0];
- name = split[1];
- }
- else
- {
- prefix = "";
- name = split[0];
- }
-
- IXmlLineInfo xmlLineInfo = null;
- if (serviceProvider != null)
- {
- var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- if (lineInfoProvider != null)
- xmlLineInfo = lineInfoProvider.XmlLineInfo;
- }
-
- var namespaceuri = namespaceResolver.LookupNamespace(prefix);
- if (namespaceuri == null)
- {
- exception = new XamlParseException(string.Format("No xmlns declaration for prefix \"{0}\"", prefix), xmlLineInfo);
- return null;
- }
-
- return getTypeFromXmlName(new XmlType(namespaceuri, name, null), xmlLineInfo, currentAssembly, out exception);
- }
-
- internal delegate Type GetTypeFromXmlName(
- XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, out XamlParseException exception);
- }
-
- internal class XamlRootObjectProvider : IRootObjectProvider
- {
- public XamlRootObjectProvider(object rootObject)
- {
- RootObject = rootObject;
- }
-
- public object RootObject { get; }
- }
-
- internal class XmlLineInfoProvider : IXmlLineInfoProvider
- {
- public XmlLineInfoProvider(IXmlLineInfo xmlLineInfo)
- {
- XmlLineInfo = xmlLineInfo;
- }
-
- public IXmlLineInfo XmlLineInfo { get; }
- }
-
- internal class NameScopeProvider : INameScopeProvider
- {
- public INameScope NameScope { get; set; }
- }
-
- internal class XmlNamespaceResolver : IXmlNamespaceResolver
- {
- readonly Dictionary<string, string> namespaces = new Dictionary<string, string>();
-
- public IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
- {
- throw new NotImplementedException();
- }
-
- public string LookupNamespace(string prefix)
- {
- string result;
- if (namespaces.TryGetValue(prefix, out result))
- return result;
- return null;
- }
-
- public string LookupPrefix(string namespaceName)
- {
- throw new NotImplementedException();
- }
-
- public void Add(string prefix, string ns)
- {
- namespaces.Add(prefix, ns);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Xml;
-
-namespace Tizen.NUI.Xaml
-{
- internal class XmlLineInfo : IXmlLineInfo
- {
- readonly bool _hasLineInfo;
-
- public XmlLineInfo()
- {
- }
-
- public XmlLineInfo(int linenumber, int lineposition)
- {
- _hasLineInfo = true;
- LineNumber = linenumber;
- LinePosition = lineposition;
- }
-
- public bool HasLineInfo()
- {
- return _hasLineInfo;
- }
-
- public int LineNumber { get; }
-
- public int LinePosition { get; }
- }
-}
\ No newline at end of file
string typeName;
string ns;
string asm;
- string targetPlatform;
-
- ParseXmlns(xmlns, out typeName, out ns, out asm, out targetPlatform);
+ ParseXmlns(xmlns, out typeName, out ns, out asm);
return ns;
}
- public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform)
+ public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm)
{
- typeName = ns = asm = targetPlatform = null;
+ typeName = ns = asm = null;
xmlns = xmlns.Trim();
if (xmlns.StartsWith("using:", StringComparison.Ordinal)) {
- ParseUsing(xmlns, out typeName, out ns, out asm, out targetPlatform);
+ ParseUsing(xmlns, out typeName, out ns, out asm);
return;
}
- ParseClrNamespace(xmlns, out typeName, out ns, out asm, out targetPlatform);
+ ParseClrNamespace(xmlns, out typeName, out ns, out asm);
}
- static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform)
+ static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm)
{
- typeName = ns = asm = targetPlatform = null;
+ typeName = ns = asm = null;
foreach (var decl in xmlns.Split(';'))
{
ns = decl.Substring(14, decl.Length - 14);
continue;
}
+
if (decl.StartsWith("assembly=", StringComparison.Ordinal))
{
asm = decl.Substring(9, decl.Length - 9);
continue;
}
- if (decl.StartsWith("targetPlatform=", StringComparison.Ordinal)) {
- targetPlatform = decl.Substring(15, decl.Length - 15);
- continue;
- }
+
var nsind = decl.LastIndexOf(".", StringComparison.Ordinal);
if (nsind > 0)
{
}
}
- static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform)
+ static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm)
{
- typeName = ns = asm = targetPlatform = null;
+ typeName = ns = asm = null;
foreach (var decl in xmlns.Split(';')) {
if (decl.StartsWith("using:", StringComparison.Ordinal)) {
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- [System.ComponentModel.TypeConverter(typeof(AcceleratorTypeConverter))]
- internal class Accelerator
- {
- const char Separator = '+';
- string _text;
-
- internal Accelerator(string text)
- {
- if (string.IsNullOrEmpty(text))
- throw new ArgumentNullException(nameof(text));
- _text = text;
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IEnumerable<string> Modifiers { get; set; }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IEnumerable<string> Keys { get; set; }
-
- public static Accelerator FromString(string text)
- {
- var accelarat = new Accelerator(text);
-
- var acceleratorParts = text.Split(Separator);
-
- if (acceleratorParts.Length > 1)
- {
- var modifiers = new List<string>();
- for (int i = 0; i < acceleratorParts.Length; i++)
- {
- var modifierMask = acceleratorParts[i];
- var modiferMaskLower = modifierMask.ToLower();
- switch (modiferMaskLower)
- {
- case "ctrl":
- case "cmd":
- case "alt":
- case "shift":
- case "fn":
- case "win":
- modifiers.Add(modiferMaskLower);
- text = text.Replace(modifierMask, "");
- break;
- }
- }
- accelarat.Modifiers = modifiers;
-
- }
-
- var keys = text.Split(new char[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
- accelarat.Keys = keys;
- return accelarat;
- }
-
- public override string ToString()
- {
- return _text;
- }
-
- public override bool Equals(object obj)
- {
- return obj != null && obj is Accelerator && Equals((Accelerator)obj);
- }
-
- bool Equals(Accelerator other)
- {
- return other.ToString() == ToString();
- }
-
- public override int GetHashCode()
- {
- return ToString().GetHashCode();
- }
-
- public static implicit operator Accelerator(string accelerator)
- {
- return FromString(accelerator);
- }
- }
-}
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class AcceleratorTypeConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value == null)
- return null;
-
- return Accelerator.FromString(value);
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Threading;
-using System.ComponentModel;
-using System.Threading.Tasks;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- internal class Application : Element, IResourcesProvider, IApplicationController, IElementConfiguration<Application>
- {
- static Application s_current;
- Task<IDictionary<string, object>> _propertiesTask;
- readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry;
-
- IAppIndexingProvider _appIndexProvider;
-
- ReadOnlyCollection<Element> _logicalChildren;
-
- Page _mainPage;
-
- static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
-
- public Application()
- {
- // var f = false;
- // if (f)
- // Loader.Load();
- NavigationProxy = new NavigationImpl(this);
- SetCurrentApplication(this);
-
- SystemResources = DependencyService.Get<ISystemResourcesProvider>()?.GetSystemResources();
- SystemResources.ValuesChanged += OnParentResourcesChanged;
- _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
- }
-
- public void Quit()
- {
- Device.PlatformServices?.QuitApplication();
- }
-
- public IAppLinks AppLinks
- {
- get
- {
- 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 Tizen.NUI.Binding.AppLinks");
- return _appIndexProvider.AppLinks;
- }
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void SetCurrentApplication(Application value) => Current = value;
-
- public static Application Current
- {
- get { return s_current; }
- set
- {
- if (s_current == value)
- return;
- if (value == null)
- s_current = null; //Allow to reset current for unittesting
- s_current = value;
- }
- }
-
- public Page MainPage
- {
- get { return _mainPage; }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
-
- if (_mainPage == value)
- return;
-
- OnPropertyChanging();
- if (_mainPage != null)
- {
- InternalChildren.Remove(_mainPage);
- _mainPage.Parent = null;
- }
-
- _mainPage = value;
-
- if (_mainPage != null)
- {
- _mainPage.Parent = this;
- _mainPage.NavigationProxy.Inner = NavigationProxy;
- InternalChildren.Add(_mainPage);
- }
- OnPropertyChanged();
- }
- }
-
- public IDictionary<string, object> Properties
- {
- get
- {
- if (_propertiesTask == null)
- {
- _propertiesTask = GetPropertiesAsync();
- }
-
- return _propertiesTask.Result;
- }
- }
-
- internal override ReadOnlyCollection<Element> LogicalChildrenInternal
- {
- get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public NavigationProxy NavigationProxy { get; }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int PanGestureId { get; set; }
-
- internal IResourceDictionary SystemResources { get; }
-
- ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SetAppIndexingProvider(IAppIndexingProvider provider)
- {
- _appIndexProvider = provider;
- }
-
- ResourceDictionary _resources;
- bool IResourcesProvider.IsResourcesCreated => _resources != null;
-
- public ResourceDictionary XamlResources
- {
- get
- {
- if (_resources != null)
- return _resources;
-
- _resources = new ResourceDictionary();
- ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
- return _resources;
- }
- set
- {
- if (_resources == value)
- return;
- OnPropertyChanging();
- if (_resources != null)
- ((IResourceDictionary)_resources).ValuesChanged -= OnResourcesChanged;
- _resources = value;
- OnResourcesChanged(value);
- if (_resources != null)
- ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
- OnPropertyChanged();
- }
- }
-
- public event EventHandler<ModalPoppedEventArgs> ModalPopped;
-
- public event EventHandler<ModalPoppingEventArgs> ModalPopping;
-
- public event EventHandler<ModalPushedEventArgs> ModalPushed;
-
- public event EventHandler<ModalPushingEventArgs> ModalPushing;
-
- public event EventHandler<Page> PageAppearing;
-
- public event EventHandler<Page> PageDisappearing;
-
-
- async void SaveProperties()
- {
- try
- {
- await SetPropertiesAsync();
- }
- catch (Exception exc)
- {
- Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}");
- }
- }
-
- public async Task SavePropertiesAsync()
- {
- if (Device.IsInvokeRequired)
- {
- Device.BeginInvokeOnMainThread(SaveProperties);
- }
- else
- {
- await SetPropertiesAsync();
- }
- }
-
- // Don't use this unless there really is no better option
- internal void SavePropertiesAsFireAndForget()
- {
- if (Device.IsInvokeRequired)
- {
- Device.BeginInvokeOnMainThread(SaveProperties);
- }
- else
- {
- SaveProperties();
- }
- }
-
- public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform
- {
- return _platformConfigurationRegistry.Value.On<T>();
- }
-
- protected virtual void OnAppLinkRequestReceived(Uri uri)
- {
- }
-
- protected override void OnParentSet()
- {
- throw new InvalidOperationException("Setting a Parent on Application is invalid.");
- }
-
- protected virtual void OnResume()
- {
- }
-
- protected virtual void OnSleep()
- {
- }
-
- protected virtual void OnStart()
- {
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void ClearCurrent()
- {
- s_current = null;
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static bool IsApplicationOrNull(Element element)
- {
- return element == null || element is Application;
- }
-
- internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
- {
- if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
- {
- base.OnParentResourcesChanged(values);
- return;
- }
-
- var innerKeys = new HashSet<string>();
- var changedResources = new List<KeyValuePair<string, object>>();
- foreach (KeyValuePair<string, object> c in XamlResources)
- innerKeys.Add(c.Key);
- foreach (KeyValuePair<string, object> value in values)
- {
- if (innerKeys.Add(value.Key))
- changedResources.Add(value);
- }
- OnResourcesChanged(changedResources);
- }
-
- internal event EventHandler PopCanceled;
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendOnAppLinkRequestReceived(Uri uri)
- {
- OnAppLinkRequestReceived(uri);
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendResume()
- {
- s_current = this;
- OnResume();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendSleep()
- {
- OnSleep();
- SavePropertiesAsFireAndForget();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Task SendSleepAsync()
- {
- OnSleep();
- return SavePropertiesAsync();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendStart()
- {
- OnStart();
- }
-
- async Task<IDictionary<string, object>> GetPropertiesAsync()
- {
- var deserializer = DependencyService.Get<IDeserializer>();
- if (deserializer == null)
- {
- Console.WriteLine("Startup", "No IDeserialzier was found registered");
- return new Dictionary<string, object>(4);
- }
-
- IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
- if (properties == null)
- properties = new Dictionary<string, object>(4);
-
- return properties;
- }
-
- internal void OnPageAppearing(Page page)
- => PageAppearing?.Invoke(this, page);
-
- internal void OnPageDisappearing(Page page)
- => PageDisappearing?.Invoke(this, page);
-
- void OnModalPopped(Page modalPage)
- => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage));
-
- bool OnModalPopping(Page modalPage)
- {
- var args = new ModalPoppingEventArgs(modalPage);
- ModalPopping?.Invoke(this, args);
- return args.Cancel;
- }
-
- void OnModalPushed(Page modalPage)
- => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage));
-
- void OnModalPushing(Page modalPage)
- => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage));
-
- void OnPopCanceled()
- => PopCanceled?.Invoke(this, EventArgs.Empty);
-
- async Task SetPropertiesAsync()
- {
- await SaveSemaphore.WaitAsync();
- try
- {
- await DependencyService.Get<IDeserializer>()?.SerializePropertiesAsync(Properties);
- }
- finally
- {
- SaveSemaphore.Release();
- }
-
- }
-
- class NavigationImpl : NavigationProxy
- {
- readonly Application _owner;
-
- public NavigationImpl(Application owner)
- {
- _owner = owner;
- }
-
- protected override async Task<Page> OnPopModal(bool animated)
- {
- Page modal = ModalStack[ModalStack.Count - 1];
- if (_owner.OnModalPopping(modal))
- {
- _owner.OnPopCanceled();
- return null;
- }
- Page result = await base.OnPopModal(animated);
- result.Parent = null;
- _owner.OnModalPopped(result);
- return result;
- }
-
- protected override async Task OnPushModal(Page modal, bool animated)
- {
- _owner.OnModalPushing(modal);
-
- modal.Parent = _owner;
-
- if (modal.NavigationProxy.ModalStack.Count == 0)
- {
- modal.NavigationProxy.Inner = this;
- await base.OnPushModal(modal, animated);
- }
- else
- {
- await base.OnPushModal(modal, animated);
- modal.NavigationProxy.Inner = this;
- }
-
- _owner.OnModalPushed(modal);
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class BaseMenuItem : Element
- {
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Linq.Expressions;
-
-namespace Tizen.NUI.Binding
-{
- internal static class BindableObjectExtensions
- {
- public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null,
- string stringFormat = null)
- {
- if (self == null)
- throw new ArgumentNullException("self");
- if (targetProperty == null)
- throw new ArgumentNullException("targetProperty");
-
- var binding = new Binding(path, mode, converter, stringFormat: stringFormat);
- self.SetBinding(targetProperty, binding);
- }
-
- [Obsolete]
- public static void SetBinding<TSource>(this BindableObject self, BindableProperty targetProperty, Expression<Func<TSource, object>> sourceProperty, BindingMode mode = BindingMode.Default,
- IValueConverter converter = null, string stringFormat = null)
- {
- if (self == null)
- throw new ArgumentNullException("self");
- if (targetProperty == null)
- throw new ArgumentNullException("targetProperty");
- if (sourceProperty == null)
- throw new ArgumentNullException("sourceProperty");
-
- Binding binding = Binding.Create(sourceProperty, mode, converter, stringFormat: stringFormat);
- self.SetBinding(targetProperty, binding);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.ComponentModel;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// A BindableProperty is a backing store for properties allowing bindings on BindableObject.
- /// </summary>
- [DebuggerDisplay("{PropertyName}")]
- [TypeConverter(typeof(BindablePropertyConverter))]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public sealed class BindableProperty
- {
- /// <summary>
- /// Delegate for BindableProperty.PropertyChanged.
- /// </summary>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="oldValue">The old property value.</param>
- /// <param name="newValue">The new property value.</param>
- public delegate void BindingPropertyChangedDelegate(BindableObject bindable, object oldValue, object newValue);
-
- /// <summary>
- /// Strongly-typed delegate for BindableProperty.PropertyChanged.
- /// </summary>
- /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="oldValue">The old property value.</param>
- /// <param name="newValue">The new property value.</param>
- public delegate void BindingPropertyChangedDelegate<in TPropertyType>(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue);
-
- /// <summary>
- /// Delegate for BindableProperty.PropertyChanging.
- /// </summary>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="oldValue">The old property value.</param>
- /// <param name="newValue">The new property value.</param>
- public delegate void BindingPropertyChangingDelegate(BindableObject bindable, object oldValue, object newValue);
-
- /// <summary>
- /// Strongly-typed delegate for BindableProperty.PropertyChanging.
- /// </summary>
- /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="oldValue">The old property value.</param>
- /// <param name="newValue">The new property value.</param>
- public delegate void BindingPropertyChangingDelegate<in TPropertyType>(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue);
-
- /// <summary>
- /// Delegate for BindableProperty.CoerceValue.
- /// </summary>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="value">The value to coerce.</param>
- /// <returns>System.Object</returns>
- public delegate object CoerceValueDelegate(BindableObject bindable, object value);
-
- /// <summary>
- /// Strongly-typed delegate for BindableProperty.CoerceValue.
- /// </summary>
- /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="value">The value to coerce.</param>
- /// <returns>TPropertyType</returns>
- public delegate TPropertyType CoerceValueDelegate<TPropertyType>(BindableObject bindable, TPropertyType value);
-
- /// <summary>
- /// Delegate for BindableProperty.DefaultValueCreator.
- /// </summary>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <returns>System.Object</returns>
- public delegate object CreateDefaultValueDelegate(BindableObject bindable);
-
- /// <summary>
- /// Strongly-typed delegate for BindableProperty.DefaultValueCreator.
- /// </summary>
- /// <typeparam name="TDeclarer">The type of the object that delared the property.</typeparam>
- /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <returns>TPropertyType</returns>
- public delegate TPropertyType CreateDefaultValueDelegate<in TDeclarer, out TPropertyType>(TDeclarer bindable);
-
- /// <summary>
- /// Delegate for BindableProperty.ValidateValue.
- /// </summary>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="value">The default value.</param>
- /// <returns>System.Boolean</returns>
- public delegate bool ValidateValueDelegate(BindableObject bindable, object value);
-
- /// <summary>
- /// Strongly-typed delegate for BindableProperty.ValidateValue.
- /// </summary>
- /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
- /// <param name="bindable">The bindable object that contains the property.</param>
- /// <param name="value">The default value.</param>
- /// <returns>System.Boolean</returns>
- public delegate bool ValidateValueDelegate<in TPropertyType>(BindableObject bindable, TPropertyType value);
-
- static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type,TypeConverter>
- {
- { 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() },
- };
-
- //Modification for NUI XAML : user defined converter for DynamicResource can be added
- static internal Dictionary<Type, TypeConverter> UserCustomConvertTypes = new Dictionary<Type, TypeConverter>
- {
- };
-
- // more or less the encoding of this, without the need to reflect
- // http://msdn.microsoft.com/en-us/library/y5b434w4.aspx
- static readonly Dictionary<Type, Type[]> SimpleConvertTypes = new Dictionary<Type, Type[]>
- {
- { typeof(sbyte), new[] { typeof(string), typeof(short), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(byte), new[] { typeof(string), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(short), new[] { typeof(string), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(ushort), new[] { typeof(string), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(int), new[] { typeof(string), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(uint), new[] { typeof(string), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(long), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(char), new[] { typeof(string), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
- { typeof(float), new[] { typeof(string), typeof(double) } },
- { typeof(ulong), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } }
- };
-
- BindableProperty(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
- ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
- CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- if (propertyName == null)
- throw new ArgumentNullException("propertyName");
- if (ReferenceEquals(returnType, null))
- throw new ArgumentNullException("returnType");
- if (ReferenceEquals(declaringType, null))
- throw new ArgumentNullException("declaringType");
-
- // don't use Enum.IsDefined as its redonkulously expensive for what it does
- if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime)
- throw new ArgumentException("Not a valid type of BindingMode", "defaultBindingMode");
- if (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.GetTypeInfo().IsValueType)
- throw new ArgumentException("Not a valid default value", "defaultValue");
- if (defaultValue != null && !returnType.IsInstanceOfType(defaultValue))
- throw new ArgumentException("Default value did not match return type", "defaultValue");
- if (defaultBindingMode == BindingMode.Default)
- defaultBindingMode = BindingMode.OneWay;
-
- PropertyName = propertyName;
- ReturnType = returnType;
- ReturnTypeInfo = returnType.GetTypeInfo();
- DeclaringType = declaringType;
- DefaultValue = defaultValue;
- DefaultBindingMode = defaultBindingMode;
- PropertyChanged = propertyChanged;
- PropertyChanging = propertyChanging;
- ValidateValue = validateValue;
- CoerceValue = coerceValue;
- BindingChanging = bindingChanging;
- IsReadOnly = isReadOnly;
- DefaultValueCreator = defaultValueCreator;
- }
-
- /// <summary>
- /// Gets the type declaring the BindableProperty.
- /// </summary>
- public Type DeclaringType { get; private set; }
-
- /// <summary>
- /// Gets the default BindingMode.
- /// </summary>
- public BindingMode DefaultBindingMode { get; private set; }
-
- /// <summary>
- /// Gets the default value for the BindableProperty.
- /// </summary>
- public object DefaultValue { get; }
-
- /// <summary>
- /// Gets a value indicating if the BindableProperty is created form a BindablePropertyKey.
- /// </summary>
- public bool IsReadOnly { get; private set; }
-
- /// <summary>
- /// Gets the property name.
- /// </summary>
- public string PropertyName { get; }
-
- /// <summary>
- /// Gets the type of the BindableProperty.
- /// </summary>
- public Type ReturnType { get; }
-
- internal BindablePropertyBindingChanging BindingChanging { get; private set; }
-
- internal CoerceValueDelegate CoerceValue { get; private set; }
-
- internal CreateDefaultValueDelegate DefaultValueCreator { get; }
-
- internal BindingPropertyChangedDelegate PropertyChanged { get; private set; }
-
- internal BindingPropertyChangingDelegate PropertyChanging { get; private set; }
-
- internal System.Reflection.TypeInfo ReturnTypeInfo { get; }
-
- internal ValidateValueDelegate ValidateValue { get; private set; }
-
- /// <summary>
- /// Deprecated. Do not use.
- /// </summary>
- /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
- /// <typeparam name="TPropertyType">The type of the property.</typeparam>
- /// <param name="getter">An expression identifying the getter for the property using this BindableProperty as backing store.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created BindableProperty.</returns>
- [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- public static BindableProperty Create<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
- ValidateValueDelegate<TPropertyType> validateValue = null, BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null,
- BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null, CoerceValueDelegate<TPropertyType> coerceValue = null,
- CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
- {
- return Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, defaultValueCreator: defaultValueCreator);
- }
-
- /// <summary>
- /// Creates a new instance of the BindableProperty class.
- /// </summary>
- /// <param name="propertyName">The name of the BindableProperty.</param>
- /// <param name="returnType">The type of the property.</param>
- /// <param name="declaringType">The type of the declaring object.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created BindableProperty.</returns>
- public static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay,
- ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
- CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue,
- defaultValueCreator: defaultValueCreator);
- }
-
- /// <summary>
- /// Deprecated. Do not use.
- /// </summary>
- /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
- /// <typeparam name="TPropertyType">The type of the property.</typeparam>
- /// <param name="staticgetter">An expression identifying a static method returning the value of the property using this BindableProperty as backing store.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- public static BindableProperty CreateAttached<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue,
- BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate<TPropertyType> validateValue = null, BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null,
- BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null, CoerceValueDelegate<TPropertyType> coerceValue = null,
- CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
- {
- return CreateAttached<TDeclarer, TPropertyType>(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null,
- defaultValueCreator: defaultValueCreator);
- }
-
- /// <summary>
- /// Creates a new instance of the BindableProperty class for an attached property.
- /// </summary>
- /// <param name="propertyName">The name of the BindableProperty.</param>
- /// <param name="returnType">The type of the property.</param>
- /// <param name="declaringType">The type of the declaring object.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created BindableProperty.</returns>
- public static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
- ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
- CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, false, defaultValueCreator);
- }
-
- /// <summary>
- /// Deprecated. Do not use.
- /// </summary>
- /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
- /// <typeparam name="TPropertyType">The type of the property.</typeparam>
- /// <param name="staticgetter">An expression identifying a static method returning the value of the property using this BindableProperty as backing store.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created attached read-only BindablePropertyKey.</returns>
- [Obsolete("CreateAttachedReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- public static BindablePropertyKey CreateAttachedReadOnly<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue,
- BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate<TPropertyType> validateValue = null,
- BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null,
- CoerceValueDelegate<TPropertyType> coerceValue = null, CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
-
- {
- return
- new BindablePropertyKey(CreateAttached<TDeclarer, TPropertyType>(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true,
- defaultValueCreator));
- }
-
- /// <summary>
- /// Creates a new instance of the BindableProperty class for attached read-only properties.
- /// </summary>
- /// <param name="propertyName">The name of the BindableProperty.</param>
- /// <param name="returnType">The type of the property.</param>
- /// <param name="declaringType">The type of the declaring object.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created attached read-only BindablePropertyKey.</returns>
- public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource,
- ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
- CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return
- new BindablePropertyKey(CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true,
- defaultValueCreator));
- }
-
- /// <summary>
- /// Deprecated. Do not use.
- /// </summary>
- /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
- /// <typeparam name="TPropertyType">The type of the property.</typeparam>
- /// <param name="getter">An expression identifying the getter for the property using this BindableProperty as backing store.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created BindablePropertyKey.</returns>
- [Obsolete("CreateReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- public static BindablePropertyKey CreateReadOnly<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue,
- BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate<TPropertyType> validateValue = null,
- BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null,
- CoerceValueDelegate<TPropertyType> coerceValue = null, CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
- {
- return new BindablePropertyKey(Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, defaultValueCreator));
- }
-
- /// <summary>
- /// Creates a new instance of the BindablePropertyKey class.
- /// </summary>
- /// <param name="propertyName">The name of the BindableProperty.</param>
- /// <param name="returnType">The type of the property.</param>
- /// <param name="declaringType">The type of the declaring object.</param>
- /// <param name="defaultValue">The default value for the property.</param>
- /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
- /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
- /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
- /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
- /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
- /// <returns>A newly created BindablePropertyKey.</returns>
- public static BindablePropertyKey CreateReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource,
- ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
- CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return
- new BindablePropertyKey(new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue,
- isReadOnly: true, defaultValueCreator: defaultValueCreator));
- }
-
- [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- internal static BindableProperty Create<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue, BindingMode defaultBindingMode,
- ValidateValueDelegate<TPropertyType> validateValue, BindingPropertyChangedDelegate<TPropertyType> propertyChanged, BindingPropertyChangingDelegate<TPropertyType> propertyChanging,
- CoerceValueDelegate<TPropertyType> coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false,
- CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
- {
- if (getter == null)
- throw new ArgumentNullException("getter");
-
- Expression expr = getter.Body;
-
- var unary = expr as UnaryExpression;
- if (unary != null)
- expr = unary.Operand;
-
- var member = expr as MemberExpression;
- if (member == null)
- throw new ArgumentException("getter must be a MemberExpression", "getter");
-
- var property = (PropertyInfo)member.Member;
-
- ValidateValueDelegate untypedValidateValue = null;
- BindingPropertyChangedDelegate untypedBindingPropertyChanged = null;
- BindingPropertyChangingDelegate untypedBindingPropertyChanging = null;
- CoerceValueDelegate untypedCoerceValue = null;
- CreateDefaultValueDelegate untypedDefaultValueCreator = null;
- if (validateValue != null)
- untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value);
- if (propertyChanged != null)
- untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
- if (propertyChanging != null)
- untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
- if (coerceValue != null)
- untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value);
- if (defaultValueCreator != null)
- untypedDefaultValueCreator = o => defaultValueCreator((TDeclarer)o);
-
- return new BindableProperty(property.Name, property.PropertyType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged,
- untypedBindingPropertyChanging, untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator);
- }
-
- internal static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue,
- BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging,
- CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging,
- defaultValueCreator: defaultValueCreator);
- }
-
- [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
- internal static BindableProperty CreateAttached<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue, BindingMode defaultBindingMode,
- ValidateValueDelegate<TPropertyType> validateValue, BindingPropertyChangedDelegate<TPropertyType> propertyChanged, BindingPropertyChangingDelegate<TPropertyType> propertyChanging,
- CoerceValueDelegate<TPropertyType> coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false,
- CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
- {
- if (staticgetter == null)
- throw new ArgumentNullException("staticgetter");
-
- Expression expr = staticgetter.Body;
-
- var unary = expr as UnaryExpression;
- if (unary != null)
- expr = unary.Operand;
-
- var methodcall = expr as MethodCallExpression;
- if (methodcall == null)
- throw new ArgumentException("staticgetter must be a MethodCallExpression", "staticgetter");
-
- MethodInfo method = methodcall.Method;
- if (!method.Name.StartsWith("Get", StringComparison.Ordinal))
- throw new ArgumentException("staticgetter name must start with Get", "staticgetter");
-
- string propertyname = method.Name.Substring(3);
-
- ValidateValueDelegate untypedValidateValue = null;
- BindingPropertyChangedDelegate untypedBindingPropertyChanged = null;
- BindingPropertyChangingDelegate untypedBindingPropertyChanging = null;
- CoerceValueDelegate untypedCoerceValue = null;
- CreateDefaultValueDelegate untypedDefaultValueCreator = null;
- if (validateValue != null)
- untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value);
- if (propertyChanged != null)
- untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
- if (propertyChanging != null)
- untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
- if (coerceValue != null)
- untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value);
- if (defaultValueCreator != null)
- untypedDefaultValueCreator = o => defaultValueCreator(o);
-
- return new BindableProperty(propertyname, method.ReturnType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, untypedBindingPropertyChanging,
- untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator);
- }
-
- internal static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue,
- BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging,
- bool isReadOnly, CreateDefaultValueDelegate defaultValueCreator = null)
- {
- return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, isReadOnly,
- defaultValueCreator);
- }
-
- internal object GetDefaultValue(BindableObject bindable)
- {
- if (DefaultValueCreator != null)
- return DefaultValueCreator(bindable);
-
- return DefaultValue;
- }
-
- internal bool TryConvert(ref object value)
- {
- if (value == null)
- {
- return !ReturnTypeInfo.IsValueType || ReturnTypeInfo.IsGenericType && ReturnTypeInfo.GetGenericTypeDefinition() == typeof(Nullable<>);
- }
-
- Type valueType = value.GetType();
- Type type = ReturnType;
-
- // Dont support arbitrary IConvertible by limiting which types can use this
- Type[] convertableTo;
- TypeConverter typeConverterTo;
- if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1)
- {
- value = Convert.ChangeType(value, type);
- }
- else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType))
- {
- value = typeConverterTo.ConvertFromInvariantString(value.ToString());
- }
- else if (UserCustomConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType))
- {
- //Modification for NUI XAML : user defined converter for DynamicResource can be added
- value = typeConverterTo.ConvertFromInvariantString(value.ToString());
- }
- else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo()))
- {
- var cast = type.GetImplicitConversionOperator(fromType: valueType, toType: type)
- ?? valueType.GetImplicitConversionOperator(fromType: valueType, toType: type);
-
- if (cast == null)
- return false;
-
- value = cast.Invoke(null, new[] { value });
- }
-
- return true;
- }
-
- internal delegate void BindablePropertyBindingChanging(BindableObject bindable, BindingBase oldValue, BindingBase newValue);
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Linq;
-using System.Reflection;
-using System.Xml;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindablePropertyConverter")]
- [Xaml.TypeConversion(typeof(BindableProperty))]
- internal sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter
- {
- object IExtendedTypeConverter.ConvertFrom(CultureInfo culture, object value, IServiceProvider serviceProvider)
- {
- return ((IExtendedTypeConverter)this).ConvertFromInvariantString(value as string, serviceProvider);
- }
-
- object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
- {
- if (string.IsNullOrWhiteSpace(value))
- return null;
- if (serviceProvider == null)
- return null;
- var parentValuesProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
- var typeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
- if (typeResolver == null)
- return null;
- IXmlLineInfo lineinfo = null;
- var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- if (xmlLineInfoProvider != null)
- lineinfo = xmlLineInfoProvider.XmlLineInfo;
- string[] parts = value.Split('.');
- Type type = null;
- if (parts.Length == 1)
- {
- if (parentValuesProvider == null)
- {
- string msg = string.Format("Can't resolve {0}", parts[0]);
- throw new XamlParseException(msg, lineinfo);
- }
- object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault();
- if (parentValuesProvider.TargetObject is Setter)
- {
- var style = parent as Style;
- var triggerBase = parent as TriggerBase;
- var visualState = parent as VisualState;
- if (style != null)
- type = style.TargetType;
- else if (triggerBase != null)
- type = triggerBase.TargetType;
- else if (visualState != null)
- type = FindTypeForVisualState(parentValuesProvider, lineinfo);
- }
- else if (parentValuesProvider.TargetObject is Trigger)
- type = (parentValuesProvider.TargetObject as Trigger).TargetType;
- else if (parentValuesProvider.TargetObject is XamlPropertyCondition && (parent as TriggerBase) != null)
- type = (parent as TriggerBase).TargetType;
-
- if (type == null)
- throw new XamlParseException($"Can't resolve {parts [0]}", lineinfo);
-
- return ConvertFrom(type, parts[0], lineinfo);
- }
- if (parts.Length == 2)
- {
- if (!typeResolver.TryResolve(parts[0], out type))
- {
- string msg = string.Format("Can't resolve {0}", parts[0]);
- throw new XamlParseException(msg, lineinfo);
- }
- return ConvertFrom(type, parts[1], lineinfo);
- }
- throw new XamlParseException($"Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyName.", lineinfo);
- }
-
- public override object ConvertFromInvariantString(string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- return null;
- if (value.Contains(":"))
- {
- Console.WriteLine(null, "Can't resolve properties with xml namespace prefix.");
- return null;
- }
- string[] parts = value.Split('.');
- if (parts.Length != 2)
- {
- Console.WriteLine(null, $"Can't resolve {value}. Accepted syntax is Type.PropertyName.");
- return null;
- }
- Type type = Type.GetType("Tizen.NUI." + parts[0]);
- return ConvertFrom(type, parts[1], null);
- }
-
- BindableProperty ConvertFrom(Type type, string propertyName, IXmlLineInfo lineinfo)
- {
- string name = propertyName + "Property";
- FieldInfo bpinfo = type.GetField(fi => fi.Name == name && fi.IsStatic && fi.IsPublic && fi.FieldType == typeof(BindableProperty));
- if (bpinfo == null)
- throw new XamlParseException($"Can't resolve {name} on {type.Name}", lineinfo);
- var bp = bpinfo.GetValue(null) as BindableProperty;
- var isObsolete = bpinfo.GetCustomAttribute<ObsoleteAttribute>() != null;
- if (bp != null && bp.PropertyName != propertyName && !isObsolete)
- throw new XamlParseException($"The PropertyName of {type.Name}.{name} is not {propertyName}", lineinfo);
- return bp;
- }
-
- Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)
- {
- var parents = parentValueProvider.ParentObjects.ToList();
-
- // Skip 0; we would not be making this check if TargetObject were not a Setter
- // Skip 1; we would not be making this check if the immediate parent were not a VisualState
-
- // VisualStates must be in a VisualStateGroup
- if(!(parents[2] is VisualStateGroup)) {
- throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo);
- }
-
- var vsTarget = parents[3];
-
- // Are these Visual States directly on a VisualElement?
- if (vsTarget is /*VisualElement*/BaseHandle)
- {
- return vsTarget.GetType();
- }
-
- if (!(parents[3] is VisualStateGroupList))
- {
- throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
- }
-
- if (!(parents[4] is Setter))
- {
- throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
- }
-
- // These must be part of a Style; verify that
- if (!(parents[5] is Style style))
- {
- throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo);
- }
-
- return style.TargetType;
- }
- }
-}
+++ /dev/null
-using System;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// The secret key to a BindableProperty, used to implement a BindableProperty with restricted write access.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public sealed class BindablePropertyKey
- {
- internal BindablePropertyKey(BindableProperty property)
- {
- if (property == null)
- throw new ArgumentNullException("property");
-
- BindableProperty = property;
- }
-
- /// <summary>
- /// Gets the BindableProperty.
- /// </summary>
- public BindableProperty BindableProperty { get; private set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Globalization;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.Text;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- internal sealed class Binding : BindingBase
- {
- internal const string SelfPath = ".";
- IValueConverter _converter;
- object _converterParameter;
-
- BindingExpression _expression;
- string _path;
- object _source;
- string _updateSourceEventName;
-
- public Binding()
- {
- }
-
- public Binding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null)
- {
- if (path == null)
- throw new ArgumentNullException("path");
- if (string.IsNullOrWhiteSpace(path))
- throw new ArgumentException("path can not be an empty string", "path");
-
- Path = path;
- Converter = converter;
- ConverterParameter = converterParameter;
- Mode = mode;
- StringFormat = stringFormat;
- Source = source;
- }
-
- public IValueConverter Converter
- {
- get { return _converter; }
- set
- {
- ThrowIfApplied();
-
- _converter = value;
- }
- }
-
- public object ConverterParameter
- {
- get { return _converterParameter; }
- set
- {
- ThrowIfApplied();
-
- _converterParameter = value;
- }
- }
-
- public string Path
- {
- get { return _path; }
- set
- {
- ThrowIfApplied();
-
- _path = value;
- _expression = new BindingExpression(this, !string.IsNullOrWhiteSpace(value) ? value : SelfPath);
- }
- }
-
- public object Source
- {
- get { return _source; }
- set
- {
- ThrowIfApplied();
- _source = value;
- }
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string UpdateSourceEventName {
- get { return _updateSourceEventName; }
- set {
- ThrowIfApplied();
- _updateSourceEventName = value;
- }
- }
-
- [Obsolete]
- public static Binding Create<TSource>(Expression<Func<TSource, object>> propertyGetter, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null,
- string stringFormat = null)
- {
- if (propertyGetter == null)
- throw new ArgumentNullException("propertyGetter");
-
- return new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat);
- }
-
- internal override void Apply(bool fromTarget)
- {
- base.Apply(fromTarget);
-
- if (_expression == null)
- _expression = new BindingExpression(this, SelfPath);
-
- _expression.Apply(fromTarget);
- }
-
- internal override void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
- {
- object src = _source;
- var isApplied = IsApplied;
-
- base.Apply(src ?? newContext, bindObj, targetProperty, fromBindingContextChanged: fromBindingContextChanged);
-
- if (src != null && isApplied && fromBindingContextChanged)
- return;
-
- object bindingContext = src ?? Context ?? newContext;
- if (_expression == null && bindingContext != null)
- _expression = new BindingExpression(this, SelfPath);
-
- _expression?.Apply(bindingContext, bindObj, targetProperty);
- }
-
- internal override BindingBase Clone()
- {
- return new Binding(Path, Mode) { Converter = Converter, ConverterParameter = ConverterParameter, StringFormat = StringFormat, Source = Source, UpdateSourceEventName = UpdateSourceEventName };
- }
-
- internal override object GetSourceValue(object value, Type targetPropertyType)
- {
- if (Converter != null)
- value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
-
- return base.GetSourceValue(value, targetPropertyType);
- }
-
- internal override object GetTargetValue(object value, Type sourcePropertyType)
- {
- if (Converter != null)
- value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
-
- return base.GetTargetValue(value, sourcePropertyType);
- }
-
- internal override void Unapply(bool fromBindingContextChanged = false)
- {
- if (Source != null && fromBindingContextChanged && IsApplied)
- return;
-
- base.Unapply(fromBindingContextChanged: fromBindingContextChanged);
-
- if (_expression != null)
- _expression.Unapply();
- }
-
- [Obsolete]
- static string GetBindingPath<TSource>(Expression<Func<TSource, object>> propertyGetter)
- {
- Expression expr = propertyGetter.Body;
-
- var unary = expr as UnaryExpression;
- if (unary != null)
- expr = unary.Operand;
-
- var builder = new StringBuilder();
-
- var indexed = false;
-
- var member = expr as MemberExpression;
- if (member == null)
- {
- var methodCall = expr as MethodCallExpression;
- if (methodCall != null)
- {
- if (methodCall.Arguments.Count == 0)
- throw new ArgumentException("Method calls are not allowed in binding expression");
-
- var arguments = new List<string>(methodCall.Arguments.Count);
- foreach (Expression arg in methodCall.Arguments)
- {
- if (arg.NodeType != ExpressionType.Constant)
- throw new ArgumentException("Only constants can be used as indexer arguments");
-
- object value = ((ConstantExpression)arg).Value;
- arguments.Add(value != null ? value.ToString() : "null");
- }
-
- Type declarerType = methodCall.Method.DeclaringType;
- DefaultMemberAttribute defaultMember = declarerType.GetTypeInfo().GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType<DefaultMemberAttribute>().FirstOrDefault();
- string indexerName = defaultMember != null ? defaultMember.MemberName : "Item";
-
- MethodInfo getterInfo =
- declarerType.GetProperties().Where(pi => (pi.GetMethod != null) && pi.Name == indexerName && pi.CanRead && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic).Select(pi => pi.GetMethod).FirstOrDefault();
- if (getterInfo != null)
- {
- if (getterInfo == methodCall.Method)
- {
- indexed = true;
- builder.Append("[");
-
- var first = true;
- foreach (string argument in arguments)
- {
- if (!first)
- builder.Append(",");
-
- builder.Append(argument);
- first = false;
- }
-
- builder.Append("]");
-
- member = methodCall.Object as MemberExpression;
- }
- else
- throw new ArgumentException("Method calls are not allowed in binding expressions");
- }
- else
- throw new ArgumentException("Public indexer not found");
- }
- else
- throw new ArgumentException("Invalid expression type");
- }
-
- while (member != null)
- {
- var property = (PropertyInfo)member.Member;
- if (builder.Length != 0)
- {
- if (!indexed)
- builder.Insert(0, ".");
- else
- indexed = false;
- }
-
- builder.Insert(0, property.Name);
-
- // member = member.Expression as MemberExpression ?? (member.Expression as UnaryExpression)?.Operand as MemberExpression;
- member = member.Expression as MemberExpression ?? (member.Expression is UnaryExpression ? (member.Expression as UnaryExpression).Operand as MemberExpression : null);
- }
-
- return builder.ToString();
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections;
-using System.Runtime.CompilerServices;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// An abstract class that provides a BindingMode and a formatting option.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal abstract class BindingBase
- {
- static readonly ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext> SynchronizedCollections = new ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext>();
-
- BindingMode _mode = BindingMode.Default;
- string _stringFormat;
- object _targetNullValue;
- object _fallbackValue;
-
- internal BindingBase()
- {
- }
-
- /// <summary>
- /// Gets or sets the mode for this binding.
- /// </summary>
- public BindingMode Mode
- {
- get { return _mode; }
- set
- {
- if ( value != BindingMode.Default
- && value != BindingMode.OneWay
- && value != BindingMode.OneWayToSource
- && value != BindingMode.TwoWay
- && value != BindingMode.OneTime)
- throw new ArgumentException("mode is not a valid BindingMode", "mode");
-
- ThrowIfApplied();
-
- _mode = value;
- }
- }
-
- /// <summary>
- /// Gets or sets the string format for this binding.
- /// </summary>
- public string StringFormat
- {
- get { return _stringFormat; }
- set
- {
- ThrowIfApplied();
-
- _stringFormat = value;
- }
- }
-
- 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; }
-
- internal bool IsApplied { get; private set; }
-
- /// <summary>
- /// Stops synchronization on the collection.
- /// </summary>
- /// <param name="collection">The collection on which to stop synchronization.</param>
- public static void DisableCollectionSynchronization(IEnumerable collection)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
-
- SynchronizedCollections.Remove(collection);
- }
-
- public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
- if (callback == null)
- throw new ArgumentNullException(nameof(callback));
-
- SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
- }
-
- /// <summary>
- /// Throws an InvalidOperationException if the binding has been applied.
- /// </summary>
- protected void ThrowIfApplied()
- {
- if (IsApplied)
- throw new InvalidOperationException("Can not change a binding while it's applied");
- }
-
- internal virtual void Apply(bool fromTarget)
- {
- IsApplied = true;
- }
-
- internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
- {
- IsApplied = true;
- }
-
- internal abstract BindingBase Clone();
-
- internal virtual object GetSourceValue(object value, Type targetPropertyType)
- {
- if (value == null && TargetNullValue != null)
- return TargetNullValue;
- if (StringFormat != null)
- return string.Format(StringFormat, value);
-
- return value;
- }
-
- internal virtual object GetTargetValue(object value, Type sourcePropertyType)
- {
- return value;
- }
-
- internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
-
- return SynchronizedCollections.TryGetValue(collection, out synchronizationContext);
- }
-
- internal virtual void Unapply(bool fromBindingContextChanged = false)
- {
- IsApplied = false;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// The direction of changes propagation for bindings.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public enum BindingMode
- {
- /// <summary>
- /// When used in Bindings, indicates that the Binding should use the DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay.
- /// </summary>
- Default,
-
- /// <summary>
- /// Indicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions.
- /// </summary>
- TwoWay,
-
- /// <summary>
- /// Indicates that the binding should only propagate changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values.
- /// </summary>
- OneWay,
-
- /// <summary>
- /// Indicates that the binding should only propagate changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values.
- /// </summary>
- OneWayToSource,
-
- /// <summary>
- /// Indicates that the binding will be applied only when the binding context changes and the value will not be monitored for changes with INotifyPropertyChanged.
- /// </summary>
- OneTime,
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindingTypeConverter")]
- [Xaml.TypeConversion(typeof(Binding))]
- internal sealed class BindingTypeConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- return new Binding(value);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections;
-
-namespace Tizen.NUI.Binding
-{
- internal delegate void CollectionSynchronizationCallback(IEnumerable collection, object context, Action accessMethod, bool writeAccess);
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Globalization;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ColorTypeConverter")]
- [Xaml.TypeConversion(typeof(Color))]
- internal class ColorTypeConverter : TypeConverter
- {
- // Supported inputs
- // HEX #rgb, #argb, #rrggbb, #aarrggbb
- // float array 0.5,0.5,0.5,0.5
- // Predefined color case insensitive
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null)
- {
- value = value.Trim();
- if (value.StartsWith("#", StringComparison.Ordinal))
- {
- return FromHex(value);
- }
-
- string[] parts = value.Split(',');
- if (parts.Length == 1) //like Red or Color.Red
- {
- parts = value.Split('.');
- if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Color"))
- {
- string color = parts[parts.Length - 1];
- switch (color)
- {
- case "Black": return Color.Black;
- case "White": return Color.White;
- case "Red": return Color.Red;
- case "Green": return Color.Green;
- case "Blue": return Color.Blue;
- case "Yellow": return Color.Yellow;
- case "Magenta": return Color.Magenta;
- case "Cyan": return Color.Cyan;
- case "Transparent": return Color.Transparent;
- }
- }
- }
- else if (parts.Length == 4) //like 0.5,0.5,0.5,0.5
- {
- 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));
- }
- }
-
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Color)}");
- }
-
- static uint ToHex(char c)
- {
- ushort x = (ushort)c;
- if (x >= '0' && x <= '9')
- return (uint)(x - '0');
-
- x |= 0x20;
- if (x >= 'a' && x <= 'f')
- return (uint)(x - 'a' + 10);
- return 0;
- }
-
- static uint ToHexD(char c)
- {
- var j = ToHex(c);
- return (j << 4) | j;
- }
-
- public static Color FromRgba(int r, int g, int b, int a)
- {
- float red = (float)r / 255;
- float green = (float)g / 255;
- float blue = (float)b / 255;
- float alpha = (float)a / 255;
- return new Color(red, green, blue, alpha);
- }
-
- public static Color FromRgb(int r, int g, int b)
- {
- return FromRgba(r, g, b, 255);
- }
-
- static Color FromHex(string hex)
- {
- // Undefined
- if (hex.Length < 3)
- return Color.Black;
- int idx = (hex[0] == '#') ? 1 : 0;
-
- switch (hex.Length - idx)
- {
- case 3: //#rgb => ffrrggbb
- var t1 = ToHexD(hex[idx++]);
- var t2 = ToHexD(hex[idx++]);
- var t3 = ToHexD(hex[idx]);
-
- return FromRgb((int)t1, (int)t2, (int)t3);
-
- case 4: //#argb => aarrggbb
- var f1 = ToHexD(hex[idx++]);
- var f2 = ToHexD(hex[idx++]);
- var f3 = ToHexD(hex[idx++]);
- var f4 = ToHexD(hex[idx]);
- return FromRgba((int)f2, (int)f3, (int)f4, (int)f1);
-
- case 6: //#rrggbb => ffrrggbb
- return FromRgb((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
- (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
- (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])));
-
- case 8: //#aarrggbb
- var a1 = ToHex(hex[idx++]) << 4 | ToHex(hex[idx++]);
- return FromRgba((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
- (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
- (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])),
- (int)a1);
-
- default: //everything else will result in unexpected results
- return Color.Black;
- }
- }
- }
-}
+++ /dev/null
-
-namespace Tizen.NUI.Binding
-{
- internal class Configuration<TPlatform, TElement> : IPlatformElementConfiguration<TPlatform, TElement>
- where TPlatform : IConfigPlatform
- where TElement : Element
-
- {
- public Configuration(TElement element)
- {
- Element = element;
- }
-
- public TElement Element { get; }
-
- public static Configuration<TPlatform, TElement> Create(TElement element)
- {
- return new Configuration<TPlatform, TElement>(element);
- }
- }
-}
catch (System.IO.FileNotFoundException)
{
// Sometimes the previewer doesn't actually have everything required for these loads to work
- Console.WriteLine(nameof(Registrar), "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, targetAttrType.FullName);
+ Tizen.Log.Fatal("NUI", "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, targetAttrType.FullName);
continue;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public static DeviceInfo info;
- static IPlatformServices s_platformServices;
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetIdiom(TargetIdiom value) => Idiom = value;
public static TargetIdiom Idiom { get; internal set; }
}
#pragma warning restore 0618
- public static string RuntimePlatform => PlatformServices?.RuntimePlatform;
+ public static string RuntimePlatform => null;
[EditorBrowsable(EditorBrowsableState.Never)]
public static DeviceInfo Info
public static void SetFlowDirection(FlowDirection value) => FlowDirection = value;
public static FlowDirection FlowDirection { get; internal set; }
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static bool IsInvokeRequired
- {
- get { return PlatformServices.IsInvokeRequired; }
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static IPlatformServices PlatformServices
- {
- get
- {
- if (s_platformServices == null)
- throw new InvalidOperationException("You MUST call Tizen.NUI.Init(); prior to using it.");
- return s_platformServices;
- }
- set
- {
- s_platformServices = value;
- Console.WriteLine("Device s_platformServices : " + s_platformServices );
- }
- }
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static IReadOnlyList<string> Flags { get; private set; }
public static void BeginInvokeOnMainThread(Action action)
{
- PlatformServices?.BeginInvokeOnMainThread(action);
action();
Console.WriteLine("Device BeginInvokeOnMainThread action called");
}
// return GetNamedSize(size, targetElementType, false);
// }
- [Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
- public static void OnPlatform(Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null)
- {
- switch (OS)
- {
- case TargetPlatform.iOS:
- if (iOS != null)
- iOS();
- else if (Default != null)
- Default();
- break;
- case TargetPlatform.Android:
- if (Android != null)
- Android();
- else if (Default != null)
- Default();
- break;
- case TargetPlatform.Windows:
- case TargetPlatform.WinPhone:
- if (WinPhone != null)
- WinPhone();
- else if (Default != null)
- Default();
- break;
- case TargetPlatform.Other:
- if (Default != null)
- Default();
- break;
- }
- }
-
[Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
public static T OnPlatform<T>(T iOS, T Android, T WinPhone)
{
// PlatformServices?.OpenUriAction(uri);
}
- public static void StartTimer(TimeSpan interval, Func<bool> callback)
- {
- PlatformServices.StartTimer(interval, callback);
- }
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static Assembly[] GetAssemblies()
{
- return PlatformServices?.GetAssemblies();
+ return null;
}
// [EditorBrowsable(EditorBrowsableState.Never)]
// return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
// }
- internal static Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
- {
- return PlatformServices?.GetStreamAsync(uri, cancellationToken);
- }
-
public static class Styles
{
public static readonly string TitleStyleKey = "TitleStyle";
+++ /dev/null
-using System;
-using System.ComponentModel;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// A collection of styles and properties that can be added to an element at run time.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal abstract class Effect
- {
- internal Effect()
- {
- }
-
- /// <summary>
- /// Gets the element to which the style is attached.
- /// </summary>
- public Element Element { get; internal set; }
-
- /// <summary>
- /// Gets a value that tells whether the effect is attached to an element.
- /// </summary>
- public bool IsAttached { get; private set; }
-
- /// <summary>
- /// Gets the ID that is used to resolve this effect at runtime.
- /// </summary>
- public string ResolveId { get; internal set; }
-
- #region Statics
- /// <summary>
- /// Returns an Effect for the specified name, which is of the form ResolutionGroupName.ExportEffect.
- /// </summary>
- /// <param name="name">The name of the effect to get.</param>
- /// <returns>The uniquely identified effect.</returns>
- public static Effect Resolve(string name)
- {
- Effect result = null;
- if (Tizen.NUI.Binding.Internals.Registrar.Effects.TryGetValue(name, out Type effectType))
- {
- result = (Effect)DependencyResolver.ResolveOrCreate(effectType);
- }
-
- if (result == null)
- result = new NullEffect();
- result.ResolveId = name;
- return result;
- }
-
- #endregion
-
- /// <summary>
- /// Method that is called after the effect is attached and made valid.
- /// </summary>
- protected abstract void OnAttached();
-
- /// <summary>
- /// Method that is called after the effect is detached and invalidated.
- /// </summary>
- protected abstract void OnDetached();
-
- internal virtual void ClearEffect()
- {
- if (IsAttached)
- SendDetached();
- Element = null;
- }
-
- internal virtual void SendAttached()
- {
- if (IsAttached)
- return;
- OnAttached();
- IsAttached = true;
- }
-
- internal virtual void SendDetached()
- {
- if (!IsAttached)
- return;
- OnDetached();
- IsAttached = false;
- }
-
- internal virtual void SendOnElementPropertyChanged(PropertyChangedEventArgs args)
- {
- }
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [Flags]
- internal enum EffectiveFlowDirection
- {
- RightToLeft = 1 << 0,
- Explicit = 1 << 1,
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.ComponentModel;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal static class EffectiveFlowDirectionExtensions
- {
- internal static EffectiveFlowDirection ToEffectiveFlowDirection(this FlowDirection self, bool isExplicit = false)
- {
- switch (self)
- {
- case FlowDirection.MatchParent:
- return default(EffectiveFlowDirection);
-
-
- case FlowDirection.LeftToRight:
- if (isExplicit)
- {
- return EffectiveFlowDirection.Explicit;
- }
- else
- {
- return default(EffectiveFlowDirection);
- }
-
- case FlowDirection.RightToLeft:
- if (isExplicit)
- {
- return EffectiveFlowDirection.RightToLeft | EffectiveFlowDirection.Explicit;
- }
- else
- {
- return EffectiveFlowDirection.RightToLeft;
- }
-
- default:
- throw new InvalidOperationException($"Cannot convert {self} to {nameof(EffectiveFlowDirection)}.");
- }
- }
-
- internal static FlowDirection ToFlowDirection(this EffectiveFlowDirection self)
- {
- if (self.IsLeftToRight())
- return FlowDirection.LeftToRight;
- else
- return FlowDirection.RightToLeft;
-
- throw new InvalidOperationException($"Cannot convert {self} to {nameof(FlowDirection)}.");
- }
-
- public static bool IsRightToLeft(this EffectiveFlowDirection self)
- {
- return (self & EffectiveFlowDirection.RightToLeft) == EffectiveFlowDirection.RightToLeft;
- }
-
- public static bool IsLeftToRight(this EffectiveFlowDirection self)
- {
- return (self & EffectiveFlowDirection.RightToLeft) != EffectiveFlowDirection.RightToLeft;
- }
-
- public static bool IsImplicit(this EffectiveFlowDirection self)
- {
- return (self & EffectiveFlowDirection.Explicit) != EffectiveFlowDirection.Explicit;
- }
-
- public static bool IsExplicit(this EffectiveFlowDirection self)
- {
- return (self & EffectiveFlowDirection.Explicit) == EffectiveFlowDirection.Explicit;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Collections.ObjectModel;
-
-namespace Tizen.NUI.Binding
-{
- internal class ElementCollection<T> : ObservableWrapper<Element, T> where T : Element
- {
- public ElementCollection(ObservableCollection<Element> list) : base(list)
- {
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal class ElementEventArgs : EventArgs
- {
- public ElementEventArgs(Element element)
- {
- if (element == null)
- throw new ArgumentNullException("element");
-
- Element = element;
- }
-
- public Element Element { get; private set; }
- }
-}
+++ /dev/null
-using System.Threading.Tasks;
-
-namespace Tizen.NUI.Binding
-{
- [TypeConverter(typeof(FileImageSourceConverter))]
- internal sealed class FileImageSource : ImageSource
- {
- public static readonly BindableProperty FileProperty = BindableProperty.Create("File", typeof(string), typeof(FileImageSource), default(string));
-
- public string File
- {
- get { return (string)GetValue(FileProperty); }
- set { SetValue(FileProperty, value); }
- }
-
- public override Task<bool> Cancel()
- {
- return Task.FromResult(false);
- }
-
- public override string ToString()
- {
- return $"File: {File}";
- }
-
- public static implicit operator FileImageSource(string file)
- {
- return (FileImageSource)FromFile(file);
- }
-
- public static implicit operator string(FileImageSource file)
- {
- return file != null ? file.File : null;
- }
-
- protected override void OnPropertyChanged(string propertyName = null)
- {
- if (propertyName == FileProperty.PropertyName)
- OnSourceChanged();
- base.OnPropertyChanged(propertyName);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.TypeConversion(typeof(FileImageSource))]
- internal sealed class FileImageSourceConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null)
- return (FileImageSource)ImageSource.FromFile(value);
-
- throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FileImageSource)));
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface IAppIndexingProvider
- {
- IAppLinks AppLinks { get; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- internal interface IAppLinkEntry
- {
- Uri AppLinkUri { get; set; }
-
- string Description { get; set; }
-
- bool IsLinkActive { get; set; }
-
- IDictionary<string, string> KeyValues { get; }
-
- ImageSource Thumbnail { get; set; }
-
- string Title { get; set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal interface IAppLinks
- {
- void DeregisterLink(IAppLinkEntry appLink);
- void DeregisterLink(Uri appLinkUri);
- void RegisterLink(IAppLinkEntry appLink);
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface IApplicationController
- {
- void SetAppIndexingProvider(IAppIndexingProvider appIndexing);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// When implemented in a renderer, registers a platform-specific effect on an element.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal interface IEffectControlProvider
- {
- /// <summary>
- /// Registers the effect with the element by establishing the parent-child relations needed for rendering on the specific platform.
- /// </summary>
- /// <param name="effect">The effect to register.</param>
- void RegisterEffect(Effect effect);
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal interface ILayout
- {
- event EventHandler LayoutChanged;
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- internal interface ILayoutController
- {
- IReadOnlyList<Element> Children { get; }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface IMenuItemController
- {
- bool IsEnabled { get; set; }
- string IsEnabledPropertyName { get; }
-
- void Activate();
- }
-}
+++ /dev/null
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// Interface abstracting platform-specific navigation.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal interface INavigation
- {
- /// <summary>
- /// Gets the modal navigation stack.
- /// </summary>
- IReadOnlyList<Page> ModalStack { get; }
-
- /// <summary>
- /// Gets the stack of pages in the navigation.
- /// </summary>
- IReadOnlyList<Page> NavigationStack { get; }
-
- /// <summary>
- /// Inserts a page in the navigation stack before an existing page in the stack.
- /// </summary>
- /// <param name="page">The page to add.</param>
- /// <param name="before">The existing page, before which page will be inserted.</param>
- void InsertPageBefore(Page page, Page before);
-
- /// <summary>
- /// Asynchronously removes the most recent Page from the navigation stack.
- /// </summary>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- Task<Page> PopAsync();
-
- /// <summary>
- /// Asynchronously removes the most recent Page from the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- Task<Page> PopAsync(bool animated);
-
- /// <summary>
- /// Asynchronously dismisses the most recent modally presented Page.
- /// </summary>
- /// <returns>An awaitable instance, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped.</returns>
- Task<Page> PopModalAsync();
-
- /// <summary>
- /// Asynchronously dismisses the most recent modally presented Page, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>An awaitable, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped.</returns>
- Task<Page> PopModalAsync(bool animated);
-
- /// <summary>
- /// Pops all but the root Page off the navigation stack.
- /// </summary>
- /// <returns>A task representing the asynchronous dismiss operation.</returns>
- Task PopToRootAsync();
-
- /// <summary>
- /// Pops all but the root Page off the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>A task representing the asynchronous dismiss operation.</returns>
- Task PopToRootAsync(bool animated);
-
- /// <summary>
- /// Asynchronously adds a Page to the top of the navigation stack.
- /// </summary>
- /// <param name="page">The Page to be pushed on top of the navigation stack.</param>
- /// <returns>A task that represents the asynchronous push operation.</returns>
- Task PushAsync(Page page);
-
- /// <summary>
- /// Asynchronously adds a Page to the top of the navigation stack, with optional animation.
- /// </summary>
- /// <param name="page">The page to push.</param>
- /// <param name="animated">Whether to animate the push.</param>
- /// <returns>A task that represents the asynchronous push operation.</returns>
- Task PushAsync(Page page, bool animated);
-
- /// <summary>
- /// Presents a Page modally.
- /// </summary>
- /// <param name="page">The Page to present modally.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- Task PushModalAsync(Page page);
-
- /// <summary>
- /// Presents a Page modally, with optional animation.
- /// </summary>
- /// <param name="page">The page to push.</param>
- /// <param name="animated">Whether to animate the push.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- Task PushModalAsync(Page page, bool animated);
-
- /// <summary>
- /// Removes the specified page from the navigation stack.
- /// </summary>
- /// <param name="page">The page to remove.</param>
- void RemovePage(Page page);
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface INavigationMenuController : IViewController
- {
- void SendTargetSelected(Page target);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- internal interface INavigationPageController
- {
- Task<Page> RemoveAsyncInner(Page page, bool animated, bool fast);
-
- Page Peek(int depth = 0);
-
- IEnumerable<Page> Pages { get; }
-
- int StackDepth { get; }
-
- Task<Page> PopAsyncInner(bool animated, bool fast = false);
-
- event EventHandler<NavigationRequestedEventArgs> InsertPageBeforeRequested;
-
- event EventHandler<NavigationRequestedEventArgs> PopRequested;
-
- event EventHandler<NavigationRequestedEventArgs> PopToRootRequested;
-
- event EventHandler<NavigationRequestedEventArgs> PushRequested;
-
- event EventHandler<NavigationRequestedEventArgs> RemovePageRequested;
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- interface IPaddingElement
- {
- //note to implementor: implement this property publicly
- // Thickness Padding { get; }
-
- //note to implementor: but implement this method explicitly
- void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue);
- Thickness PaddingDefaultValueCreator();
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal interface IPlatform
- {
- /// <summary>
- /// Returns the native size.
- /// </summary>
- /// <param name="view">The view</param>
- /// <param name="widthConstraint">The width constraint.</param>
- /// <param name="heightConstraint">The height constraint.</param>
- /// <returns>The native size.</returns>
- SizeRequest GetNativeSize(BaseHandle view, double widthConstraint, double heightConstraint);
- }
-}
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// Marker interface for returning platform-specific configuration elements.
- /// </summary>
- /// <typeparam name="TPlatform">The platform type.</typeparam>
- /// <typeparam name="TElement">The element type.</typeparam>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal interface IPlatformElementConfiguration<out TPlatform, out TElement> : IConfigElement<TElement>
- where TPlatform : IConfigPlatform
- where TElement : Element
- {
- }
-}
void BeginInvokeOnMainThread(Action action);
- Ticker CreateTicker();
-
Assembly[] GetAssemblies();
string GetMD5Hash(string input);
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface IRegisterable
- {
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- //this will go once Timer is included in Pcl profiles
- internal interface ITimer
- {
- void Change(int dueTime, int period);
- void Change(long dueTime, long period);
- void Change(TimeSpan dueTime, TimeSpan period);
- void Change(uint dueTime, uint period);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- internal interface IViewContainer<T> where T : /*VisualElement*/BaseHandle
- {
- IList<T> Children { get; }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal interface IViewController : IVisualElementController
- {
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- internal interface IVisualElementController : IElementController
- {
- void NativeSizeChanged();
- void InvalidateMeasure(InvalidationTrigger trigger);
- bool Batched { get; }
- bool DisableLayout { get; set; }
- EffectiveFlowDirection EffectiveFlowDirection { get; }
- bool IsInNativeLayout { get; set; }
- bool IsNativeStateConsistent { get; set; }
- bool IsPlatformEnabled { get; set; }
- NavigationProxy NavigationProxy { get; }
- event EventHandler<EventArg</*VisualElement*/BaseHandle>> BatchCommitted;
- event EventHandler<BaseHandle.FocusRequestArgs> FocusChangeRequested;
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.IO;
-using System.Reflection;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Tizen.NUI.Binding
-{
- [TypeConverter(typeof(ImageSourceConverter))]
- internal abstract class ImageSource : Element
- {
- readonly object _synchandle = new object();
- CancellationTokenSource _cancellationTokenSource;
-
- TaskCompletionSource<bool> _completionSource;
-
- readonly WeakEventManager _weakEventManager = new WeakEventManager();
-
- protected ImageSource()
- {
- }
-
- protected CancellationTokenSource CancellationTokenSource
- {
- get { return _cancellationTokenSource; }
- private set
- {
- if (_cancellationTokenSource == value)
- return;
- if (_cancellationTokenSource != null)
- _cancellationTokenSource.Cancel();
- _cancellationTokenSource = value;
- }
- }
-
- bool IsLoading
- {
- get { return _cancellationTokenSource != null; }
- }
-
- public virtual Task<bool> Cancel()
- {
- if (!IsLoading)
- return Task.FromResult(false);
-
- var tcs = new TaskCompletionSource<bool>();
- TaskCompletionSource<bool> original = Interlocked.CompareExchange(ref _completionSource, tcs, null);
- if (original == null)
- {
- _cancellationTokenSource.Cancel();
- }
- else
- tcs = original;
-
- return tcs.Task;
- }
-
- public static ImageSource FromFile(string file)
- {
- return new FileImageSource { File = file };
- }
-
- public static ImageSource FromResource(string resource, Type resolvingType)
- {
- return FromResource(resource, resolvingType.GetTypeInfo().Assembly);
- }
-
- public static ImageSource FromResource(string resource, Assembly sourceAssembly = null)
- {
-#if NETSTANDARD2_0
- sourceAssembly = sourceAssembly ?? Assembly.GetCallingAssembly();
-#else
- if (sourceAssembly == null)
- {
- MethodInfo callingAssemblyMethod = typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetCallingAssembly");
- if (callingAssemblyMethod != null)
- {
- sourceAssembly = (Assembly)callingAssemblyMethod.Invoke(null, new object[0]);
- }
- else
- {
- Internals.Log.Warning("Warning", "Can not find CallingAssembly, pass resolvingType to FromResource to ensure proper resolution");
- return null;
- }
- }
-#endif
- return FromStream(() => sourceAssembly.GetManifestResourceStream(resource));
- }
-
- public static ImageSource FromStream(Func<Stream> stream)
- {
- // return new StreamImageSource { Stream = token => Task.Run(stream, token) };
- return null;
- }
-
- public static ImageSource FromUri(Uri uri)
- {
- if (!uri.IsAbsoluteUri)
- throw new ArgumentException("uri is relative");
- // return new UriImageSource { Uri = uri };
- return null;
- }
-
- public static implicit operator ImageSource(string source)
- {
- Uri uri;
- return Uri.TryCreate(source, UriKind.Absolute, out uri) && uri.Scheme != "file" ? FromUri(uri) : FromFile(source);
- }
-
- public static implicit operator ImageSource(Uri uri)
- {
- if (!uri.IsAbsoluteUri)
- throw new ArgumentException("uri is relative");
- return FromUri(uri);
- }
-
- protected void OnLoadingCompleted(bool cancelled)
- {
- if (!IsLoading || _completionSource == null)
- return;
-
- TaskCompletionSource<bool> tcs = Interlocked.Exchange(ref _completionSource, null);
- if (tcs != null)
- tcs.SetResult(cancelled);
-
- lock (_synchandle)
- {
- CancellationTokenSource = null;
- }
- }
-
- protected void OnLoadingStarted()
- {
- lock (_synchandle)
- {
- CancellationTokenSource = new CancellationTokenSource();
- }
- }
-
- protected void OnSourceChanged()
- {
- _weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(SourceChanged));
- }
-
- internal event EventHandler SourceChanged
- {
- add { _weakEventManager.AddEventHandler(nameof(SourceChanged), value); }
- remove { _weakEventManager.RemoveEventHandler(nameof(SourceChanged), value); }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.TypeConversion(typeof(ImageSource))]
- internal sealed class ImageSourceConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null)
- {
- Uri uri;
- return Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme != "file" ? ImageSource.FromUri(uri) : ImageSource.FromFile(value);
- }
-
- throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(ImageSource)));
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Reflection;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class Behavior : BindableObject, IAttachedObject
- {
- internal Behavior(Type associatedType)
- {
- if (associatedType == null)
- throw new ArgumentNullException("associatedType");
- AssociatedType = associatedType;
- }
-
- protected Type AssociatedType { get; }
-
- void IAttachedObject.AttachTo(BindableObject bindable)
- {
- if (bindable == null)
- throw new ArgumentNullException("bindable");
- if (!AssociatedType.IsInstanceOfType(bindable))
- throw new InvalidOperationException("bindable not an instance of AssociatedType");
- OnAttachedTo(bindable);
- }
-
- void IAttachedObject.DetachFrom(BindableObject bindable)
- {
- OnDetachingFrom(bindable);
- }
-
- protected virtual void OnAttachedTo(BindableObject bindable)
- {
- }
-
- protected virtual void OnDetachingFrom(BindableObject bindable)
- {
- }
- }
-
- internal abstract class Behavior<T> : Behavior where T : BindableObject
- {
- protected Behavior() : base(typeof(T))
- {
- }
-
- protected override void OnAttachedTo(BindableObject bindable)
- {
- base.OnAttachedTo(bindable);
- OnAttachedTo((T)bindable);
- }
-
- protected virtual void OnAttachedTo(T bindable)
- {
- }
-
- protected override void OnDetachingFrom(BindableObject bindable)
- {
- OnDetachingFrom((T)bindable);
- base.OnDetachingFrom(bindable);
- }
-
- protected virtual void OnDetachingFrom(T bindable)
- {
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
- [AcceptEmptyServiceProvider]
- internal sealed class BindingCondition : Condition, IValueProvider
- {
- readonly BindableProperty _boundProperty;
-
- BindingBase _binding;
- object _triggerValue;
-
- public BindingCondition()
- {
- _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged);
- }
-
- public BindingBase Binding
- {
- get { return _binding; }
- set
- {
- if (_binding == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Binding once the Condition has been applied.");
- _binding = value;
- }
- }
-
- public object Value
- {
- get { return _triggerValue; }
- set
- {
- if (_triggerValue == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Value once the Condition has been applied.");
- _triggerValue = value;
- }
- }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- //This is no longer required
- return this;
- }
-
- internal override bool GetState(BindableObject bindable)
- {
- object newValue = bindable.GetValue(_boundProperty);
- return EqualsToValue(newValue);
- }
-
- internal override void SetUp(BindableObject bindable)
- {
- if (Binding != null)
- bindable.SetBinding(_boundProperty, Binding.Clone());
- }
-
- internal override void TearDown(BindableObject bindable)
- {
- bindable.RemoveBinding(_boundProperty);
- bindable.ClearValue(_boundProperty);
- }
-
- static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
-
- bool EqualsToValue(object other)
- {
- if ((other == Value) || (other != null && other.Equals(Value)))
- return true;
-
- object converted = null;
- if (s_valueConverter != null)
- converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null);
- else
- return false;
-
- return (other == converted) || (other != null && other.Equals(converted));
- }
-
- void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
- {
- bool oldState = EqualsToValue(oldValue);
- bool newState = EqualsToValue(newValue);
-
- if (newState == oldState)
- return;
-
- if (ConditionChanged != null)
- ConditionChanged(bindable, oldState, newState);
- }
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class Condition
- {
- Action<BindableObject, bool, bool> _conditionChanged;
-
- bool _isSealed;
-
- internal Condition()
- {
- }
-
- internal Action<BindableObject, bool, bool> ConditionChanged
- {
- get { return _conditionChanged; }
- set
- {
- if (_conditionChanged == value)
- return;
- if (_conditionChanged != null)
- throw new InvalidOperationException("The same condition instance can not be reused");
- _conditionChanged = value;
- }
- }
-
- internal bool IsSealed
- {
- get { return _isSealed; }
- set
- {
- if (_isSealed == value)
- return;
- if (!value)
- throw new InvalidOperationException("What is sealed can not be unsealed.");
- _isSealed = value;
- OnSealed();
- }
- }
-
- internal abstract bool GetState(BindableObject bindable);
-
- internal virtual void OnSealed()
- {
- }
-
- internal abstract void SetUp(BindableObject bindable);
- internal abstract void TearDown(BindableObject bindable);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Setters")]
- [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
- [AcceptEmptyServiceProvider]
- internal sealed class DataTrigger : TriggerBase, IValueProvider
- {
- public DataTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new BindingCondition(), targetType)
- {
- }
-
- public BindingBase Binding
- {
- get { return ((BindingCondition)Condition).Binding; }
- set
- {
- if (((BindingCondition)Condition).Binding == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Binding once the Trigger has been applied.");
- OnPropertyChanging();
- ((BindingCondition)Condition).Binding = value;
- OnPropertyChanged();
- }
- }
-
- public new IList<Setter> Setters
- {
- get { return base.Setters; }
- }
-
- public object Value
- {
- get { return ((BindingCondition)Condition).Value; }
- set
- {
- if (((BindingCondition)Condition).Value == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
- OnPropertyChanging();
- ((BindingCondition)Condition).Value = value;
- OnPropertyChanged();
- }
- }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- //This is no longer required
- return this;
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Tizen.NUI.Binding.Internals;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Actions")]
- internal sealed class EventTrigger : TriggerBase
- {
- static readonly MethodInfo s_handlerinfo = typeof(EventTrigger).GetRuntimeMethods().Single(mi => mi.Name == "OnEventTriggered" && mi.IsPublic == false);
- readonly List<BindableObject> _associatedObjects = new List<BindableObject>();
-
- EventInfo _eventinfo;
-
- string _eventname;
- Delegate _handlerdelegate;
-
- public EventTrigger() : base(typeof(BindableObject))
- {
- Actions = new SealedList<TriggerAction>();
- }
-
- public IList<TriggerAction> Actions { get; }
-
- public string Event
- {
- get { return _eventname; }
- set
- {
- if (_eventname == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Event cannot be changed once the Trigger has been applied");
- OnPropertyChanging();
- _eventname = value;
- OnPropertyChanged();
- }
- }
-
- internal override void OnAttachedTo(BindableObject bindable)
- {
- base.OnAttachedTo(bindable);
- if (!string.IsNullOrEmpty(Event))
- AttachHandlerTo(bindable);
- _associatedObjects.Add(bindable);
- }
-
- internal override void OnDetachingFrom(BindableObject bindable)
- {
- _associatedObjects.Remove(bindable);
- DetachHandlerFrom(bindable);
- base.OnDetachingFrom(bindable);
- }
-
- internal override void OnSeal()
- {
- base.OnSeal();
- ((SealedList<TriggerAction>)Actions).IsReadOnly = true;
- }
-
- void AttachHandlerTo(BindableObject bindable)
- {
- try
- {
- _eventinfo = bindable.GetType().GetRuntimeEvent(Event);
- _handlerdelegate = s_handlerinfo.CreateDelegate(_eventinfo?.EventHandlerType, this);
- }
- catch (Exception)
- {
- Console.WriteLine("EventTrigger", "Can not attach EventTrigger to {0}.{1}. Check if the handler exists and if the signature is right.", bindable.GetType(), Event);
- }
- if (_eventinfo != null && _handlerdelegate != null)
- _eventinfo.AddEventHandler(bindable, _handlerdelegate);
- }
-
- void DetachHandlerFrom(BindableObject bindable)
- {
- if (_eventinfo != null && _handlerdelegate != null)
- _eventinfo.RemoveEventHandler(bindable, _handlerdelegate);
- }
-
- // [Preserve]
- void OnEventTriggered(object sender, EventArgs e)
- {
- var bindable = (BindableObject)sender;
- foreach (TriggerAction action in Actions)
- action.DoInvoke(bindable);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Setters")]
- internal sealed class MultiTrigger : TriggerBase
- {
- public MultiTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new MultiCondition(), targetType)
- {
- }
-
- public IList<Condition> Conditions
- {
- get { return ((MultiCondition)Condition).Conditions; }
- }
-
- public new IList<Setter> Setters
- {
- get { return base.Setters; }
- }
- }
-}
\ No newline at end of file
+++ /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
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Setters")]
- [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
- [AcceptEmptyServiceProvider]
- internal sealed class Trigger : TriggerBase, IValueProvider
- {
- public Trigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new XamlPropertyCondition(), targetType)
- {
- }
-
- public BindableProperty Property
- {
- get { return ((XamlPropertyCondition)Condition).Property; }
- set
- {
- if (((XamlPropertyCondition)Condition).Property == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
- OnPropertyChanging();
- ((XamlPropertyCondition)Condition).Property = value;
- OnPropertyChanged();
- }
- }
-
- public new IList<Setter> Setters
- {
- get { return base.Setters; }
- }
-
- public object Value
- {
- get { return ((XamlPropertyCondition)Condition).Value; }
- set
- {
- if (((XamlPropertyCondition)Condition).Value == value)
- return;
- if (IsSealed)
- throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
- OnPropertyChanging();
- ((XamlPropertyCondition)Condition).Value = value;
- OnPropertyChanged();
- }
- }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- //This is no longer required
- return this;
- }
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class TriggerAction
- {
- internal TriggerAction(Type associatedType)
- {
- if (associatedType == null)
- throw new ArgumentNullException("associatedType");
- AssociatedType = associatedType;
- }
-
- protected Type AssociatedType { get; private set; }
-
- protected abstract void Invoke(object sender);
-
- internal virtual void DoInvoke(object sender)
- {
- Invoke(sender);
- }
- }
-
- internal abstract class TriggerAction<T> : TriggerAction where T : BindableObject
- {
- protected TriggerAction() : base(typeof(T))
- {
- }
-
- protected override void Invoke(object sender)
- {
- Invoke((T)sender);
- }
-
- protected abstract void Invoke(T sender);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class TriggerBase : BindableObject, IAttachedObject
- {
- bool _isSealed;
-
- internal TriggerBase(Type targetType)
- {
- if (targetType == null)
- throw new ArgumentNullException("targetType");
- TargetType = targetType;
-
- EnterActions = new SealedList<TriggerAction>();
- ExitActions = new SealedList<TriggerAction>();
- }
-
- internal TriggerBase(Condition condition, Type targetType) : this(targetType)
- {
- Setters = new SealedList<Setter>();
- Condition = condition;
- Condition.ConditionChanged = OnConditionChanged;
- }
-
- public IList<TriggerAction> EnterActions { get; }
-
- public IList<TriggerAction> ExitActions { get; }
-
- public bool IsSealed
- {
- get { return _isSealed; }
- private set
- {
- if (_isSealed == value)
- return;
- if (!value)
- throw new InvalidOperationException("What is sealed can not be unsealed.");
- _isSealed = value;
- OnSeal();
- }
- }
-
- public Type TargetType { get; }
-
- internal Condition Condition { get; }
-
- //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger
- internal IList<Setter> Setters { get; }
-
- void IAttachedObject.AttachTo(BindableObject bindable)
- {
- IsSealed = true;
-
- if (bindable == null)
- throw new ArgumentNullException("bindable");
- if (!TargetType.IsInstanceOfType(bindable))
- throw new InvalidOperationException("bindable not an instance of AssociatedType");
- OnAttachedTo(bindable);
- }
-
- void IAttachedObject.DetachFrom(BindableObject bindable)
- {
- if (bindable == null)
- throw new ArgumentNullException("bindable");
- OnDetachingFrom(bindable);
- }
-
- internal virtual void OnAttachedTo(BindableObject bindable)
- {
- if (Condition != null)
- Condition.SetUp(bindable);
- }
-
- internal virtual void OnDetachingFrom(BindableObject bindable)
- {
- if (Condition != null)
- Condition.TearDown(bindable);
- }
-
- internal virtual void OnSeal()
- {
- ((SealedList<TriggerAction>)EnterActions).IsReadOnly = true;
- ((SealedList<TriggerAction>)ExitActions).IsReadOnly = true;
- if (Setters != null)
- ((SealedList<Setter>)Setters).IsReadOnly = true;
- if (Condition != null)
- Condition.IsSealed = true;
- }
-
- void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)
- {
- if (newValue)
- {
- foreach (TriggerAction action in EnterActions)
- action.DoInvoke(bindable);
- foreach (Setter setter in Setters)
- setter.Apply(bindable);
- }
- else
- {
- foreach (Setter setter in Setters)
- setter.UnApply(bindable);
- foreach (TriggerAction action in ExitActions)
- action.DoInvoke(bindable);
- }
- }
-
- internal class SealedList<T> : IList<T>
- {
- readonly IList<T> _actual;
-
- bool _isReadOnly;
-
- public SealedList()
- {
- _actual = new List<T>();
- }
-
- public void Add(T item)
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- _actual.Add(item);
- }
-
- public void Clear()
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- _actual.Clear();
- }
-
- public bool Contains(T item)
- {
- return _actual.Contains(item);
- }
-
- public void CopyTo(T[] array, int arrayIndex)
- {
- _actual.CopyTo(array, arrayIndex);
- }
-
- public int Count
- {
- get { return _actual.Count; }
- }
-
- public bool IsReadOnly
- {
- get { return _isReadOnly; }
- set
- {
- if (_isReadOnly == value)
- return;
- if (!value)
- throw new InvalidOperationException("Can't change this back to non readonly");
- _isReadOnly = value;
- }
- }
-
- public bool Remove(T item)
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- return _actual.Remove(item);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)_actual).GetEnumerator();
- }
-
- public IEnumerator<T> GetEnumerator()
- {
- return _actual.GetEnumerator();
- }
-
- public int IndexOf(T item)
- {
- return _actual.IndexOf(item);
- }
-
- public void Insert(int index, T item)
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- _actual.Insert(index, item);
- }
-
- public T this[int index]
- {
- get { return _actual[index]; }
- set
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- _actual[index] = value;
- }
- }
-
- public void RemoveAt(int index)
- {
- if (IsReadOnly)
- throw new InvalidOperationException("This list is ReadOnly");
- _actual.RemoveAt(index);
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.ComponentModel;
-using System.Reflection;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")]
- [AcceptEmptyServiceProvider]
- internal sealed class XamlPropertyCondition : Condition, IValueProvider
- {
- readonly BindableProperty _stateProperty;
-
- BindableProperty _property;
- object _triggerValue;
-
- public XamlPropertyCondition()
- {
- _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), 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);
- _triggerValue = s_valueConverter.Convert(value, _property.ReturnType, minforetriever, null);
- }
- else
- {
- _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);
- }
- }
-}
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding.Internals
-{
- internal class DynamicResource
- {
- public DynamicResource(string key)
- {
- Key = key;
- }
-
- public string Key { get; private set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.ComponentModel;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding.Internals
-{
- internal interface IDynamicResourceHandler
- {
- void SetDynamicResource(BindableProperty property, string key);
- }
-}
+++ /dev/null
-using System;
-using System.ComponentModel;
-using System.Xml;
-
-namespace Tizen.NUI.Binding.Internals
-{
- internal interface INameScope
- {
- object FindByName(string name);
- void RegisterName(string name, object scopedElement);
- void UnregisterName(string name);
- [Obsolete]void RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo);
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Xml;
-using Tizen.NUI.Binding;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding.Internals
-{
- internal class NameScope : INameScope
- {
- public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope));
-
- readonly Dictionary<string, object> _names = new Dictionary<string, object>();
-
- object INameScope.FindByName(string name)
- {
- if (_names.ContainsKey(name))
- return _names[name];
- return null;
- }
-
- void INameScope.RegisterName(string name, object scopedElement)
- {
- if (_names.ContainsKey(name))
- throw new ArgumentException("An element with the same key already exists in NameScope", "name");
-
- _names[name] = scopedElement;
- }
-
- [Obsolete]
- void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo)
- {
- try
- {
- ((INameScope)this).RegisterName(name, scopedElement);
- }
- catch (ArgumentException)
- {
- throw new XamlParseException(string.Format("An element with the name \"{0}\" already exists in this NameScope", name), xmlLineInfo);
- }
- }
-
- void INameScope.UnregisterName(string name)
- {
- _names.Remove(name);
- }
-
- public static INameScope GetNameScope(BindableObject bindable)
- {
- return (INameScope)bindable.GetValue(NameScopeProperty);
- }
-
- public static void SetNameScope(BindableObject bindable, INameScope value)
- {
- bindable.SetValue(NameScopeProperty, value);
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Linq;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding.Internals
-{
- internal abstract class Ticker
- {
- static Ticker s_ticker;
- readonly Stopwatch _stopwatch;
- readonly List<Tuple<int, Func<long, bool>>> _timeouts;
-
- int _count;
- bool _enabled;
-
- protected Ticker()
- {
- _count = 0;
- _timeouts = new List<Tuple<int, Func<long, bool>>>();
-
- _stopwatch = new Stopwatch();
- }
-
- public static void SetDefault(Ticker ticker) => Default = ticker;
- public static Ticker Default
- {
- internal set { s_ticker = value; }
- get { return s_ticker ?? (s_ticker = Device.PlatformServices.CreateTicker()); }
- }
-
- public virtual int Insert(Func<long, bool> timeout)
- {
- _count++;
- _timeouts.Add(new Tuple<int, Func<long, bool>>(_count, timeout));
-
- if (!_enabled)
- {
- _enabled = true;
- Enable();
- }
-
- return _count;
- }
-
- public virtual void Remove(int handle)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- _timeouts.RemoveAll(t => t.Item1 == handle);
-
- if (!_timeouts.Any())
- {
- _enabled = false;
- Disable();
- }
- });
- }
-
- protected abstract void DisableTimer();
-
- protected abstract void EnableTimer();
-
- protected void SendSignals(int timestep = -1)
- {
- long step = timestep >= 0 ? timestep : _stopwatch.ElapsedMilliseconds;
- _stopwatch.Reset();
- _stopwatch.Start();
-
- var localCopy = new List<Tuple<int, Func<long, bool>>>(_timeouts);
- foreach (Tuple<int, Func<long, bool>> timeout in localCopy)
- {
- bool remove = !timeout.Item2(step);
- if (remove)
- _timeouts.RemoveAll(t => t.Item1 == timeout.Item1);
- }
-
- if (!_timeouts.Any())
- {
- _enabled = false;
- Disable();
- }
- }
-
- void Disable()
- {
- _stopwatch.Reset();
- DisableTimer();
- }
-
- void Enable()
- {
- _stopwatch.Start();
- EnableTimer();
- }
- }
-}
+++ /dev/null
-#define DO_NOT_CHECK_FOR_BINDING_REUSE
-
-using System;
-using System.ComponentModel;
-using System.Globalization;
-using System.Collections.Generic;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding.Internals
-{
- //FIXME: need a better name for this, and share with Binding, so we can share more unittests
- internal abstract class TypedBindingBase : BindingBase
- {
- IValueConverter _converter;
- object _converterParameter;
- object _source;
- string _updateSourceEventName;
-
- public IValueConverter Converter {
- get { return _converter; }
- set {
- ThrowIfApplied();
- _converter = value;
- }
- }
-
- public object ConverterParameter {
- get { return _converterParameter; }
- set {
- ThrowIfApplied();
- _converterParameter = value;
- }
- }
-
- public object Source {
- get { return _source; }
- set {
- ThrowIfApplied();
- _source = value;
- }
- }
-
- internal string UpdateSourceEventName {
- get { return _updateSourceEventName; }
- set {
- ThrowIfApplied();
- _updateSourceEventName = value;
- }
- }
-
- internal TypedBindingBase()
- {
- }
- }
-
- internal sealed class TypedBinding<TSource, TProperty> : TypedBindingBase
- {
- readonly Func<TSource, TProperty> _getter;
- readonly Action<TSource, TProperty> _setter;
- readonly PropertyChangedProxy [] _handlers;
-
- public TypedBinding(Func<TSource, TProperty> getter, Action<TSource, TProperty> setter, Tuple<Func<TSource, object>, string> [] handlers)
- {
- if (getter == null)
- throw new ArgumentNullException(nameof(getter));
-
- _getter = getter;
- _setter = setter;
-
- if (handlers == null)
- return;
-
- _handlers = new PropertyChangedProxy [handlers.Length];
- for (var i = 0; i < handlers.Length; i++)
- _handlers [i] = new PropertyChangedProxy(handlers [i].Item1, handlers [i].Item2, this);
- }
-
- readonly WeakReference<object> _weakSource = new WeakReference<object>(null);
- readonly WeakReference<BindableObject> _weakTarget = new WeakReference<BindableObject>(null);
- BindableProperty _targetProperty;
-
- // Applies the binding to a previously set source and target.
- internal override void Apply(bool fromTarget = false)
- {
- base.Apply(fromTarget);
-
- BindableObject target;
-#if DO_NOT_CHECK_FOR_BINDING_REUSE
- if (!_weakTarget.TryGetTarget(out target))
- throw new InvalidOperationException();
-#else
- if (!_weakTarget.TryGetTarget(out target) || target == null) {
- Unapply();
- return;
- }
-#endif
- object source;
- if (_weakSource.TryGetTarget(out source) && source != null)
- ApplyCore(source, target, _targetProperty, fromTarget);
- }
-
- // Applies the binding to a new source or target.
- internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
- {
- _targetProperty = targetProperty;
- var source = Source ?? Context ?? context;
- var isApplied = IsApplied;
-
- if (Source != null && isApplied && fromBindingContextChanged)
- return;
-
- base.Apply(source, bindObj, targetProperty, fromBindingContextChanged);
-
-#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
- BindableObject prevTarget;
- if (_weakTarget.TryGetTarget(out prevTarget) && !ReferenceEquals(prevTarget, bindObj))
- throw new InvalidOperationException("Binding instances can not be reused");
-
- object previousSource;
- if (_weakSource.TryGetTarget(out previousSource) && !ReferenceEquals(previousSource, source))
- throw new InvalidOperationException("Binding instances can not be reused");
-#endif
- _weakSource.SetTarget(source);
- _weakTarget.SetTarget(bindObj);
-
- ApplyCore(source, bindObj, targetProperty);
- }
-
- internal override BindingBase Clone()
- {
- Tuple<Func<TSource, object>, string> [] handlers = _handlers == null ? null : new Tuple<Func<TSource, object>, string> [_handlers.Length];
- if (handlers != null) {
- for (var i = 0; i < _handlers.Length; i++)
- handlers [i] = new Tuple<Func<TSource, object>, string>(_handlers [i].PartGetter, _handlers [i].PropertyName);
- }
- return new TypedBinding<TSource, TProperty>(_getter, _setter, handlers) {
- Mode = Mode,
- Converter = Converter,
- ConverterParameter = ConverterParameter,
- StringFormat = StringFormat,
- Source = Source,
- UpdateSourceEventName = UpdateSourceEventName,
- };
- }
-
- internal override object GetSourceValue(object value, Type targetPropertyType)
- {
- if (Converter != null)
- value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
-
- //return base.GetSourceValue(value, targetPropertyType);
- if (StringFormat != null)
- return string.Format(StringFormat, value);
-
- return value;
- }
-
- internal override object GetTargetValue(object value, Type sourcePropertyType)
- {
- if (Converter != null)
- value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
-
- //return base.GetTargetValue(value, sourcePropertyType);
- return value;
- }
-
- internal override void Unapply(bool fromBindingContextChanged = false)
- {
- if (Source != null && fromBindingContextChanged && IsApplied)
- return;
-
-#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
- base.Unapply(fromBindingContextChanged:fromBindingContextChanged);
-#endif
- if (_handlers != null)
- Unsubscribe();
-
-#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
- _weakSource.SetTarget(null);
- _weakTarget.SetTarget(null);
-#endif
- }
-
- // ApplyCore is as slim as it should be:
- // Setting 100000 values : 17ms.
- // ApplyCore 100000 (w/o INPC, w/o unnapply) : 20ms.
- internal void ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget = false)
- {
- var isTSource = sourceObject != null && sourceObject is TSource;
- var mode = this.GetRealizedMode(property);
- if ((mode == BindingMode.OneWay || mode == BindingMode.OneTime) && fromTarget)
- return;
-
- var needsGetter = (mode == BindingMode.TwoWay && !fromTarget) || mode == BindingMode.OneWay || mode == BindingMode.OneTime;
-
- if (isTSource && (mode == BindingMode.OneWay || mode == BindingMode.TwoWay) && _handlers != null)
- Subscribe((TSource)sourceObject);
-
- if (needsGetter) {
- var value = property.DefaultValue;
- if (isTSource) {
- try {
- value = GetSourceValue(_getter((TSource)sourceObject), property.ReturnType);
- } catch (Exception ex) when (ex is NullReferenceException || ex is KeyNotFoundException) {
- }
- }
- if (!TryConvert(ref value, property, property.ReturnType, true)) {
- // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType);
- return;
- }
- target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false);
- return;
- }
-
- var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource;
- if (needsSetter && _setter != null && isTSource) {
- var value = GetTargetValue(target.GetValue(property), typeof(TProperty));
- if (!TryConvert(ref value, property, typeof(TProperty), false)) {
- // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, typeof(TProperty));
- return;
- }
- _setter((TSource)sourceObject, (TProperty)value);
- }
- }
-
- static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget)
- {
- if (value == null)
- return true;
- if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value)))
- return true;
-
- object original = value;
- try {
- value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture);
- return true;
- } catch (Exception ex ) when (ex is InvalidCastException || ex is FormatException||ex is OverflowException) {
- value = original;
- return false;
- }
- }
-
- class PropertyChangedProxy
- {
- public Func<TSource, object> PartGetter { get; }
- public string PropertyName { get; }
- public BindingExpression.WeakPropertyChangedProxy Listener { get; }
- WeakReference<INotifyPropertyChanged> _weakPart = new WeakReference<INotifyPropertyChanged>(null);
- readonly BindingBase _binding;
-
- public INotifyPropertyChanged Part {
- get {
- INotifyPropertyChanged target;
- if (_weakPart.TryGetTarget(out target))
- return target;
- return null;
- }
- set {
- _weakPart.SetTarget(value);
- Listener.SubscribeTo(value, OnPropertyChanged);
- }
- }
-
- public PropertyChangedProxy(Func<TSource, object> partGetter, string propertyName, BindingBase binding)
- {
- PartGetter = partGetter;
- PropertyName = propertyName;
- _binding = binding;
- Listener = new BindingExpression.WeakPropertyChangedProxy();
- }
-
- void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (!string.IsNullOrEmpty(e.PropertyName) && string.CompareOrdinal(e.PropertyName, PropertyName) != 0)
- return;
- Device.BeginInvokeOnMainThread(() => _binding.Apply(false));
- }
- }
-
- void Subscribe(TSource sourceObject)
- {
- for (var i = 0; i < _handlers.Length; i++) {
- var part = _handlers [i].PartGetter(sourceObject);
- if (part == null)
- break;
- var inpc = part as INotifyPropertyChanged;
- if (inpc == null)
- continue;
- _handlers [i].Part = (inpc);
- }
- }
-
- void Unsubscribe()
- {
- for (var i = 0; i < _handlers.Length; i++)
- _handlers [i].Listener.Unsubscribe();
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.ComponentModel;
-using System.Linq;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.BaseComponents;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Children")]
- internal abstract class Layout<T> : Layout, IViewContainer<T> where T : View
- {
- readonly ElementCollection<T> _children;
-
- protected Layout()
- {
- _children = new ElementCollection<T>(InternalChildren);
- }
-
- public new IList<T> Children
- {
- get { return _children; }
- }
-
- protected virtual void OnAdded(T view)
- {
- }
-
- protected override void OnChildAdded(Element child)
- {
- base.OnChildAdded(child);
-
- var typedChild = child as T;
- if (typedChild != null)
- OnAdded(typedChild);
- }
-
- protected override void OnChildRemoved(Element child)
- {
- base.OnChildRemoved(child);
-
- var typedChild = child as T;
- if (typedChild != null)
- OnRemoved(typedChild);
- }
-
- protected virtual void OnRemoved(T view)
- {
- }
- }
-
- internal abstract class Layout : View, ILayout, ILayoutController, IPaddingElement
- {
- public static readonly BindableProperty IsClippedToBoundsProperty = BindableProperty.Create("IsClippedToBounds", typeof(bool), typeof(Layout), false);
-
- public static readonly BindableProperty CascadeInputTransparentProperty = BindableProperty.Create(
- nameof(CascadeInputTransparent), typeof(bool), typeof(Layout), true);
-
- public static new readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
-
- static IList<KeyValuePair<Layout, int>> s_resolutionList = new List<KeyValuePair<Layout, int>>();
- static bool s_relayoutInProgress;
-
- bool _hasDoneLayout;
- Size _lastLayoutSize = new Size(-1, -1, 0);
-
- ReadOnlyCollection<Element> _logicalChildren;
-
- protected Layout()
- {
- //if things were added in base ctor (through implicit styles), the items added aren't properly parented
- if (InternalChildren.Count > 0)
- InternalChildrenOnCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, InternalChildren));
-
- InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged;
- }
-
- public bool IsClippedToBounds
- {
- get { return (bool)GetValue(IsClippedToBoundsProperty); }
- set { SetValue(IsClippedToBoundsProperty, value); }
- }
-
- public new Thickness Padding
- {
- get { return (Thickness)GetValue(PaddingElement.PaddingProperty); }
- set { SetValue(PaddingElement.PaddingProperty, value); }
- }
-
- public bool CascadeInputTransparent
- {
- get { return (bool)GetValue(CascadeInputTransparentProperty); }
- set { SetValue(CascadeInputTransparentProperty, value); }
- }
-
- Thickness IPaddingElement.PaddingDefaultValueCreator()
- {
- return default(Thickness);
- }
-
- void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
- {
- UpdateChildrenLayout();
- }
-
- internal ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
-
- internal override ReadOnlyCollection<Element> LogicalChildrenInternal
- {
- get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
- }
-
- /// <summary>
- /// Raised when the layout of the Page has changed.
- /// </summary>
- public event EventHandler LayoutChanged;
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new IReadOnlyList<Element> Children
- {
- get { return InternalChildren; }
- }
-
- public void ForceLayout()
- {
- }
-
-
- public static void LayoutChildIntoBoundingRegion(BaseHandle child, Rectangle region)
- {
- var view = child as View;
- if (view == null)
- {
- return;
- }
- }
-
- public void LowerChild(View view)
- {
- if (!InternalChildren.Contains(view) || (InternalChildren.First() as BaseHandle) == view)
- return;
-
- InternalChildren.Move(InternalChildren.IndexOf(view), 0);
- }
-
- public void RaiseChild(View view)
- {
- if (!InternalChildren.Contains(view) || (InternalChildren.Last() as BaseHandle) == view)
- return;
-
- InternalChildren.Move(InternalChildren.IndexOf(view), InternalChildren.Count - 1);
- }
-
- protected virtual void InvalidateLayout()
- {
- _hasDoneLayout = false;
- if (!_hasDoneLayout)
- ForceLayout();
- }
-
- protected abstract void LayoutChildren(double x, double y, double width, double height);
-
- protected void OnChildMeasureInvalidated(object sender, EventArgs e)
- {
- InvalidationTrigger trigger = (e as InvalidationEventArgs)?.Trigger ?? InvalidationTrigger.Undefined;
- OnChildMeasureInvalidated((BaseHandle)sender, trigger);
- OnChildMeasureInvalidated();
- }
-
- protected virtual void OnChildMeasureInvalidated()
- {
- }
-
- protected virtual bool ShouldInvalidateOnChildAdded(View child)
- {
- return true;
- }
-
- protected virtual bool ShouldInvalidateOnChildRemoved(View child)
- {
- return true;
- }
-
- protected void UpdateChildrenLayout()
- {
- _hasDoneLayout = true;
-
- if (!ShouldLayoutChildren())
- return;
-
- LayoutChanged?.Invoke(this, EventArgs.Empty);
- }
-
- internal static void LayoutChildIntoBoundingRegion(View child, Rectangle region, SizeRequest childSizeRequest)
- {
- }
-
- internal virtual void OnChildMeasureInvalidated(BaseHandle child, InvalidationTrigger trigger)
- {
- ReadOnlyCollection<Element> children = LogicalChildrenInternal;
- int count = children.Count;
- for (var index = 0; index < count; index++)
- {
- var v = LogicalChildrenInternal[index] as BaseHandle;
- if (v != null)
- {
- return;
- }
- }
-
- var view = child as View;
- if (view != null)
- {
- //we can ignore the request if we are either fully constrained or when the size request changes and we were already fully constrainted
- if ((trigger == InvalidationTrigger.MeasureChanged) ||
- (trigger == InvalidationTrigger.SizeRequestChanged))
- {
- return;
- }
- }
-
- s_resolutionList.Add(new KeyValuePair<Layout, int>(this, GetElementDepth(this)));
- if (!s_relayoutInProgress)
- {
- s_relayoutInProgress = true;
- Device.BeginInvokeOnMainThread(() =>
- {
- // if thread safety mattered we would need to lock this and compareexchange above
- IList<KeyValuePair<Layout, int>> copy = s_resolutionList;
- s_resolutionList = new List<KeyValuePair<Layout, int>>();
- s_relayoutInProgress = false;
- });
- }
- }
-
- static int GetElementDepth(Element view)
- {
- var result = 0;
- while (view.Parent != null)
- {
- result++;
- view = view.Parent;
- }
- return result;
- }
-
- void InternalChildrenOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (e.Action == NotifyCollectionChangedAction.Move)
- {
- return;
- }
-
- if (e.OldItems != null)
- {
- foreach (object item in e.OldItems)
- {
- var v = item as View;
- if (v == null)
- continue;
-
- OnInternalRemoved(v);
- }
- }
-
- if (e.NewItems != null)
- {
- foreach (object item in e.NewItems)
- {
- var v = item as View;
- if (v == null)
- continue;
-
- if ((item as BaseHandle) == this)
- throw new InvalidOperationException("Can not add self to own child collection.");
-
- OnInternalAdded(v);
- }
- }
- }
-
- void OnInternalAdded(View view)
- {
- var parent = view.GetParent() as Layout;
- parent?.InternalChildren.Remove(view);
-
- OnChildAdded(view);
- if (ShouldInvalidateOnChildAdded(view))
- InvalidateLayout();
- }
-
- void OnInternalRemoved(View view)
- {
- OnChildRemoved(view);
- if (ShouldInvalidateOnChildRemoved(view))
- InvalidateLayout();
- }
-
- bool ShouldLayoutChildren()
- {
- if ( !LogicalChildrenInternal.Any() )
- {
- return false;
- }
-
- foreach (Element element in VisibleDescendants())
- {
- var visual = element as BaseHandle;
- if (visual == null)
- {
- continue;
- }
- }
- return true;
- }
- }
-}
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [Flags]
- internal enum LayoutAlignment
- {
- Start = 0,
- Center = 1,
- End = 2,
- Fill = 3
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [Flags]
- internal enum LayoutExpandFlag
- {
- Expand = 4
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- [TypeConverter(typeof(LayoutOptionsConverter))]
- internal struct LayoutOptions
- {
- int _flags;
-
- public static readonly LayoutOptions Start = new LayoutOptions(LayoutAlignment.Start, false);
- public static readonly LayoutOptions Center = new LayoutOptions(LayoutAlignment.Center, false);
- public static readonly LayoutOptions End = new LayoutOptions(LayoutAlignment.End, false);
- public static readonly LayoutOptions Fill = new LayoutOptions(LayoutAlignment.Fill, false);
- public static readonly LayoutOptions StartAndExpand = new LayoutOptions(LayoutAlignment.Start, true);
- public static readonly LayoutOptions CenterAndExpand = new LayoutOptions(LayoutAlignment.Center, true);
- public static readonly LayoutOptions EndAndExpand = new LayoutOptions(LayoutAlignment.End, true);
- public static readonly LayoutOptions FillAndExpand = new LayoutOptions(LayoutAlignment.Fill, true);
-
- public LayoutOptions(LayoutAlignment alignment, bool expands)
- {
- var a = (int)alignment;
- if (a < 0 || a > 3)
- throw new ArgumentOutOfRangeException();
- _flags = (int)alignment | (expands ? (int)LayoutExpandFlag.Expand : 0);
- }
-
- public LayoutAlignment Alignment
- {
- get { return (LayoutAlignment)(_flags & 3); }
- set { _flags = (_flags & ~3) | (int)value; }
- }
-
- public bool Expands
- {
- get { return (_flags & (int)LayoutExpandFlag.Expand) != 0; }
- set { _flags = (_flags & 3) | (value ? (int)LayoutExpandFlag.Expand : 0); }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Linq;
-using System.Reflection;
-using Tizen.NUI.Binding.Internals;
-
-using Tizen.NUI;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.LayoutOptionsConverter")]
- [Xaml.TypeConversion(typeof(LayoutOptions))]
- internal sealed class LayoutOptionsConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null) {
- var parts = value.Split('.');
- if (parts.Length > 2 || (parts.Length == 2 && parts [0] != "LayoutOptions"))
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(LayoutOptions)}");
- value = parts [parts.Length - 1];
- switch (value) {
- case "Start": return LayoutOptions.Start;
- case "Center": return LayoutOptions.Center;
- case "End": return LayoutOptions.End;
- case "Fill": return LayoutOptions.Fill;
- case "StartAndExpand": return LayoutOptions.StartAndExpand;
- case "CenterAndExpand": return LayoutOptions.CenterAndExpand;
- case "EndAndExpand": return LayoutOptions.EndAndExpand;
- case "FillAndExpand": return LayoutOptions.FillAndExpand;
- }
- FieldInfo field = typeof(LayoutOptions).GetFields().FirstOrDefault(fi => fi.IsStatic && fi.Name == value);
- if (field != null)
- return (LayoutOptions)field.GetValue(null);
- }
-
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(LayoutOptions)}");
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Windows.Input;
-
-namespace Tizen.NUI.Binding
-{
-
- internal class MenuItem : BaseMenuItem, IMenuItemController
- {
- public static readonly BindableProperty AcceleratorProperty = BindableProperty.CreateAttached(nameof(Accelerator), typeof(Accelerator), typeof(MenuItem), null);
-
- public static Accelerator GetAccelerator(BindableObject bindable) => (Accelerator)bindable.GetValue(AcceleratorProperty);
-
- public static void SetAccelerator(BindableObject bindable, Accelerator value) => bindable.SetValue(AcceleratorProperty, value);
-
- public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(MenuItem), null);
-
- public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(MenuItem), null,
- propertyChanging: (bo, o, n) => ((MenuItem)bo).OnCommandChanging(), propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandChanged());
-
- public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(MenuItem), null,
- propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandParameterChanged());
-
- public static readonly BindableProperty IsDestructiveProperty = BindableProperty.Create("IsDestructive", typeof(bool), typeof(MenuItem), false);
-
- public static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(MenuItem), default(FileImageSource));
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), typeof(ToolbarItem), true);
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string IsEnabledPropertyName
- {
- get
- {
- return IsEnabledProperty.PropertyName;
- }
- }
-
- public ICommand Command
- {
- get { return (ICommand)GetValue(CommandProperty); }
- set { SetValue(CommandProperty, value); }
- }
-
- public object CommandParameter
- {
- get { return GetValue(CommandParameterProperty); }
- set { SetValue(CommandParameterProperty, value); }
- }
-
- public FileImageSource Icon
- {
- get { return (FileImageSource)GetValue(IconProperty); }
- set { SetValue(IconProperty, value); }
- }
-
- public bool IsDestructive
- {
- get { return (bool)GetValue(IsDestructiveProperty); }
- set { SetValue(IsDestructiveProperty, value); }
- }
-
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEnabled
- {
- get { return (bool)GetValue(IsEnabledProperty); }
- set { SetValue(IsEnabledProperty, value); }
- }
-
- bool IsEnabledCore
- {
- set { SetValueCore(IsEnabledProperty, value); }
- }
-
- public event EventHandler Clicked;
-
- protected virtual void OnClicked()
- => Clicked?.Invoke(this, EventArgs.Empty);
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void Activate()
- {
- if (Command != null)
- {
- if (IsEnabled)
- Command.Execute(CommandParameter);
- }
-
- OnClicked();
- }
-
- void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
- {
- IsEnabledCore = Command.CanExecute(CommandParameter);
- }
-
- void OnCommandChanged()
- {
- if (Command == null)
- {
- IsEnabledCore = true;
- return;
- }
-
- IsEnabledCore = Command.CanExecute(CommandParameter);
-
- Command.CanExecuteChanged += OnCommandCanExecuteChanged;
- }
-
- void OnCommandChanging()
- {
- if (Command == null)
- return;
-
- Command.CanExecuteChanged -= OnCommandCanExecuteChanged;
- }
-
- void OnCommandParameterChanged()
- {
- if (Command == null)
- return;
-
- IsEnabledCore = Command.CanExecute(CommandParameter);
- }
- }
-}
\ No newline at end of file
{
////If the base type is one of these, stop registering dynamic resources further
////The last one (typeof(Element)) is a safety guard as we might be creating VisualElement directly in internal code
- static readonly IList<Type> s_stopAtTypes = new List<Type> { typeof(View), typeof(Layout<>), typeof(Element) };
+ static readonly IList<Type> s_stopAtTypes = new List<Type> { typeof(View), typeof(Element) };
IList<BindableProperty> _classStyleProperties;
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class ModalEventArgs : EventArgs
- {
- protected ModalEventArgs(Page modal)
- {
- Modal = modal;
- }
-
- public Page Modal { get; private set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class ModalPoppedEventArgs : ModalEventArgs
- {
- public ModalPoppedEventArgs(Page modal) : base(modal)
- {
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class ModalPoppingEventArgs : ModalEventArgs
- {
- public ModalPoppingEventArgs(Page modal) : base(modal)
- {
- }
-
- public bool Cancel { get; set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class ModalPushedEventArgs : ModalEventArgs
- {
- public ModalPushedEventArgs(Page modal) : base(modal)
- {
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class ModalPushingEventArgs : ModalEventArgs
- {
- public ModalPushingEventArgs(Page modal) : base(modal)
- {
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal enum NamedSize
- {
- Default = 0,
- Micro = 1,
- Small = 2,
- Medium = 3,
- Large = 4
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// EventArgs for the NavigationPage's navigation events.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationEventArgs : EventArgs
- {
- /// <summary>
- /// Create a NavigationEventArgs instance.
- /// </summary>
- /// <param name="page">The page that was popped or is newly visible.</param>
- public NavigationEventArgs(Page page)
- {
- if (page == null)
- throw new ArgumentNullException("page");
-
- Page = page;
- }
-
- /// <summary>
- /// Gets the page that was removed or is newly visible.
- /// </summary>
- public Page Page { get; private set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
-
-namespace Tizen.NUI.Binding
-{
- // Mark as internal until renderers are ready for release after 1.0
- // [RenderWith(typeof(_NavigationMenuRenderer))]
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationMenu : View, /*INavigationMenuController,*/ IElementConfiguration<NavigationMenu>
- {
- readonly List<Page> _targets = new List<Page>();
-
- readonly Lazy<PlatformConfigurationRegistry<NavigationMenu>> _platformConfigurationRegistry;
-
- public NavigationMenu()
- {
- _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationMenu>>(() => new PlatformConfigurationRegistry<NavigationMenu>(this));
- }
-
- public IEnumerable<Page> Targets
- {
- get { return _targets; }
- set
- {
- if (_targets.AsEnumerable().SequenceEqual(value))
- return;
-
- foreach (Page page in value)
- {
- VerifyTarget(page);
- }
-
- OnPropertyChanging();
- _targets.Clear();
- _targets.AddRange(value);
- OnPropertyChanged();
- }
- }
-
- public void Add(Page target)
- {
- if (_targets.Contains(target))
- return;
- VerifyTarget(target);
-
- OnPropertyChanging("Targets");
- _targets.Add(target);
- OnPropertyChanged("Targets");
- }
-
- public void Remove(Page target)
- {
- if (_targets.Contains(target))
- {
- OnPropertyChanging("Targets");
- if (_targets.Remove(target))
- OnPropertyChanged("Targets");
- }
- }
-
- public IPlatformElementConfiguration<T, NavigationMenu> On<T>() where T : IConfigPlatform
- {
- return _platformConfigurationRegistry.Value.On<T>();
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendTargetSelected(Page target)
- {
- Navigation.PushAsync(target);
- }
-
- void VerifyTarget(Page target)
- {
- if (target.Icon == null || string.IsNullOrWhiteSpace(target.Icon.File))
- throw new Exception("Icon must be set for each page before adding them to a Navigation Menu");
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-
-namespace Tizen.NUI.Binding
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationModel
- {
- readonly List<Page> _modalStack = new List<Page>();
- readonly List<List<Page>> _navTree = new List<List<Page>>();
-
- public Page CurrentPage
- {
- get
- {
- if (_navTree.Any())
- return _navTree.Last().Last();
- return null;
- }
- }
-
- public IEnumerable<Page> Modals
- {
- get { return _modalStack; }
- }
-
- public IEnumerable<Page> Roots
- {
- get
- {
- foreach (List<Page> list in _navTree)
- {
- yield return list[0];
- }
- }
- }
-
- public IReadOnlyList<IReadOnlyList<Page>> Tree
- {
- get { return _navTree; }
- }
-
- public void Clear()
- {
- _navTree.Clear();
- _modalStack.Clear();
- }
-
- public void InsertPageBefore(Page page, Page before)
- {
- List<Page> currentStack = _navTree.Last();
- int index = currentStack.IndexOf(before);
-
- if (index == -1)
- throw new ArgumentException("before must be in the current navigation context");
-
- currentStack.Insert(index, page);
- }
-
- public Page Pop(Page ancestralNav)
- {
- ancestralNav = AncestorToRoot(ancestralNav);
- foreach (List<Page> stack in _navTree)
- {
- if (stack.Contains(ancestralNav))
- {
- if (stack.Count <= 1)
- throw new InvalidNavigationException("Can not pop final item in stack");
- Page result = stack.Last();
- stack.Remove(result);
- return result;
- }
- }
-
- throw new InvalidNavigationException("Popped from unpushed item?");
- }
-
- public Page PopModal()
- {
- if (_navTree.Count <= 1)
- throw new InvalidNavigationException("Can't pop modal without any modals pushed");
- Page modal = _navTree.Last().First();
- _modalStack.Remove(modal);
- _navTree.Remove(_navTree.Last());
- return modal;
- }
-
- public Page PopTopPage()
- {
- Page itemToRemove;
- if (_navTree.Count == 1)
- {
- if (_navTree[0].Count > 1)
- {
- itemToRemove = _navTree[0].Last();
- _navTree[0].Remove(itemToRemove);
- return itemToRemove;
- }
- return null;
- }
- itemToRemove = _navTree.Last().Last();
- _navTree.Last().Remove(itemToRemove);
- if (!_navTree.Last().Any())
- {
- _navTree.RemoveAt(_navTree.Count - 1);
- }
- return itemToRemove;
- }
-
- public void PopToRoot(Page ancestralNav)
- {
- ancestralNav = AncestorToRoot(ancestralNav);
- foreach (List<Page> stack in _navTree)
- {
- if (stack.Contains(ancestralNav))
- {
- if (stack.Count <= 1)
- throw new InvalidNavigationException("Can not pop final item in stack");
- stack.RemoveRange(1, stack.Count - 1);
- return;
- }
- }
-
- throw new InvalidNavigationException("Popped from unpushed item?");
- }
-
- public void Push(Page page, Page ancestralNav)
- {
- if (ancestralNav == null)
- {
- if (_navTree.Any())
- throw new InvalidNavigationException("Ancestor must be provided for all pushes except first");
- _navTree.Add(new List<Page> { page });
- return;
- }
-
- ancestralNav = AncestorToRoot(ancestralNav);
-
- foreach (List<Page> stack in _navTree)
- {
- if (stack.Contains(ancestralNav))
- {
- stack.Add(page);
- return;
- }
- }
-
- throw new InvalidNavigationException("Invalid ancestor passed");
- }
-
- public void PushModal(Page page)
- {
- _navTree.Add(new List<Page> { page });
- _modalStack.Add(page);
- }
-
- public bool RemovePage(Page page)
- {
- bool found;
- List<Page> currentStack = _navTree.Last();
- var i = 0;
- while (!(found = currentStack.Remove(page)) && i < _navTree.Count - 1)
- {
- currentStack = _navTree[i++];
- }
-
- return found;
- }
-
- Page AncestorToRoot(Page ancestor)
- {
- Page result = ancestor;
- // while (!Application.IsApplicationOrNull(result.RealParent))
- result = (Page)result.RealParent;
- return result;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Linq;
-using System.Threading.Tasks;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI
-{
- /// <summary>
- /// A Page that manages the navigation and user-experience of a stack of other pages.
- /// </summary>
- // [RenderWith(typeof(_NavigationPageRenderer))]
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationPage : Page, IPageContainer<Page>, INavigationPageController, IElementConfiguration<NavigationPage>
- {
- /// <summary>
- /// Identifies the property associated with the title of the back button.
- /// </summary>
- public static readonly BindableProperty BackButtonTitleProperty = BindableProperty.CreateAttached("BackButtonTitle", typeof(string), typeof(Page), null);
-
- /// <summary>
- /// Backing store for the HasNavigationBar property.
- /// </summary>
- public static readonly BindableProperty HasNavigationBarProperty = BindableProperty.CreateAttached("HasNavigationBar", typeof(bool), typeof(Page), true);
-
- /// <summary>
- /// Backing store for the HasBackButton property.
- /// </summary>
- public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached("HasBackButton", typeof(bool), typeof(NavigationPage), true);
-
- /// <summary>
- /// Identifies the Tint bindable property.
- /// </summary>
- [Obsolete("TintProperty is obsolete as of version 1.2.0. Please use BarBackgroundColorProperty and BarTextColorProperty to change NavigationPage bar color properties.")]
- public static readonly BindableProperty TintProperty = BindableProperty.Create("Tint", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black);
-
- /// <summary>
- /// Identifies the property associated with the color of the NavigationPage's bar background color.
- /// </summary>
- public static readonly BindableProperty BarBackgroundColorProperty = BindableProperty.Create("BarBackgroundColor", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black);
-
- /// <summary>
- /// Identifies the property associated with the color of the NavigationPage's bar text color.
- /// </summary>
- public static readonly BindableProperty BarTextColorProperty = BindableProperty.Create("BarTextColor", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black);
-
- /// <summary>
- /// Indicates the NavigationPage.SetTitleIcon/NavigationPage.GetTitleIcon property.
- /// </summary>
- public static readonly BindableProperty TitleIconProperty = BindableProperty.CreateAttached("TitleIcon", typeof(FileImageSource), typeof(NavigationPage), default(FileImageSource));
-
- static readonly BindablePropertyKey CurrentPagePropertyKey = BindableProperty.CreateReadOnly("CurrentPage", typeof(Page), typeof(NavigationPage), null);
-
- /// <summary>
- /// Identifies the property associated with NavigationPage.CurrentPage
- /// </summary>
- public static readonly BindableProperty CurrentPageProperty = CurrentPagePropertyKey.BindableProperty;
-
- static readonly BindablePropertyKey RootPagePropertyKey = BindableProperty.CreateReadOnly(nameof(RootPage), typeof(Page), typeof(NavigationPage), null);
- /// <summary>
- /// Identifies the property associated with NavigationPage.RootPage
- /// </summary>
- public static readonly BindableProperty RootPageProperty = RootPagePropertyKey.BindableProperty;
-
- /// <summary>
- /// Initializes a new NavigationPage object.
- /// </summary>
- public NavigationPage()
- {
- _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationPage>>(() => new PlatformConfigurationRegistry<NavigationPage>(this));
-
- Navigation = new NavigationImpl(this);
- }
-
- /// <summary>
- /// Creates a new NavigationPage element with root as its root element.
- /// </summary>
- /// <param name="root">The root page.</param>
- public NavigationPage(Page root) : this()
- {
- PushPage(root);
- }
-
- /// <summary>
- /// Gets or sets the background color for the bar at the top of the NavigationPage.
- /// </summary>
- public Color BarBackgroundColor
- {
- get { return (Color)GetValue(BarBackgroundColorProperty); }
- set { SetValue(BarBackgroundColorProperty, value); }
- }
-
- /// <summary>
- /// Gets or sets the text that appears on the bar at the top of the NavigationPage.
- /// </summary>
- public Color BarTextColor
- {
- get { return (Color)GetValue(BarTextColorProperty); }
- set { SetValue(BarTextColorProperty, value); }
- }
-
- /// <summary>
- /// The color to be used as the Tint of the NavigationPage.
- /// </summary>
- [Obsolete("Tint is obsolete as of version 1.2.0. Please use BarBackgroundColor and BarTextColor to change NavigationPage bar color properties.")]
- public Color Tint
- {
- get { return (Color)GetValue(TintProperty); }
- set { SetValue(TintProperty, value); }
- }
-
- internal Task CurrentNavigationTask { get; set; }
-
- /// <summary>
- /// For internal use
- /// </summary>
- /// <param name="depth">The depth</param>
- /// <returns>The page instance</returns>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Page Peek(int depth)
- {
- if (depth < 0)
- {
- return null;
- }
-
- if (InternalChildren.Count <= depth)
- {
- return null;
- }
-
- return (Page)InternalChildren[InternalChildren.Count - depth - 1];
- }
-
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IEnumerable<Page> Pages => InternalChildren.Cast<Page>();
-
- /// <summary>
- /// For internal use
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int StackDepth
- {
- get { return InternalChildren.Count; }
- }
-
- /// <summary>
- /// The Page that is currently top-most on the navigation stack.
- /// </summary>
- public Page CurrentPage
- {
- get { return (Page)GetValue(CurrentPageProperty); }
- private set { SetValue(CurrentPagePropertyKey, value); }
- }
-
- /// <summary>
- /// The Page that is the root of the navigation stack.
- /// </summary>
- public Page RootPage
- {
- get { return (Page)GetValue(RootPageProperty); }
- private set { SetValue(RootPagePropertyKey, value); }
- }
-
- /// <summary>
- /// 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 Tizen.NUI.Xaml.CurrentPage.</returns>
- public static string GetBackButtonTitle(BindableObject page)
- {
- return (string)page.GetValue(BackButtonTitleProperty);
- }
-
- /// <summary>
- /// Returns a value that indicates whether page has a back button.
- /// </summary>
- /// <param name="page">The page to be checked</param>
- /// <returns>true if the page has a back button.</returns>
- public static bool GetHasBackButton(Page page)
- {
- if (page == null)
- throw new ArgumentNullException("page");
- return (bool)page.GetValue(HasBackButtonProperty);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the page has a navigation bar.
- /// </summary>
- /// <param name="page">The Page being queried.</param>
- /// <returns>true if page would display a navigation bar were it the CurrentPage.</returns>
- public static bool GetHasNavigationBar(BindableObject page)
- {
- return (bool)page.GetValue(HasNavigationBarProperty);
- }
-
- internal static FileImageSource GetTitleIcon(BindableObject bindable)
- {
- return (FileImageSource)bindable.GetValue(TitleIconProperty);
- }
-
- /// <summary>
- /// Asynchronously removes the top Page from the navigation stack.
- /// </summary>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- public Task<Page> PopAsync()
- {
- return PopAsync(true);
- }
-
- /// <summary>
- /// Asynchronously removes the top Page from the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- public async Task<Page> PopAsync(bool animated)
- {
- var tcs = new TaskCompletionSource<bool>();
- if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted)
- {
- var oldTask = CurrentNavigationTask;
- CurrentNavigationTask = tcs.Task;
- await oldTask;
- }
- else
- CurrentNavigationTask = tcs.Task;
-
- var result = await PopAsyncInner(animated, false);
- tcs.SetResult(true);
- return result;
- }
-
- /// <summary>
- /// Event that is raised after a page is popped from this NavigationPage element.
- /// </summary>
- public event EventHandler<NavigationEventArgs> Popped;
-
- /// <summary>
- /// Pops all but the root Page off the navigation stack.
- /// </summary>
- /// <returns>A task that represents the asynchronous dismiss operation.</returns>
- public Task PopToRootAsync()
- {
- return PopToRootAsync(true);
- }
-
- /// <summary>
- /// A task for asynchronously popping all pages off of the navigation stack.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>A task that represents the asynchronous dismiss operation.</returns>
- public async Task PopToRootAsync(bool animated)
- {
- if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted)
- {
- var tcs = new TaskCompletionSource<bool>();
- Task oldTask = CurrentNavigationTask;
- CurrentNavigationTask = tcs.Task;
- await oldTask;
-
- await PopToRootAsyncInner(animated);
- tcs.SetResult(true);
- return;
- }
-
- Task result = PopToRootAsyncInner(animated);
- CurrentNavigationTask = result;
- await result;
- }
-
- /// <summary>
- /// Presents a Page modally.
- /// </summary>
- /// <param name="page">The Page to present modally.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- public Task PushAsync(Page page)
- {
- return PushAsync(page, true);
- }
-
- /// <summary>
- /// A task for asynchronously pushing a page onto the navigation stack, with optional animation.
- /// </summary>
- /// <param name="page">The Page to present modally.</param>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- public async Task PushAsync(Page page, bool animated)
- {
- if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted)
- {
- var tcs = new TaskCompletionSource<bool>();
- Task oldTask = CurrentNavigationTask;
- CurrentNavigationTask = tcs.Task;
- await oldTask;
-
- await PushAsyncInner(page, animated);
- tcs.SetResult(true);
- return;
- }
-
- CurrentNavigationTask = PushAsyncInner(page, animated);
- await CurrentNavigationTask;
- }
-
- /// <summary>
- /// Event that is raised when a page is pushed onto this NavigationPage element.
- /// </summary>
- public event EventHandler<NavigationEventArgs> Pushed;
-
- /// <summary>
- /// Sets the title that appears on the back button for page.
- /// </summary>
- /// <param name="page">The BindableObject object.</param>
- /// <param name="value">The value to set.</param>
- public static void SetBackButtonTitle(BindableObject page, string value)
- {
- page.SetValue(BackButtonTitleProperty, value);
- }
-
- /// <summary>
- /// Adds or removes a back button to page, with optional animation.
- /// </summary>
- /// <param name="page">The page object.</param>
- /// <param name="value">The value to set.</param>
- public static void SetHasBackButton(Page page, bool value)
- {
- if (page == null)
- throw new ArgumentNullException("page");
- page.SetValue(HasBackButtonProperty, value);
- }
-
- /// <summary>
- /// Sets a value that indicates whether or not this NavigationPage element has a navigation bar.
- /// </summary>
- /// <param name="page">The BindableObject object</param>
- /// <param name="value">The value to set</param>
- public static void SetHasNavigationBar(BindableObject page, bool value)
- {
- page.SetValue(HasNavigationBarProperty, value);
- }
-
- internal static void SetTitleIcon(BindableObject bindable, FileImageSource value)
- {
- bindable.SetValue(TitleIconProperty, value);
- }
-
- /// <summary>
- /// Event that is raised when the hardware back button is pressed.
- /// </summary>
- /// <returns>true if consumed</returns>
- protected override bool OnBackButtonPressed()
- {
- if (CurrentPage.SendBackButtonPressed())
- return true;
-
- if (StackDepth > 1)
- {
- SafePop();
- return true;
- }
-
- return base.OnBackButtonPressed();
- }
-
- /// <summary>
- /// For internal use
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<NavigationRequestedEventArgs> InsertPageBeforeRequested;
-
- /// <summary>
- /// For internal use
- /// </summary>
- /// <param name="animated">Whether animate the pop.</param>
- /// <param name="fast"></param>
- /// <returns>A task that represents the asynchronous dismiss operation.</returns>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public async Task<Page> PopAsyncInner(bool animated, bool fast)
- {
- if (StackDepth == 1)
- {
- return null;
- }
-
- var page = (Page)InternalChildren.Last();
-
- return await (this as INavigationPageController).RemoveAsyncInner(page, animated, fast);
- }
-
- async Task<Page> INavigationPageController.RemoveAsyncInner(Page page, bool animated, bool fast)
- {
- if (StackDepth == 1)
- {
- return null;
- }
-
- var args = new NavigationRequestedEventArgs(page, animated);
-
- var removed = true;
-
- EventHandler<NavigationRequestedEventArgs> requestPop = PopRequested;
- if (requestPop != null)
- {
- requestPop(this, args);
-
- if (args.Task != null && !fast)
- removed = await args.Task;
- }
-
- if (!removed && !fast)
- return CurrentPage;
-
- InternalChildren.Remove(page);
-
- CurrentPage = (Page)InternalChildren.Last();
-
- if (Popped != null)
- Popped(this, args);
-
- return page;
- }
-
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<NavigationRequestedEventArgs> PopRequested;
-
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<NavigationRequestedEventArgs> PopToRootRequested;
-
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<NavigationRequestedEventArgs> PushRequested;
-
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<NavigationRequestedEventArgs> RemovePageRequested;
-
- void InsertPageBefore(Page page, Page before)
- {
- if (page == null)
- throw new ArgumentNullException($"{nameof(page)} cannot be null.");
-
- if (before == null)
- throw new ArgumentNullException($"{nameof(before)} cannot be null.");
-
- if (!InternalChildren.Contains(before))
- throw new ArgumentException($"{nameof(before)} must be a child of the NavigationPage", nameof(before));
-
- if (InternalChildren.Contains(page))
- throw new ArgumentException("Cannot insert page which is already in the navigation stack");
-
- EventHandler<NavigationRequestedEventArgs> handler = InsertPageBeforeRequested;
- handler?.Invoke(this, new NavigationRequestedEventArgs(page, before, false));
-
- int index = InternalChildren.IndexOf(before);
- InternalChildren.Insert(index, page);
-
- if (index == 0)
- RootPage = page;
-
- // Shouldn't be required?
- // if (Width > 0 && Height > 0)
- ForceLayout();
- }
-
- async Task PopToRootAsyncInner(bool animated)
- {
- if (StackDepth == 1)
- return;
-
- Element[] childrenToRemove = InternalChildren.Skip(1).ToArray();
- foreach (Element child in childrenToRemove)
- InternalChildren.Remove(child);
-
- CurrentPage = RootPage;
-
- var args = new NavigationRequestedEventArgs(RootPage, animated);
-
- EventHandler<NavigationRequestedEventArgs> requestPopToRoot = PopToRootRequested;
- if (requestPopToRoot != null)
- {
- requestPopToRoot(this, args);
-
- if (args.Task != null)
- await args.Task;
- }
-
- // PoppedToRoot?.Invoke(this, new PoppedToRootEventArgs(RootPage, childrenToRemove.OfType<Page>().ToList()));
- }
-
- async Task PushAsyncInner(Page page, bool animated)
- {
- if (InternalChildren.Contains(page))
- return;
-
- PushPage(page);
-
- var args = new NavigationRequestedEventArgs(page, animated);
-
- EventHandler<NavigationRequestedEventArgs> requestPush = PushRequested;
- if (requestPush != null)
- {
- requestPush(this, args);
-
- if (args.Task != null)
- await args.Task;
- }
-
- Pushed?.Invoke(this, args);
- }
-
- void PushPage(Page page)
- {
- InternalChildren.Add(page);
-
- if (InternalChildren.Count == 1)
- RootPage = page;
-
- CurrentPage = page;
- }
-
- void RemovePage(Page page)
- {
- if (page == null)
- throw new ArgumentNullException($"{nameof(page)} cannot be null.");
-
- if (page == CurrentPage && CurrentPage == RootPage)
- throw new InvalidOperationException("Cannot remove root page when it is also the currently displayed page.");
- if (page == CurrentPage)
- {
- // Log.Warning("NavigationPage", "RemovePage called for CurrentPage object. This can result in undesired behavior, consider calling PopAsync instead.");
- PopAsync();
- return;
- }
-
- if (!InternalChildren.Contains(page))
- throw new ArgumentException("Page to remove must be contained on this Navigation Page");
-
- EventHandler<NavigationRequestedEventArgs> handler = RemovePageRequested;
- handler?.Invoke(this, new NavigationRequestedEventArgs(page, true));
-
- InternalChildren.Remove(page);
- if (RootPage == page)
- RootPage = (Page)InternalChildren.First();
- }
-
- void SafePop()
- {
- PopAsync(true).ContinueWith(t =>
- {
- if (t.IsFaulted)
- throw t.Exception;
- });
- }
-
- class NavigationImpl : NavigationProxy
- {
- // readonly Lazy<ReadOnlyCastingList<Page, Element>> _castingList;
-
- public NavigationImpl(NavigationPage owner)
- {
- Owner = owner;
- // _castingList = new Lazy<ReadOnlyCastingList<Page, Element>>(() => new ReadOnlyCastingList<Page, Element>(Owner.InternalChildren));
- }
-
- NavigationPage Owner { get; }
-
- protected override IReadOnlyList<Page> GetNavigationStack()
- {
- // return _castingList.Value;
- return null;
- }
-
- protected override void OnInsertPageBefore(Page page, Page before)
- {
- Owner.InsertPageBefore(page, before);
- }
-
- protected override Task<Page> OnPopAsync(bool animated)
- {
- return Owner.PopAsync(animated);
- }
-
- protected override Task OnPopToRootAsync(bool animated)
- {
- return Owner.PopToRootAsync(animated);
- }
-
- protected override Task OnPushAsync(Page root, bool animated)
- {
- return Owner.PushAsync(root, animated);
- }
-
- protected override void OnRemovePage(Page page)
- {
- Owner.RemovePage(page);
- }
- }
-
- readonly Lazy<PlatformConfigurationRegistry<NavigationPage>> _platformConfigurationRegistry;
-
- /// <summary>
- /// Returns the platform-specific instance of this NavigationPage, on which a platform-specific method may be called.
- /// </summary>
- /// <typeparam name="T">The platform for which to return an instance.</typeparam>
- /// <returns>The platform-specific instance of this NavigationPage</returns>
- public new IPlatformElementConfiguration<T, NavigationPage> On<T>() where T : IConfigPlatform
- {
- return _platformConfigurationRegistry.Value.On<T>();
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationProxy : INavigation
- {
- INavigation _inner;
- Lazy<List<Page>> _modalStack = new Lazy<List<Page>>(() => new List<Page>());
-
- Lazy<List<Page>> _pushStack = new Lazy<List<Page>>(() => new List<Page>());
-
- internal INavigation Inner
- {
- get { return _inner; }
- set
- {
- if (_inner == value)
- return;
- _inner = value;
- // reverse so that things go into the new stack in the same order
- // null out to release memory that will likely never be needed again
-
- if (ReferenceEquals(_inner, null))
- {
- _pushStack = new Lazy<List<Page>>(() => new List<Page>());
- _modalStack = new Lazy<List<Page>>(() => new List<Page>());
- }
- else
- {
- if (_pushStack != null && _pushStack.IsValueCreated)
- {
- foreach (Page page in _pushStack.Value)
- {
- _inner.PushAsync(page);
- }
- }
-
- if (_modalStack != null && _modalStack.IsValueCreated)
- {
- foreach (Page page in _modalStack.Value)
- {
- _inner.PushModalAsync(page);
- }
- }
-
- _pushStack = null;
- _modalStack = null;
- }
- }
- }
-
- /// <summary>
- /// Inserts a page in the navigation stack before an existing page in the stack.
- /// </summary>
- /// <param name="page">The page to add.</param>
- /// <param name="before">The existing page, before which page will be inserted.</param>
- public void InsertPageBefore(Page page, Page before)
- {
- OnInsertPageBefore(page, before);
- }
-
- /// <summary>
- /// Gets the modal navigation stack.
- /// </summary>
- public IReadOnlyList<Page> ModalStack
- {
- get { return GetModalStack(); }
- }
-
- /// <summary>
- /// Gets the stack of pages in the navigation.
- /// </summary>
- public IReadOnlyList<Page> NavigationStack
- {
- get { return GetNavigationStack(); }
- }
-
- /// <summary>
- /// Asynchronously removes the most recent Page from the navigation stack.
- /// </summary>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- public Task<Page> PopAsync()
- {
- return OnPopAsync(true);
- }
-
- /// <summary>
- /// Asynchronously removes the top Page from the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- public Task<Page> PopAsync(bool animated)
- {
- return OnPopAsync(animated);
- }
-
- /// <summary>
- /// Asynchronously dismisses the most recent modally presented Page.
- /// </summary>
- /// <returns>An awaitable instance, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped.</returns>
- public Task<Page> PopModalAsync()
- {
- return OnPopModal(true);
- }
-
- /// <summary>
- /// Asynchronously removes the top Page from the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>The Page that had been at the top of the navigation stack.</returns>
- public Task<Page> PopModalAsync(bool animated)
- {
- return OnPopModal(animated);
- }
-
- /// <summary>
- /// Pops all but the root Page off the navigation stack.
- /// </summary>
- /// <returns>A task representing the asynchronous dismiss operation.</returns>
- public Task PopToRootAsync()
- {
- return OnPopToRootAsync(true);
- }
-
- /// <summary>
- /// Pops all but the root Page off the navigation stack, with optional animation.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>A task representing the asynchronous dismiss operation.</returns>
- public Task PopToRootAsync(bool animated)
- {
- return OnPopToRootAsync(animated);
- }
-
- /// <summary>
- /// Asynchronously adds a Page to the top of the navigation stack.
- /// </summary>
- /// <param name="root">The Page to be pushed on top of the navigation stack.</param>
- /// <returns>A task that represents the asynchronous push operation.</returns>
- public Task PushAsync(Page root)
- {
- return PushAsync(root, true);
- }
-
- /// <summary>
- /// Asynchronously adds a Page to the top of the navigation stack, with optional animation.
- /// </summary>
- /// <param name="root">The page to push.</param>
- /// <param name="animated">Whether to animate the push.</param>
- /// <returns>A task that represents the asynchronous push operation.</returns>
- public Task PushAsync(Page root, bool animated)
- {
- if (root.RealParent != null)
- throw new InvalidOperationException("Page must not already have a parent.");
- return OnPushAsync(root, animated);
- }
-
- /// <summary>
- /// Presents a Page modally.
- /// </summary>
- /// <param name="modal">The Page to present modally.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- public Task PushModalAsync(Page modal)
- {
- return PushModalAsync(modal, true);
- }
-
- /// <summary>
- /// Presents a Page modally, with optional animation.
- /// </summary>
- /// <param name="modal">The page to push.</param>
- /// <param name="animated">Whether to animate the push.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- public Task PushModalAsync(Page modal, bool animated)
- {
- if (modal.RealParent != null)
- throw new InvalidOperationException("Page must not already have a parent.");
- return OnPushModal(modal, animated);
- }
-
- /// <summary>
- /// Removes the specified page from the navigation stack.
- /// </summary>
- /// <param name="page">The page to remove.</param>
- public void RemovePage(Page page)
- {
- OnRemovePage(page);
- }
-
- /// <summary>
- /// For internal use. Returns the modal navigation stack.
- /// </summary>
- /// <returns>The modal navigation stack.</returns>
- protected virtual IReadOnlyList<Page> GetModalStack()
- {
- INavigation currentInner = Inner;
- return currentInner == null ? _modalStack.Value : currentInner.ModalStack;
- }
-
- /// <summary>
- /// For internal use. Returns the stack of pages in the navigation.
- /// </summary>
- /// <returns>The stack of pages in the navigation.</returns>
- protected virtual IReadOnlyList<Page> GetNavigationStack()
- {
- INavigation currentInner = Inner;
- return currentInner == null ? _pushStack.Value : currentInner.NavigationStack;
- }
-
- /// <summary>
- /// The method called when insert a page in the navigation stack before an existing page in the stack.
- /// </summary>
- /// <param name="page">The page to add.</param>
- /// <param name="before">The existing page, before which page will be inserted.</param>
- protected virtual void OnInsertPageBefore(Page page, Page before)
- {
- INavigation currentInner = Inner;
- if (currentInner == null)
- {
- int index = _pushStack.Value.IndexOf(before);
- if (index == -1)
- throw new ArgumentException("before must be in the pushed stack of the current context");
- _pushStack.Value.Insert(index, page);
- }
- else
- {
- currentInner.InsertPageBefore(page, before);
- }
- }
-
- /// <summary>
- /// This method calls when removes the top Page from the navigation stack
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns></returns>
- protected virtual Task<Page> OnPopAsync(bool animated)
- {
- INavigation inner = Inner;
- return inner == null ? Task.FromResult(Pop()) : inner.PopAsync(animated);
- }
-
- /// <summary>
- /// This method calls when removes the top Page from the navigation stack
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>An awaitable instance, indicating the PopModalAsync completion</returns>
- protected virtual Task<Page> OnPopModal(bool animated)
- {
- INavigation innerNav = Inner;
- return innerNav == null ? Task.FromResult(PopModal()) : innerNav.PopModalAsync(animated);
- }
-
- /// <summary>
- /// This method calls when Pops all but the root Page off the navigation stack.
- /// </summary>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>A task representing the asynchronous dismiss operation.</returns>
- protected virtual Task OnPopToRootAsync(bool animated)
- {
- INavigation currentInner = Inner;
- if (currentInner == null)
- {
- Page root = _pushStack.Value.Last();
- _pushStack.Value.Clear();
- _pushStack.Value.Add(root);
- return Task.FromResult(root);
- }
- return currentInner.PopToRootAsync(animated);
- }
-
- /// <summary>
- /// This method calls when adds a Page to the top of the navigation stack, with optional animation.
- /// </summary>
- /// <param name="page">The page to add</param>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>A task that represents the asynchronous push operation.</returns>
- protected virtual Task OnPushAsync(Page page, bool animated)
- {
- INavigation currentInner = Inner;
- if (currentInner == null)
- {
- _pushStack.Value.Add(page);
- return Task.FromResult(page);
- }
- return currentInner.PushAsync(page, animated);
- }
-
- /// <summary>
- /// This method calls when Presents a Page modally, with optional animation.
- /// </summary>
- /// <param name="modal">The page to push.</param>
- /// <param name="animated">Whether to animate the pop.</param>
- /// <returns>An awaitable Task, indicating the PushModal completion.</returns>
- protected virtual Task OnPushModal(Page modal, bool animated)
- {
- INavigation currentInner = Inner;
- if (currentInner == null)
- {
- _modalStack.Value.Add(modal);
- return Task.FromResult<object>(null);
- }
- return currentInner.PushModalAsync(modal, animated);
- }
-
- /// <summary>
- /// This method calls when Removes the specified page from the navigation stack.
- /// </summary>
- /// <param name="page">The page to add.</param>
- protected virtual void OnRemovePage(Page page)
- {
- INavigation currentInner = Inner;
- if (currentInner == null)
- {
- _pushStack.Value.Remove(page);
- }
- else
- {
- currentInner.RemovePage(page);
- }
- }
-
- Page Pop()
- {
- List<Page> list = _pushStack.Value;
- Page result = list[list.Count - 1];
- list.RemoveAt(list.Count - 1);
- return result;
- }
-
- Page PopModal()
- {
- List<Page> list = _modalStack.Value;
- Page result = list[list.Count - 1];
- list.RemoveAt(list.Count - 1);
- return result;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.ComponentModel;
-using System.Threading.Tasks;
-using Tizen.NUI;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class NavigationRequestedEventArgs : NavigationEventArgs
- {
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="page"></param>
- /// <param name="animated"></param>
- /// <param name="realize"></param>
- public NavigationRequestedEventArgs(Page page, bool animated, bool realize = true) : base(page)
- {
- Animated = animated;
- Realize = realize;
- }
-
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="page"></param>
- /// <param name="before"></param>
- /// <param name="animated"></param>
- public NavigationRequestedEventArgs(Page page, Page before, bool animated) : this(page, animated)
- {
- BeforePage = before;
- }
-
- /// <summary>
- /// Gets or Sets the whether animate.
- /// </summary>
- public bool Animated { get; set; }
-
- /// <summary>
- /// Gets or Sets the before page.
- /// </summary>
- public Page BeforePage { get; set; }
-
- /// <summary>
- /// Gets or Sets the realize.
- /// </summary>
- public bool Realize { get; set; }
-
- /// <summary>
- /// Gets or Sets the Task.
- /// </summary>
- public Task<bool> Task { get; set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal class NullEffect : Effect
- {
- protected override void OnAttached()
- {
- }
-
- protected override void OnDetached()
- {
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.Linq;
-
-namespace Tizen.NUI.Binding
-{
- internal class ObservableWrapper<TTrack, TRestrict> : IList<TRestrict>, INotifyCollectionChanged where TTrack : Element where TRestrict : TTrack
- {
- readonly ObservableCollection<TTrack> _list;
-
- public ObservableWrapper(ObservableCollection<TTrack> list)
- {
- if (list == null)
- throw new ArgumentNullException("list");
-
- _list = list;
-
- list.CollectionChanged += ListOnCollectionChanged;
- }
-
- public void Add(TRestrict item)
- {
- if (item == null)
- throw new ArgumentNullException("item");
- if (IsReadOnly)
- throw new NotSupportedException("The collection is read-only.");
-
- if (_list.Contains(item))
- return;
-
- item.Owned = true;
- _list.Add(item);
- }
-
- public void Clear()
- {
- if (IsReadOnly)
- throw new NotSupportedException("The collection is read-only.");
-
- foreach (TRestrict item in _list.OfType<TRestrict>().ToArray())
- {
- _list.Remove(item);
- item.Owned = false;
- }
- }
-
- public bool Contains(TRestrict item)
- {
- return item.Owned && _list.Contains(item);
- }
-
- public void CopyTo(TRestrict[] array, int destIndex)
- {
- if (array.Length - destIndex < Count)
- throw new ArgumentException("Destination array was not long enough. Check destIndex and length, and the array's lower bounds.");
- foreach (TRestrict item in this)
- {
- array[destIndex] = item;
- destIndex++;
- }
- }
-
- public int Count
- {
- get { return _list.Where(i => i.Owned).OfType<TRestrict>().Count(); }
- }
-
- public bool IsReadOnly { get; internal set; }
-
- public bool Remove(TRestrict item)
- {
- if (item == null)
- throw new ArgumentNullException("item");
- if (IsReadOnly)
- throw new NotSupportedException("The collection is read-only.");
-
- if (!item.Owned)
- return false;
-
- if (_list.Remove(item))
- {
- item.Owned = false;
- return true;
- }
- return false;
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public IEnumerator<TRestrict> GetEnumerator()
- {
- return _list.Where(i => i.Owned).OfType<TRestrict>().GetEnumerator();
- }
-
- public int IndexOf(TRestrict value)
- {
- int innerIndex = _list.IndexOf(value);
- if (innerIndex == -1)
- return -1;
- return ToOuterIndex(innerIndex);
- }
-
- public void Insert(int index, TRestrict item)
- {
- if (item == null)
- throw new ArgumentNullException("item");
- if (IsReadOnly)
- throw new NotSupportedException("The collection is read-only.");
-
- item.Owned = true;
- _list.Insert(ToInnerIndex(index), item);
- }
-
- public TRestrict this[int index]
- {
- get { return (TRestrict)_list[ToInnerIndex(index)]; }
- set
- {
- int innerIndex = ToInnerIndex(index);
- if (value != null)
- value.Owned = true;
- TTrack old = _list[innerIndex];
- _list[innerIndex] = value;
-
- if (old != null)
- old.Owned = false;
- }
- }
-
- public void RemoveAt(int index)
- {
- if (IsReadOnly)
- throw new NotSupportedException("The collection is read-only");
- int innerIndex = ToInnerIndex(index);
- TTrack item = _list[innerIndex];
- if (item != null && item.Owned)
- {
- _list.RemoveAt(innerIndex);
- item.Owned = false;
- }
- }
-
- public event NotifyCollectionChangedEventHandler CollectionChanged;
-
- void ListOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- NotifyCollectionChangedEventHandler handler = CollectionChanged;
- if (handler == null)
- return;
-
- switch (e.Action)
- {
- case NotifyCollectionChangedAction.Add:
- if (e.NewStartingIndex == -1 || e.NewItems?.Count > 1)
- goto case NotifyCollectionChangedAction.Reset;
-
- var newItem = e.NewItems?[0] as TRestrict;
- if (newItem == null || !newItem.Owned)
- break;
-
- int outerIndex = ToOuterIndex(e.NewStartingIndex);
- handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, e.NewItems, outerIndex));
- break;
- case NotifyCollectionChangedAction.Move:
- if (e.NewStartingIndex == -1 || e.OldStartingIndex == -1 || e.NewItems?.Count > 1)
- goto case NotifyCollectionChangedAction.Reset;
-
- var movedItem = e.NewItems?[0] as TRestrict;
- if (movedItem == null || !movedItem.Owned)
- break;
-
- int outerOldIndex = ToOuterIndex(e.OldStartingIndex);
- int outerNewIndex = ToOuterIndex(e.NewStartingIndex);
- handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, e.NewItems, outerNewIndex, outerOldIndex));
- break;
- case NotifyCollectionChangedAction.Remove:
- if (e.OldStartingIndex == -1 || e.OldItems?.Count > 1)
- goto case NotifyCollectionChangedAction.Reset;
-
- var removedItem = e.OldItems?[0] as TRestrict;
- if (removedItem == null || !removedItem.Owned)
- break;
-
- int outerRemovedIndex = ToOuterIndex(e.OldStartingIndex);
- var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItem, outerRemovedIndex);
- handler(this, args);
- break;
- case NotifyCollectionChangedAction.Replace:
- if (e.NewStartingIndex == -1 || e.OldStartingIndex == -1 || e.NewItems?.Count > 1)
- goto case NotifyCollectionChangedAction.Reset;
-
- var newReplaceItem = e.NewItems?[0] as TRestrict;
- var oldReplaceItem = e.OldItems?[0] as TRestrict;
-
- if ((newReplaceItem == null || !newReplaceItem.Owned) && (oldReplaceItem == null || !oldReplaceItem.Owned))
- {
- break;
- }
- if (newReplaceItem == null || !newReplaceItem.Owned || oldReplaceItem == null || !oldReplaceItem.Owned)
- {
- goto case NotifyCollectionChangedAction.Reset;
- }
-
- int index = ToOuterIndex(e.NewStartingIndex);
-
- var replaceArgs = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newReplaceItem, oldReplaceItem, index);
- handler(this, replaceArgs);
- break;
- case NotifyCollectionChangedAction.Reset:
- handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- int ToInnerIndex(int outterIndex)
- {
- var outerIndex = 0;
- int innerIndex;
- for (innerIndex = 0; innerIndex < _list.Count; innerIndex++)
- {
- TTrack item = _list[innerIndex];
- if (item is TRestrict && item.Owned)
- {
- if (outerIndex == outterIndex)
- return innerIndex;
- outerIndex++;
- }
- }
-
- return innerIndex;
- }
-
- int ToOuterIndex(int innerIndex)
- {
- var outerIndex = 0;
- for (var index = 0; index < innerIndex; index++)
- {
- TTrack item = _list[index];
- if (item is TRestrict && item.Owned)
- {
- outerIndex++;
- }
- }
-
- return outerIndex;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-namespace Tizen.NUI.Binding
-{
- internal static class PaddingElement
- {
- internal static readonly BindableProperty PaddingProperty =
- BindableProperty.Create("Padding", typeof(Thickness), typeof(IPaddingElement), default(Thickness),
- propertyChanged: OnPaddingPropertyChanged,
- defaultValueCreator: PaddingDefaultValueCreator);
-
- static void OnPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue)
- {
- ((IPaddingElement)bindable).OnPaddingPropertyChanged((Thickness)oldValue, (Thickness)newValue);
- }
-
- static object PaddingDefaultValueCreator(BindableObject bindable)
- {
- return ((IPaddingElement)bindable).PaddingDefaultValueCreator();
- }
-
- public static readonly BindableProperty PaddingLeftProperty =
- BindableProperty.Create("PaddingLeft", typeof(double), typeof(IPaddingElement), default(double),
- propertyChanged: OnPaddingLeftChanged);
-
- static void OnPaddingLeftChanged(BindableObject bindable, object oldValue, object newValue)
- {
- var padding = (Thickness)bindable.GetValue(PaddingProperty);
- padding.Left = (double)newValue;
- bindable.SetValue(PaddingProperty, padding);
- }
-
- public static readonly BindableProperty PaddingTopProperty =
- BindableProperty.Create("PaddingTop", typeof(double), typeof(IPaddingElement), default(double),
- propertyChanged: OnPaddingTopChanged);
-
- static void OnPaddingTopChanged(BindableObject bindable, object oldValue, object newValue)
- {
- var padding = (Thickness)bindable.GetValue(PaddingProperty);
- padding.Top = (double)newValue;
- bindable.SetValue(PaddingProperty, padding);
- }
-
- public static readonly BindableProperty PaddingRightProperty =
- BindableProperty.Create("PaddingRight", typeof(double), typeof(IPaddingElement), default(double),
- propertyChanged: OnPaddingRightChanged);
-
- static void OnPaddingRightChanged(BindableObject bindable, object oldValue, object newValue)
- {
- var padding = (Thickness)bindable.GetValue(PaddingProperty);
- padding.Right = (double)newValue;
- bindable.SetValue(PaddingProperty, padding);
- }
-
- public static readonly BindableProperty PaddingBottomProperty =
- BindableProperty.Create("PaddingBottom", typeof(double), typeof(IPaddingElement), default(double),
- propertyChanged: OnPaddingBottomChanged);
-
- static void OnPaddingBottomChanged(BindableObject bindable, object oldValue, object newValue)
- {
- var padding = (Thickness)bindable.GetValue(PaddingProperty);
- padding.Bottom = (double)newValue;
- bindable.SetValue(PaddingProperty, padding);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// Helper that handles storing and lookup of platform specifics implementations
- /// </summary>
- /// <typeparam name="TElement">The Element type</typeparam>
- internal class PlatformConfigurationRegistry<TElement> : IElementConfiguration<TElement>
- where TElement : Element
- {
- readonly TElement _element;
- readonly Dictionary<Type, object> _platformSpecifics = new Dictionary<Type, object>();
-
- internal PlatformConfigurationRegistry(TElement element)
- {
- _element = element;
- }
-
-
- public IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform
- {
- if (_platformSpecifics.ContainsKey(typeof(T)))
- {
- return (IPlatformElementConfiguration<T, TElement>)_platformSpecifics[typeof(T)];
- }
-
- var emptyConfig = Configuration<T, TElement>.Create(_element);
-
- _platformSpecifics.Add(typeof(T), emptyConfig);
-
- return emptyConfig;
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.Binding
-{
- // Previewer uses reflection to bind to this method; Removal or modification of visibility will break previewer.
- internal static class Registrar
- {
- internal static void RegisterAll(Type[] attrTypes) => Internals.Registrar.RegisterAll(attrTypes);
- }
-}
-
-namespace Tizen.NUI.Binding.Internals
-{
- /// <summary>
- /// For internal use.
- /// </summary>
- /// <typeparam name="TRegistrable"></typeparam>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class Registrar<TRegistrable> where TRegistrable : class
- {
- readonly Dictionary<Type, Type> _handlers = new Dictionary<Type, Type>();
-
- /// <summary>
- /// Register.
- /// </summary>
- /// <param name="tview">The type of the view</param>
- /// <param name="trender">The type of the render.</param>
- public void Register(Type tview, Type trender)
- {
- //avoid caching null renderers
- if (trender == null)
- return;
- _handlers[tview] = trender;
- }
-
- internal TRegistrable GetHandler(Type type)
- {
- Type handlerType = GetHandlerType(type);
- if (handlerType == null)
- return null;
-
- object handler = DependencyResolver.ResolveOrCreate(handlerType);
-
- return (TRegistrable)handler;
- }
-
- internal TRegistrable GetHandler(Type type, params object[] args)
- {
- if (args.Length == 0)
- {
- return GetHandler(type);
- }
-
- Type handlerType = GetHandlerType(type);
- if (handlerType == null)
- return null;
-
- return (TRegistrable)DependencyResolver.ResolveOrCreate(handlerType, args);
- }
-
- /// <summary>
- /// For internal use. Returns handler.
- /// </summary>
- /// <typeparam name="TOut">The type of the handler</typeparam>
- /// <param name="type">The type.</param>
- /// <returns>The handler instance.</returns>
- public TOut GetHandler<TOut>(Type type) where TOut : TRegistrable
- {
- return (TOut)GetHandler(type);
- }
-
- /// <summary>
- /// For internal use. Returns handler.
- /// </summary>
- /// <typeparam name="TOut">The type of the handler</typeparam>
- /// <param name="type">The type.</param>
- /// <param name="args">The args of the type</param>
- /// <returns>The handler instance.</returns>
- public TOut GetHandler<TOut>(Type type, params object[] args) where TOut : TRegistrable
- {
- return (TOut)GetHandler(type, args);
- }
-
- /// <summary>
- /// For internal use. Return the handler of the object.
- /// </summary>
- /// <typeparam name="TOut">Thetype</typeparam>
- /// <param name="obj">The object instance.</param>
- /// <returns>The handle of the obj.</returns>
- public TOut GetHandlerForObject<TOut>(object obj) where TOut : TRegistrable
- {
- if (obj == null)
- throw new ArgumentNullException(nameof(obj));
-
- var reflectableType = obj as IReflectableType;
- var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
-
- return (TOut)GetHandler(type);
- }
-
- /// <summary>
- /// For inetrnal use. Return the handler of the object.
- /// </summary>
- /// <typeparam name="TOut">The type</typeparam>
- /// <param name="obj">The object instance</param>
- /// <param name="args">The args of the type</param>
- /// <returns>The handler of the object.</returns>
- public TOut GetHandlerForObject<TOut>(object obj, params object[] args) where TOut : TRegistrable
- {
- if (obj == null)
- throw new ArgumentNullException(nameof(obj));
-
- var reflectableType = obj as IReflectableType;
- var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
-
- return (TOut)GetHandler(type, args);
- }
-
- /// <summary>
- /// For internal use. Returns the handle type.
- /// </summary>
- /// <param name="viewType">The view type.</param>
- /// <returns>The type of the handle.</returns>
- public Type GetHandlerType(Type viewType)
- {
- Type type;
- if (LookupHandlerType(viewType, out type))
- return type;
-
- // lazy load render-view association with RenderWithAttribute (as opposed to using ExportRenderer)
- var attribute = viewType.GetTypeInfo().GetCustomAttribute<RenderWithAttribute>();
- if (attribute == null)
- {
- Register(viewType, null); // Cache this result so we don't have to do GetCustomAttribute again
- return null;
- }
-
- type = attribute.Type;
-
- if (type.Name.StartsWith("_", StringComparison.Ordinal))
- {
- // TODO: Remove attribute2 once renderer names have been unified across all platforms
- var attribute2 = type.GetTypeInfo().GetCustomAttribute<RenderWithAttribute>();
- if (attribute2 != null)
- type = attribute2.Type;
-
- if (type.Name.StartsWith("_", StringComparison.Ordinal))
- {
- Register(viewType, null); // Cache this result so we don't work through this chain again
- return null;
- }
- }
-
- Register(viewType, type); // Register this so we don't have to look for the RenderWith Attibute again in the future
-
- return type;
- }
-
- /// <summary>
- /// For internal use. Return the handle type of the object
- /// </summary>
- /// <param name="obj">The object instance.</param>
- /// <returns>The type of the handler.</returns>
- public Type GetHandlerTypeForObject(object obj)
- {
- if (obj == null)
- throw new ArgumentNullException(nameof(obj));
-
- var reflectableType = obj as IReflectableType;
- var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
-
- return GetHandlerType(type);
- }
-
- bool LookupHandlerType(Type viewType, out Type handlerType)
- {
- Type type = viewType;
-
- while (type != null)
- {
- if (_handlers.ContainsKey(type))
- {
- handlerType = _handlers[type];
- return true;
- }
-
- type = type.GetTypeInfo().BaseType;
- }
-
- handlerType = null;
- return false;
- }
- }
-
- /// <summary>
- /// For internal use
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal static class Registrar
- {
- static Registrar()
- {
- Registered = new Registrar<IRegisterable>();
- }
-
- internal static Dictionary<string, Type> Effects { get; } = new Dictionary<string, Type>();
- internal static Dictionary<string, StyleSheets.StylePropertyAttribute> StyleProperties { get; } = new Dictionary<string, StyleSheets.StylePropertyAttribute>();
-
- public static IEnumerable<Assembly> ExtraAssemblies { get; set; }
-
- public static Registrar<IRegisterable> Registered { get; internal set; }
-
- public static void RegisterAll(Type[] attrTypes)
- {
- Assembly[] assemblies = Device.GetAssemblies();
- if (ExtraAssemblies != null)
- assemblies = assemblies.Union(ExtraAssemblies).ToArray();
-
- Assembly defaultRendererAssembly = Device.PlatformServices.GetType().GetTypeInfo().Assembly;
- int indexOfExecuting = Array.IndexOf(assemblies, defaultRendererAssembly);
-
- if (indexOfExecuting > 0)
- {
- assemblies[indexOfExecuting] = assemblies[0];
- assemblies[0] = defaultRendererAssembly;
- }
-
- // Don't use LINQ for performance reasons
- // Naive implementation can easily take over a second to run
- foreach (Assembly assembly in assemblies)
- {
- foreach (Type attrType in attrTypes)
- {
- Attribute[] attributes;
- try
- {
- attributes = assembly.GetCustomAttributes(attrType).ToArray();
- }
- catch (System.IO.FileNotFoundException)
- {
- // Sometimes the previewer doesn't actually have everything required for these loads to work
- Console.WriteLine(nameof(Registrar), "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, attrType.FullName);
- continue;
- }
- var length = attributes.Length;
- for (var i = 0; i < length;i++)
- {
- var attribute = (HandlerAttribute)attributes[i];
- if (attribute.ShouldRegister())
- Registered.Register(attribute.HandlerType, attribute.TargetType);
- }
- }
-
- string resolutionName = assembly.FullName;
- var resolutionNameAttribute = (ResolutionGroupNameAttribute)assembly.GetCustomAttribute(typeof(ResolutionGroupNameAttribute));
- if (resolutionNameAttribute != null)
- resolutionName = resolutionNameAttribute.ShortName;
-
- Attribute[] effectAttributes = assembly.GetCustomAttributes(typeof(ExportEffectAttribute)).ToArray();
- var exportEffectsLength = effectAttributes.Length;
- for (var i = 0; i < exportEffectsLength;i++)
- {
- var effect = (ExportEffectAttribute)effectAttributes[i];
- Effects [resolutionName + "." + effect.Id] = effect.Type;
- }
-
- Attribute[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute)).ToArray();
- var stylePropertiesLength = styleAttributes.Length;
- for (var i = 0; i < stylePropertiesLength; i++)
- {
- var attribute = (StyleSheets.StylePropertyAttribute)styleAttributes[i];
- StyleProperties[attribute.CssPropertyName] = attribute;
- }
- }
-
- DependencyService.Initialize(assemblies);
- }
- }
-}
+++ /dev/null
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- internal class RoutingEffect : Effect
- {
- internal readonly Effect Inner;
-
- protected RoutingEffect(string effectId)
- {
- Inner = Resolve(effectId);
- }
-
- protected override void OnAttached()
- {
- }
-
- protected override void OnDetached()
- {
- }
-
- internal override void ClearEffect()
- {
- Inner?.ClearEffect();
- }
-
- internal override void SendAttached()
- {
- Inner?.SendAttached();
- }
-
- internal override void SendDetached()
- {
- Inner?.SendDetached();
- }
-
- internal override void SendOnElementPropertyChanged(PropertyChangedEventArgs args)
- {
- Inner?.SendOnElementPropertyChanged(args);
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Xml;
-using Tizen.NUI.Binding.Internals;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Value")]
- [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")]
- internal sealed class Setter : IValueProvider
- {
- readonly ConditionalWeakTable<BindableObject, object> _originalValues = new ConditionalWeakTable<BindableObject, object>();
-
- public BindableProperty Property { get; set; }
-
- public object Value { get; set; }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- if (Property == null)
- {
- var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
- IXmlLineInfo lineInfo = lineInfoProvider != null ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
- throw new XamlParseException("Property not set", lineInfo);
- }
- var valueconverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider;
-
- Func<MemberInfo> minforetriever =
- () =>
- (MemberInfo)Property.DeclaringType.GetRuntimeProperty(Property.PropertyName) ?? (MemberInfo)Property.DeclaringType.GetRuntimeMethod("Get" + Property.PropertyName, new[] { typeof(BindableObject) });
-
- object value = valueconverter?.Convert(Value, Property.ReturnType, minforetriever, serviceProvider);
- Value = value;
- return this;
- }
-
- internal void Apply(BindableObject target, bool fromStyle = false)
- {
- if (target == null)
- throw new ArgumentNullException("target");
- if (Property == null)
- return;
-
- object originalValue = target.GetValue(Property);
- if (!Equals(originalValue, Property.DefaultValue))
- {
- _originalValues.Remove(target);
- _originalValues.Add(target, originalValue);
- }
-
- var dynamicResource = Value as DynamicResource;
- var binding = Value as BindingBase;
- if (binding != null)
- target.SetBinding(Property, binding.Clone(), fromStyle);
- else if (dynamicResource != null)
- target.SetDynamicResource(Property, dynamicResource.Key, fromStyle);
- else
- {
- if (Value is IList<VisualStateGroup> visualStateGroupCollection)
- target.SetValue(Property, visualStateGroupCollection.Clone(), fromStyle);
- else
- target.SetValue(Property, Value, fromStyle);
- }
- }
-
- internal void UnApply(BindableObject target, bool fromStyle = false)
- {
- if (target == null)
- throw new ArgumentNullException(nameof(target));
- if (Property == null)
- return;
-
- object actual = target.GetValue(Property);
- if (!Equals(actual, Value) && !(Value is Tizen.NUI.Binding.Binding) && !(Value is DynamicResource))
- {
- //Do not reset default value if the value has been changed
- _originalValues.Remove(target);
- return;
- }
-
- object defaultValue;
- if (_originalValues.TryGetValue(target, out defaultValue))
- {
- //reset default value, unapply bindings and dynamicResource
- target.SetValue(Property, defaultValue, fromStyle);
- _originalValues.Remove(target);
- }
- else
- target.ClearValue(Property);
- }
- }
-}
+++ /dev/null
-using System.Diagnostics;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// Struct that defines minimum and maximum Sizes.
- /// </summary>
- [DebuggerDisplay("Request={Request.Width}x{Request.Height}, Minimum={Minimum.Width}x{Minimum.Height}")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal struct SizeRequest
- {
- /// <summary>
- /// The requested size.
- /// </summary>
- public Size Request { get; set; }
-
- /// <summary>
- /// The minimum acceptable size.
- /// </summary>
- public Size Minimum { get; set; }
-
- /// <summary>
- /// Creates a new SizeRequest object that requests at least the size minimum, but preferably the size request.
- /// </summary>
- /// <param name="request">The size of the request.</param>
- /// <param name="minimum">The minimum size for the request.</param>
- public SizeRequest(Size request, Size minimum)
- {
- Request = request;
- Minimum = minimum;
- }
-
- /// <summary>
- /// Creates a new SizeRequest with the specified request size.
- /// </summary>
- /// <param name="request">The size of the request.</param>
- public SizeRequest(Size request)
- {
- Request = request;
- Minimum = request;
- }
-
- /// <summary>
- /// Returns a string representation of the size request.
- /// </summary>
- /// <returns>a string representation of the size request.</returns>
- public override string ToString()
- {
- return string.Format("{{Request={0} Minimum={1}}}", Request, Minimum);
- }
- }
-}
+++ /dev/null
-using System;
-using System.Linq;
-using System.Reflection;
-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)
- {
- if (value != null)
- {
- string[] parts = value.Split(',');
- if (parts.Length == 3)
- {
- int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
- int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
- int z = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim());
- return new Size(x, y, z);
- }
- }
-
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}");
- }
- }
-
- [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
- internal class Size2DTypeConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null)
- {
- string[] parts = value.Split(',');
- if (parts.Length == 2)
- {
- int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
- int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
- return new Size2D(x, y);
- }
- }
-
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}");
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Tizen.NUI.StyleSheets;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- [ContentProperty("Setters")]
- internal sealed class Style : IStyle
- {
- internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass.";
-
- readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style),
- propertyChanged: OnBasedOnResourceChanged);
-
- readonly List<WeakReference<BindableObject>> _targets = new List<WeakReference<BindableObject>>(4);
-
- Style _basedOnStyle;
-
- string _baseResourceKey;
-
- IList<Behavior> _behaviors;
-
- IList<TriggerBase> _triggers;
-
- public Style([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType)
- {
- if (targetType == null)
- throw new ArgumentNullException("targetType");
-
- TargetType = targetType;
- Setters = new List<Setter>();
- }
-
- public bool ApplyToDerivedTypes { get; set; }
-
- public Style BasedOn
- {
- get { return _basedOnStyle; }
- set
- {
- if (_basedOnStyle == value)
- return;
- if (!ValidateBasedOn(value))
- throw new ArgumentException("BasedOn.TargetType is not compatible with TargetType");
- Style oldValue = _basedOnStyle;
- _basedOnStyle = value;
- BasedOnChanged(oldValue, value);
- if (value != null)
- BaseResourceKey = null;
- }
- }
-
- public string BaseResourceKey
- {
- get { return _baseResourceKey; }
- set
- {
- if (_baseResourceKey == value)
- return;
- _baseResourceKey = value;
- //update all DynamicResources
- foreach (WeakReference<BindableObject> bindableWr in _targets)
- {
- BindableObject target;
- if (!bindableWr.TryGetTarget(out target))
- continue;
- target.RemoveDynamicResource(_basedOnResourceProperty);
- if (value != null)
- target.SetDynamicResource(_basedOnResourceProperty, value);
- }
- if (value != null)
- BasedOn = null;
- }
- }
-
- internal IList<Behavior> Behaviors
- {
- get { return _behaviors ?? (_behaviors = new AttachedCollection<Behavior>()); }
- }
-
- public bool CanCascade { get; set; }
-
- public string Class { get; set; }
-
- public IList<Setter> Setters { get; }
-
- /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IList<TriggerBase> Triggers
- {
- get { return _triggers ?? (_triggers = new AttachedCollection<TriggerBase>()); }
- }
-
- void IStyle.Apply(BindableObject bindable)
- {
- _targets.Add(new WeakReference<BindableObject>(bindable));
- if (BaseResourceKey != null)
- bindable.SetDynamicResource(_basedOnResourceProperty, BaseResourceKey);
- ApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
- }
-
- public Type TargetType { get; }
-
- void IStyle.UnApply(BindableObject bindable)
- {
- UnApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
- bindable.RemoveDynamicResource(_basedOnResourceProperty);
- _targets.RemoveAll(wr =>
- {
- BindableObject target;
- return wr.TryGetTarget(out target) && target == bindable;
- });
- }
-
- internal bool CanBeAppliedTo(Type targetType)
- {
- if (TargetType == targetType)
- return true;
- if (!ApplyToDerivedTypes)
- return false;
- do
- {
- targetType = targetType.GetTypeInfo().BaseType;
- if (TargetType == targetType)
- return true;
- } while (targetType != typeof(Element));
- return false;
- }
-
- void ApplyCore(BindableObject bindable, Style basedOn)
- {
- if (basedOn != null)
- ((IStyle)basedOn).Apply(bindable);
-
- foreach (Setter setter in Setters)
- setter.Apply(bindable, true);
- ((AttachedCollection<Behavior>)Behaviors).AttachTo(bindable);
- ((AttachedCollection<TriggerBase>)Triggers).AttachTo(bindable);
- }
-
- void BasedOnChanged(Style oldValue, Style newValue)
- {
- foreach (WeakReference<BindableObject> bindableRef in _targets)
- {
- BindableObject bindable;
- if (!bindableRef.TryGetTarget(out bindable))
- continue;
-
- UnApplyCore(bindable, oldValue);
- ApplyCore(bindable, newValue);
- }
- }
-
- Style GetBasedOnResource(BindableObject bindable)
- {
- return (Style)bindable.GetValue(_basedOnResourceProperty);
- }
-
- static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue)
- {
- // Style style = (bindable as /*VisualElement*/BaseHandle).Style;
- // if (style == null)
- // return;
- // style.UnApplyCore(bindable, (Style)oldValue);
- // style.ApplyCore(bindable, (Style)newValue);
- }
-
- void UnApplyCore(BindableObject bindable, Style basedOn)
- {
- ((AttachedCollection<TriggerBase>)Triggers).DetachFrom(bindable);
- ((AttachedCollection<Behavior>)Behaviors).DetachFrom(bindable);
- foreach (Setter setter in Setters)
- setter.UnApply(bindable, true);
-
- if (basedOn != null)
- ((IStyle)basedOn).UnApply(bindable);
- }
-
- bool ValidateBasedOn(Style value)
- {
- if (value == null)
- return true;
- return value.TargetType.IsAssignableFrom(TargetType);
- }
- }
-}
+++ /dev/null
-using System.Diagnostics;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <summary>
- /// Struct defining thickness around the edges of a Rectangle using doubles.
- /// </summary>
- [DebuggerDisplay("Left={Left}, Top={Top}, Right={Right}, Bottom={Bottom}, HorizontalThickness={HorizontalThickness}, VerticalThickness={VerticalThickness}")]
- [TypeConverter(typeof(ThicknessTypeConverter))]
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal struct Thickness
- {
- /// <summary>
- /// The thickness of the left side of a rectangle.
- /// </summary>
- public double Left { get; set; }
-
- /// <summary>
- /// The thickness of the top of a rectangle.
- /// </summary>
- public double Top { get; set; }
-
- /// <summary>
- /// The thickness of the right side of a rectangle.
- /// </summary>
- public double Right { get; set; }
-
- /// <summary>
- /// The thickness of the bottom of a rectangle.
- /// </summary>
- public double Bottom { get; set; }
-
- /// <summary>
- /// The sum of Left and Right.
- /// </summary>
- public double HorizontalThickness
- {
- get { return Left + Right; }
- }
-
- /// <summary>
- /// The sum of Top and Bottom.
- /// </summary>
- public double VerticalThickness
- {
- get { return Top + Bottom; }
- }
-
- internal bool IsDefault
- {
- get { return Left == 0 && Top == 0 && Right == 0 && Bottom == 0; }
- }
-
- /// <summary>
- /// Creates a new Thickness object that represents a uniform thickness of size uniformSize.
- /// </summary>
- /// <param name="uniformSize">The uniform size of all edges in the new thickness.</param>
- public Thickness(double uniformSize) : this(uniformSize, uniformSize, uniformSize, uniformSize)
- {
- }
-
- /// <summary>
- /// Creates a new Thickness object that has a horizontal thickness of horizontalSize and a vertical thickness of verticalSize.
- /// </summary>
- /// <param name="horizontalSize">The width of the left and right thicknesses.</param>
- /// <param name="verticalSize">The height of the top and bottom thicknesses.</param>
- public Thickness(double horizontalSize, double verticalSize) : this(horizontalSize, verticalSize, horizontalSize, verticalSize)
- {
- }
-
- /// <summary>
- /// Creates a new Thickness object with thicknesses defined by left, top, right, and bottom.
- /// </summary>
- /// <param name="left">The width of the left thickness.</param>
- /// <param name="top">The height of the top thickness.</param>
- /// <param name="right">The width of the right thickness.</param>
- /// <param name="bottom">The height of the bottom thickness.</param>
- public Thickness(double left, double top, double right, double bottom) : this()
- {
- Left = left;
- Top = top;
- Right = right;
- Bottom = bottom;
- }
-
- /// <summary>
- /// Converts a Size into a Thickness.
- /// </summary>
- /// <param name="size">A Size to convert to a Thickness</param>
- public static implicit operator Thickness(Size size)
- {
- return new Thickness(size.Width, size.Height, size.Width, size.Height);
- }
-
- /// <summary>
- /// Implicit cast operator from Double.
- /// </summary>
- /// <param name="uniformSize">The value for the uniform Thickness.</param>
- public static implicit operator Thickness(double uniformSize)
- {
- return new Thickness(uniformSize);
- }
-
- /// <summary>
- /// Whether the other has equivalent values.
- /// </summary>
- /// <param name="other">A Thickness to be compared.</param>
- /// <returns>true if other has equivalent values.</returns>
- bool Equals(Thickness other)
- {
- return Left.Equals(other.Left) && Top.Equals(other.Top) && Right.Equals(other.Right) && Bottom.Equals(other.Bottom);
- }
-
- /// <summary>
- /// Whether the obj has equivalent values.
- /// </summary>
- /// <param name="obj">A Thickness to be compared.</param>
- /// <returns>true if obj is a Thickness and has equivalent values.</returns>
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- return false;
- return obj is Thickness && Equals((Thickness)obj);
- }
-
- /// <summary>
- /// A hash value for this Thickness.
- /// </summary>
- /// <returns>The hash value</returns>
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = Left.GetHashCode();
- hashCode = (hashCode * 397) ^ Top.GetHashCode();
- hashCode = (hashCode * 397) ^ Right.GetHashCode();
- hashCode = (hashCode * 397) ^ Bottom.GetHashCode();
- return hashCode;
- }
- }
-
- /// <summary>
- /// Whether two Thicknesses have identical values.
- /// </summary>
- /// <param name="left">A Thickness to be compared.</param>
- /// <param name="right">A Thickness to be compared.</param>
- /// <returns>true if left and right have identical values for Left,Right, Top, and Bottom.</returns>
- public static bool operator ==(Thickness left, Thickness right)
- {
- return left.Equals(right);
- }
-
- /// <summary>
- /// Whether the values of two Thickness's have at least one difference.
- /// </summary>
- /// <param name="left">A Thickness to be compared.</param>
- /// <param name="right">A Thickness to be compared.</param>
- /// <returns>true if any of the Left,Right, Top, and Bottom values differ between left and right.</returns>
- public static bool operator !=(Thickness left, Thickness right)
- {
- return !left.Equals(right);
- }
-
- /// <summary>
- /// Stores the components of the thickness in the corresponding arguments.
- /// </summary>
- /// <param name="left">Variable in which to store the left thickness of thickness object.</param>
- /// <param name="top">Variable in which to store the top thickness of thickness object.</param>
- /// <param name="right">Variable in which to store the right thickness of thickness object.</param>
- /// <param name="bottom">Variable in which to store the bottom thickness of thickness object.</param>
- public void Deconstruct(out double left, out double top, out double right, out double bottom)
- {
- left = Left;
- top = Top;
- right = Right;
- bottom = Bottom;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Globalization;
-
-namespace Tizen.NUI.Binding
-{
- [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ThicknessTypeConverter")]
- [Xaml.TypeConversion(typeof(Thickness))]
- internal class ThicknessTypeConverter : TypeConverter
- {
- public override object ConvertFromInvariantString(string value)
- {
- if (value != null) {
- value = value.Trim();
- if (value.Contains(",")) { //Xaml
- var thickness = value.Split(',');
- switch (thickness.Length) {
- case 2:
- if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double h)
- && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double v))
- return new Thickness(h, v);
- break;
- case 4:
- if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double l)
- && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double t)
- && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out double r)
- && double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out double b))
- return new Thickness(l, t, r, b);
- break;
- }
- }
- else if (value.Contains(" ")) { //CSS
- var thickness = value.Split(' ');
- switch (thickness.Length) {
- case 2:
- if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double v)
- && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double h))
- return new Thickness(h, v);
- break;
- case 3:
- if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double t)
- && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out h)
- && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out double b))
- return new Thickness(h, t, h, b);
- break;
- case 4:
- if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out t)
- && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double r)
- && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out b)
- && double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out double l))
- return new Thickness(l, t, r, b);
- break;
- }
- }
- else { //single uniform thickness
- if (double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out double l))
- return new Thickness(l);
- }
- }
-
- throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Thickness)}");
- }
- }
-}
\ No newline at end of file
s_context = SynchronizationContext.Current;
}
- public class TizenTicker : Ticker
- {
- readonly System.Threading.Timer _timer;
-
- public TizenTicker()
- {
- _timer = new System.Threading.Timer((object o) => HandleElapsed(o), this, Timeout.Infinite, Timeout.Infinite);
- }
-
- protected override void EnableTimer()
- {
- _timer.Change(16, 16);
- }
-
- protected override void DisableTimer()
- {
- _timer.Change(-1, -1);
- }
-
- void HandleElapsed(object state)
- {
- s_context.Post((o) => SendSignals(-1), null);
- }
- }
#region IPlatformServices implementation
-
- // public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
- // {
- // int pt;
- // // Actual font size depends on the target idiom.
- // switch (size)
- // {
- // case NamedSize.Micro:
- // pt = Device.Idiom == TargetIdiom.TV || Device.Idiom == TargetIdiom.Watch ? 24 : 19;
- // break;
- // case NamedSize.Small:
- // pt = Device.Idiom == TargetIdiom.TV ? 26 : (Device.Idiom == TargetIdiom.Watch ? 30 : 22);
- // break;
- // case NamedSize.Default:
- // case NamedSize.Medium:
- // pt = Device.Idiom == TargetIdiom.TV ? 28 : (Device.Idiom == TargetIdiom.Watch ? 32 : 25);
- // break;
- // case NamedSize.Large:
- // pt = Device.Idiom == TargetIdiom.TV ? 84 : (Device.Idiom == TargetIdiom.Watch ? 36 : 31);
- // break;
- // default:
- // throw new ArgumentOutOfRangeException();
- // }
- // return Forms.ConvertToDPFont(pt);
- // }
-
- // public void OpenUriAction(Uri uri)
- // {
- // if (uri == null || uri.AbsoluteUri == null)
- // {
- // throw new ArgumentNullException(nameof(uri));
- // }
- // TAppControl tAppControl = new TAppControl() { Operation = "%", Uri = uri.AbsoluteUri };
- // var matchedApplications = TAppControl.GetMatchedApplicationIds(tAppControl);
- // if (matchedApplications.Count() > 0)
- // {
- // TAppControl.SendLaunchRequest(tAppControl);
- // return;
- // }
- // throw new PlatformNotSupportedException();
- // }
-
public void BeginInvokeOnMainThread(Action action)
{
s_context.Post((o) => action(), null);
}
- public Ticker CreateTicker()
- {
- return new TizenTicker();
- }
-
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
Console.WriteLine("TizenPlatformServices StartTimer ...");
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal class ToolbarItem : MenuItem
- {
- static readonly BindableProperty OrderProperty = BindableProperty.Create("Order", typeof(ToolbarItemOrder), typeof(ToolbarItem), ToolbarItemOrder.Default, validateValue: (bo, o) =>
- {
- var order = (ToolbarItemOrder)o;
- return order == ToolbarItemOrder.Default || order == ToolbarItemOrder.Primary || order == ToolbarItemOrder.Secondary;
- });
-
- static readonly BindableProperty PriorityProperty = BindableProperty.Create("Priority", typeof(int), typeof(ToolbarItem), 0);
-
- public ToolbarItem()
- {
- }
-
- public ToolbarItem(string name, string icon, Action activated, ToolbarItemOrder order = ToolbarItemOrder.Default, int priority = 0)
- {
- if (activated == null)
- throw new ArgumentNullException("activated");
-
- Text = name;
- Icon = icon;
- Clicked += (s, e) => activated();
- Order = order;
- Priority = priority;
- }
-
- [Obsolete("Name is obsolete as of version 1.3.0. Please use Text instead.")]
- public string Name
- {
- get { return Text; }
- set { Text = value; }
- }
-
- public ToolbarItemOrder Order
- {
- get { return (ToolbarItemOrder)GetValue(OrderProperty); }
- set { SetValue(OrderProperty, value); }
- }
-
- public int Priority
- {
- get { return (int)GetValue(PriorityProperty); }
- set { SetValue(PriorityProperty, value); }
- }
-
- [Obsolete("Activated is obsolete as of version 1.3.0. Please use Clicked instead.")]
- public event EventHandler Activated
- {
- add { Clicked += value; }
- remove { Clicked -= value; }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.Binding
-{
- internal class ToolbarItemEventArgs : EventArgs
- {
- public ToolbarItemEventArgs(ToolbarItem item)
- {
- ToolbarItem = item;
- }
-
- public ToolbarItem ToolbarItem { get; private set; }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Globalization;
-
-namespace Tizen.NUI.Binding
-{
- internal abstract class TypeConverter
- {
- public virtual bool CanConvertFrom(Type sourceType)
- {
- if (sourceType == null)
- throw new ArgumentNullException(nameof(sourceType));
-
- return sourceType == typeof(string);
- }
-
- [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")]
- public virtual object ConvertFrom(object o)
- {
- return null;
- }
-
- [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")]
- public virtual object ConvertFrom(CultureInfo culture, object o)
- {
- return null;
- }
-
- public virtual object ConvertFromInvariantString(string value)
- {
-#pragma warning disable 0618 // retain until ConvertFrom removed
- return ConvertFrom(CultureInfo.InvariantCulture, value);
-#pragma warning restore
- }
- }
-}
\ No newline at end of file
}
}
- var nativeValueConverterService = DependencyService.Get<INativeValueConverterService>();
-
- object nativeValue = null;
- if (nativeValueConverterService != null && nativeValueConverterService.ConvertTo(value, toType, out nativeValue))
- return nativeValue;
-
return value;
}
}
}
- internal override bool IsCreateByXaml
+ /// Only used by the IL of xaml, will never changed to not hidden.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool IsCreateByXaml
{
get
{
}
}
- internal override bool IsCreateByXaml
+ /// Only used by the IL of xaml, will never changed to not hidden.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool IsCreateByXaml
{
get
{
/// View is the base class for all views.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- [ContentProperty("Children")]
public class View : Container, IResourcesProvider
{
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
}
}
- internal Style Style
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Style Style
{
get
{
/// <since_tizen> 3 </since_tizen>
public class BaseHandle : Element, global::System.IDisposable
{
- internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation));
-
- /// <summary>
- /// Backing store for the Navigation property.
- /// </summary>
- internal static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty;
-
/// <summary>
/// swigCMemOwn
/// </summary>
}
}
- /// <summary>
- /// For internal use.
- /// </summary>
- internal NavigationProxy NavigationProxy
- {
- get { return Navigation as NavigationProxy; }
- }
-
- /// <summary>
- /// Gets the navigation.
- /// </summary>
- internal INavigation Navigation
- {
- get { return (INavigation)GetValue(NavigationProperty); }
- set { SetValue(NavigationPropertyKey, value); }
- }
-
/// <summary>
/// Returns the bool value true to indicate that an operand is true and returns false otherwise.
/// </summary>
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
namespace Tizen.NUI
{
protected override void OnCreate()
{
base.OnCreate();
- Device.PlatformServices = new TizenPlatformServices();
}
}
}
}
- internal override bool IsCreateByXaml
+ /// Only used by the IL of xaml, will never changed to not hidden.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool IsCreateByXaml
{
get
{
}
}
- internal override bool IsCreateByXaml
+ /// Only used by the IL of xaml, will never changed to not hidden.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool IsCreateByXaml
{
get
{
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IMarkupExtension<out T> : IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ new T ProvideValue(IServiceProvider serviceProvider);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object ProvideValue(IServiceProvider serviceProvider);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [AttributeUsage(AttributeTargets.Class, Inherited = false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class AcceptEmptyServiceProviderAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IProvideValueTarget
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object TargetObject { get; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object TargetProperty { get; }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IReferenceProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object FindByName(string name);
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal interface IRootObjectProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object RootObject { get; }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IValueProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object ProvideValue(IServiceProvider serviceProvider);
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IXamlTypeResolver
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider = null);
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ bool TryResolve(string qualifiedTypeName, out Type type);
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+using System.Xml;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IXmlLineInfoProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ IXmlLineInfo XmlLineInfo { get; }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Items")]
+ [AcceptEmptyServiceProvider]
+ public class ArrayExtension : IMarkupExtension<Array>
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ArrayExtension()
+ {
+ Items = new List<object>();
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList Items { get; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type Type { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Array ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (Type == null)
+ throw new InvalidOperationException("Type argument mandatory for x:Array extension");
+
+ if (Items == null)
+ return null;
+
+ var array = Array.CreateInstance(Type, Items.Count);
+ for (var i = 0; i < Items.Count; i++)
+ ((IList)array)[i] = Items[i];
+
+ return array;
+ }
+
+ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return (this as IMarkupExtension<Array>).ProvideValue(serviceProvider);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Binding;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Path")]
+ [AcceptEmptyServiceProvider]
+ public sealed class BindingExtension : IMarkupExtension<BindingBase>
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Path { get; set; } = Binding.Binding.SelfPath;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingMode Mode { get; set; } = BindingMode.Default;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IValueConverter Converter { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ConverterParameter { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string StringFormat { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Source { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string UpdateSourceEventName { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object TargetNullValue { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object FallbackValue { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ 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,
+ FallbackValue = FallbackValue,
+ TargetNullValue = TargetNullValue,
+ };
+
+ TypedBinding.Mode = Mode;
+ TypedBinding.Converter = Converter;
+ TypedBinding.ConverterParameter = ConverterParameter;
+ TypedBinding.StringFormat = StringFormat;
+ TypedBinding.Source = Source;
+ TypedBinding.UpdateSourceEventName = UpdateSourceEventName;
+ TypedBinding.FallbackValue = FallbackValue;
+ TypedBinding.TargetNullValue = TargetNullValue;
+ return TypedBinding;
+ }
+
+ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return (this as IMarkupExtension<BindingBase>).ProvideValue(serviceProvider);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Binding.Internals;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Key")]
+ public sealed class DynamicResourceExtension : IMarkupExtension<DynamicResource>
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Key { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ return ((IMarkupExtension<DynamicResource>)this).ProvideValue(serviceProvider);
+ }
+
+ DynamicResource IMarkupExtension<DynamicResource>.ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (Key == null)
+ {
+ var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
+ throw new XamlParseException("DynamicResource markup require a Key", lineInfo);
+ }
+ return new DynamicResource(Key);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.NullExtension")]
+ [AcceptEmptyServiceProvider]
+ public class NullExtension : IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ return null;
+ }
+ }
+}
--- /dev/null
+using System;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Xaml.Internals;
+using Tizen.NUI.Binding;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Name")]
+ public class ReferenceExtension : IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Name { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (serviceProvider == null)
+ throw new ArgumentNullException(nameof(serviceProvider));
+ var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues;
+ if (valueProvider == null)
+ throw new ArgumentException("serviceProvider does not provide an IProvideValueTarget");
+ var namescopeprovider = serviceProvider.GetService(typeof (INameScopeProvider)) as INameScopeProvider;
+ if (namescopeprovider != null && namescopeprovider.NameScope != null)
+ {
+ var value = namescopeprovider.NameScope.FindByName(Name);
+ if (value != null)
+ return value;
+ }
+
+ foreach (var target in valueProvider.ParentObjects)
+ {
+ var bo = target as BindableObject;
+ if (bo == null)
+ continue;
+ var ns = NameScope.GetNameScope(bo) as INameScope;
+ if (ns == null)
+ continue;
+ var value = ns.FindByName(Name);
+ if (value != null)
+ return value;
+ }
+ //foreach (var target in valueProvider.ParentObjects)
+ //{
+ // var ns = target as INameScope;
+ // if (ns == null)
+ // continue;
+ // var value = ns.FindByName(Name);
+ // if (value != null)
+ // return value;
+ //}
+
+ var lineInfo = (serviceProvider?.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo ?? new XmlLineInfo();
+ throw new XamlParseException($"Can not find the object referenced by `{Name}`", lineInfo);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Xml;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty(nameof(Member))]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.StaticExtension")]
+ public class StaticExtension : IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Member { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ IXmlLineInfoProvider lineInfoProvider;
+ IXmlLineInfo lineInfo;
+
+ if (serviceProvider == null)
+ throw new ArgumentNullException(nameof(serviceProvider));
+ var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver;
+ if (typeResolver == null)
+ throw new ArgumentException("No IXamlTypeResolver in IServiceProvider");
+
+ if (string.IsNullOrEmpty(Member) || !Member.Contains("."))
+ {
+ lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
+ throw new XamlParseException("Syntax for x:Static is [Member=][prefix:]typeName.staticMemberName", lineInfo);
+ }
+
+ var dotIdx = Member.LastIndexOf('.');
+ var typename = Member.Substring(0, dotIdx);
+ var membername = Member.Substring(dotIdx + 1);
+
+ var type = typeResolver.Resolve(typename, serviceProvider);
+
+ var pinfo = type.GetRuntimeProperties().FirstOrDefault(pi => pi.GetMethod != null && pi.Name == membername && pi.GetMethod.IsStatic);
+ if (pinfo != null)
+ return pinfo.GetMethod?.Invoke(null, Array.Empty<object>());
+
+ var finfo = type.GetRuntimeFields().FirstOrDefault(fi => fi.Name == membername && fi.IsStatic);
+ if (finfo != null)
+ return finfo.GetValue(null);
+
+ lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
+ throw new XamlParseException($"No static member found for {Member}", lineInfo);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Xml;
+using Tizen.NUI.StyleSheets;
+using System.Reflection;
+using System.IO;
+using Tizen.NUI.Binding;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty(nameof(Style))]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
+ public sealed class StyleSheetExtension : IValueProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Style { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Uri Source { get; set; }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ IXmlLineInfo lineInfo;
+
+ if (!string.IsNullOrEmpty(Style) && Source != null) {
+ lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
+ throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo);
+ }
+
+ if (Source != null) {
+ lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
+ if (Source.IsAbsoluteUri)
+ throw new XamlParseException($"Source only accepts Relative URIs", lineInfo);
+
+ var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType();
+ if (rootObjectType == null)
+ return null;
+ var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
+ var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath);
+ var resString = DependencyService.Get<IResourcesLoader>()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
+ return StyleSheet.FromString(resString);
+ }
+
+ if (!string.IsNullOrEmpty(Style)) {
+ using (var reader = new StringReader(Style))
+ return StyleSheet.FromReader(reader);
+ }
+
+ lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
+ throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Path")]
+ [AcceptEmptyServiceProvider]
+ public sealed class TemplateBindingExtension : IMarkupExtension<BindingBase>
+ {
+ internal TemplateBindingExtension()
+ {
+ Mode = BindingMode.Default;
+ Path = Tizen.NUI.Binding.Binding.SelfPath;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Path { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingMode Mode { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IValueConverter Converter { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ConverterParameter { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string StringFormat { get; set; }
+
+ BindingBase IMarkupExtension<BindingBase>.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return new TemplateBinding(Path, Mode, Converter, ConverterParameter, StringFormat);
+ }
+
+ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return (this as IMarkupExtension<BindingBase>).ProvideValue(serviceProvider);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Xaml
+{
+ [ContentProperty(nameof(TypeName))]
+ [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.TypeExtension")]
+ internal class TypeExtension : IMarkupExtension<Type>
+ {
+ public string TypeName { get; set; }
+
+ public Type ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (string.IsNullOrEmpty(TypeName))
+ throw new InvalidOperationException("TypeName isn't set.");
+ if (serviceProvider == null)
+ throw new ArgumentNullException(nameof(serviceProvider));
+ var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver;
+ if (typeResolver == null)
+ throw new ArgumentException("No IXamlTypeResolver in IServiceProvider");
+
+ return typeResolver.Resolve(TypeName, serviceProvider);
+ }
+
+ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return (this as IMarkupExtension<Type>).ProvideValue(serviceProvider);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Xml;
+using System.Reflection;
+using System.Linq;
+using Tizen.NUI.Binding;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Key")]
+ public sealed class StaticResourceExtension : IMarkupExtension
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Key { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (serviceProvider == null)
+ throw new ArgumentNullException(nameof(serviceProvider));
+ if (Key == null) {
+ var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
+ throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo);
+ }
+ var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
+ if (valueProvider == null)
+ throw new ArgumentException();
+ var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null;
+ object resource = null;
+
+ foreach (var p in valueProvider.ParentObjects) {
+ var irp = p as IResourcesProvider;
+ var resDict = irp != null && irp.IsResourcesCreated ? irp.XamlResources : p as ResourceDictionary;
+ if (resDict == null)
+ continue;
+ if (resDict.TryGetValue(Key, out resource))
+ break;
+ }
+ resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo);
+
+ var bp = valueProvider.TargetProperty as BindableProperty;
+ var pi = valueProvider.TargetProperty as PropertyInfo;
+ var propertyType = bp?.ReturnType ?? pi?.PropertyType;
+ if (propertyType == null) {
+ if (resource != null) {
+ if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) {
+ // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty
+ var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() });
+ if (method != null) {
+ resource = method.Invoke(null, new[] { resource });
+ }
+ }
+ }
+ return resource;
+ }
+ if (propertyType.IsAssignableFrom(resource?.GetType()))
+ return resource;
+ var implicit_op = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType)
+ ?? propertyType.GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType);
+ if (implicit_op != null)
+ return implicit_op.Invoke(resource, new [] { resource });
+
+ if (resource != null) {
+ //Special case for https://bugzilla.xamarin.com/show_bug.cgi?id=59818
+ //On OnPlatform, check for an opImplicit from the targetType
+ if ( Device.Flags != null
+ && Device.Flags.Contains("xamlDoubleImplicitOpHack")
+ && resource.GetType().GetTypeInfo().IsGenericType
+ && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>))) {
+ var tType = resource.GetType().GenericTypeArguments[0];
+ var opImplicit = tType.GetImplicitConversionOperator(fromType: tType, toType: propertyType)
+ ?? propertyType.GetImplicitConversionOperator(fromType: tType, toType: propertyType);
+
+ if (opImplicit != null) {
+ //convert the OnPlatform<T> to T
+ var opPlatformImplicitConversionOperator = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: tType);
+ resource = opPlatformImplicitConversionOperator?.Invoke(null, new[] { resource });
+
+ //and convert to toType
+ resource = opImplicit.Invoke(null, new[] { resource });
+ return resource;
+ }
+ }
+ }
+ return resource;
+ }
+
+ internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo)
+ {
+ object resource = null;
+ if (Application.Current == null || !((IResourcesProvider)Application.Current).IsResourcesCreated || !Application.Current.XamlResources.TryGetValue(Key, out resource))
+ throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
+ return resource;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [System.AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
+ public sealed class TypeConversionAttribute : Attribute
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type TargetType { get; private set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TypeConversionAttribute(Type targetType)
+ {
+ TargetType = targetType;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Flags]
+ public enum XamlCompilationOptions
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ Skip = 1 << 0,
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ Compile = 1 << 1
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class, Inherited = false)]
+ public sealed class XamlCompilationAttribute : Attribute
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlCompilationAttribute(XamlCompilationOptions xamlCompilationOptions)
+ {
+ XamlCompilationOptions = xamlCompilationOptions;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlCompilationOptions XamlCompilationOptions { get; set; }
+ }
+
+ internal static class XamlCExtensions
+ {
+ public static bool IsCompiled(this Type type)
+ {
+ var attr = type.GetTypeInfo().GetCustomAttribute<XamlCompilationAttribute>();
+ if (attr != null)
+ return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
+ attr = type.GetTypeInfo().Module.GetCustomAttribute<XamlCompilationAttribute>();
+ if (attr != null)
+ return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
+ attr = type.GetTypeInfo().Assembly.GetCustomAttribute<XamlCompilationAttribute>();
+ if (attr != null)
+ return attr.XamlCompilationOptions == XamlCompilationOptions.Compile;
+
+ return false;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
+ public sealed class XamlFilePathAttribute : Attribute
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlFilePathAttribute([CallerFilePath] string filePath = "")
+ {
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Text;
+using System.Xml;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XamlParseException : Exception
+ {
+ readonly string _unformattedMessage;
+
+ 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;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException)
+ {
+ _unformattedMessage = message;
+ XmlInfo = xmlInfo;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IXmlLineInfo XmlInfo { get; private set; }
+
+ internal string UnformattedMessage
+ {
+ get { return _unformattedMessage ?? Message; }
+ }
+
+ static string FormatMessage(string message, IXmlLineInfo xmlinfo)
+ {
+ if (xmlinfo == null || !xmlinfo.HasLineInfo())
+ return message;
+ return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Reflection;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
+ public sealed class XamlResourceIdAttribute : Attribute
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string ResourceId { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Path { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type Type { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlResourceIdAttribute(string resourceId, string path, Type type)
+ {
+ ResourceId = resourceId;
+ Path = path;
+ Type = type;
+ }
+
+ internal static string GetResourceIdForType(Type type)
+ {
+ var assembly = type.GetTypeInfo().Assembly;
+ foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
+ if (xria.Type == type)
+ return xria.ResourceId;
+ }
+ return null;
+ }
+
+ internal static string GetPathForType(Type type)
+ {
+ var assembly = type.GetTypeInfo().Assembly;
+ foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
+ if (xria.Type == type)
+ return xria.Path;
+ }
+ return null;
+ }
+
+ internal static string GetResourceIdForPath(Assembly assembly, string path)
+ {
+ foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
+ if (xria.Path == path)
+ return xria.ResourceId;
+ }
+ return null;
+ }
+
+ internal static Type GetTypeForResourceId(Assembly assembly, string resourceId)
+ {
+ foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
+ if (xria.ResourceId == resourceId)
+ return xria.Type;
+ }
+ return null;
+ }
+
+ internal static Type GetTypeForPath(Assembly assembly, string path)
+ {
+ foreach (var xria in assembly.GetCustomAttributes<XamlResourceIdAttribute>()) {
+ if (xria.Path == path)
+ return xria.Type;
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Reflection;
+using System.Xml;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Binding.Internals;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XamlServiceProvider : IServiceProvider
+ {
+ readonly Dictionary<Type, object> services = new Dictionary<Type, object>();
+
+ internal XamlServiceProvider(INode node, HydrationContext context)
+ {
+ object targetObject;
+ if (node != null && node.Parent != null && context.Values.TryGetValue(node.Parent, out targetObject))
+ IProvideValueTarget = new XamlValueTargetProvider(targetObject, node, context, null);
+ if (context != null)
+ IRootObjectProvider = new XamlRootObjectProvider(context.RootElement);
+ if (node != null)
+ {
+ IXamlTypeResolver = new XamlTypeResolver(node.NamespaceResolver, XamlParser.GetElementType,
+ context?.RootElement.GetType().GetTypeInfo().Assembly);
+
+ Add(typeof(IReferenceProvider), new ReferenceProvider(node));
+ }
+
+ var xmlLineInfo = node as IXmlLineInfo;
+ if (xmlLineInfo != null)
+ IXmlLineInfoProvider = new XmlLineInfoProvider(xmlLineInfo);
+
+ IValueConverterProvider = new ValueConverterProvider();
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlServiceProvider()
+ {
+ IValueConverterProvider = new ValueConverterProvider();
+ }
+
+ internal IProvideValueTarget IProvideValueTarget
+ {
+ get { return (IProvideValueTarget)GetService(typeof (IProvideValueTarget)); }
+ set { services[typeof (IProvideValueTarget)] = value; }
+ }
+
+ internal IXamlTypeResolver IXamlTypeResolver
+ {
+ get { return (IXamlTypeResolver)GetService(typeof (IXamlTypeResolver)); }
+ set { services[typeof (IXamlTypeResolver)] = value; }
+ }
+
+ internal IRootObjectProvider IRootObjectProvider
+ {
+ get { return (IRootObjectProvider)GetService(typeof (IRootObjectProvider)); }
+ set { services[typeof (IRootObjectProvider)] = value; }
+ }
+
+ internal IXmlLineInfoProvider IXmlLineInfoProvider
+ {
+ get { return (IXmlLineInfoProvider)GetService(typeof (IXmlLineInfoProvider)); }
+ set { services[typeof (IXmlLineInfoProvider)] = value; }
+ }
+
+ internal INameScopeProvider INameScopeProvider
+ {
+ get { return (INameScopeProvider)GetService(typeof (INameScopeProvider)); }
+ set { services[typeof (INameScopeProvider)] = value; }
+ }
+
+ internal IValueConverterProvider IValueConverterProvider
+ {
+ get { return (IValueConverterProvider)GetService(typeof (IValueConverterProvider)); }
+ set { services[typeof (IValueConverterProvider)] = value; }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object GetService(Type serviceType)
+ {
+ object service;
+ return services.TryGetValue(serviceType, out service) ? service : null;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Add(Type type, object service)
+ {
+ services.Add(type, service);
+ }
+ }
+
+ internal class XamlValueTargetProvider : IProvideParentValues, IProvideValueTarget
+ {
+ public XamlValueTargetProvider(object targetObject, INode node, HydrationContext context, object targetProperty)
+ {
+ Context = context;
+ Node = node;
+ TargetObject = targetObject;
+ TargetProperty = targetProperty;
+ }
+
+ INode Node { get; }
+
+ HydrationContext Context { get; }
+ public object TargetObject { get; }
+ public object TargetProperty { get; internal set; } = null;
+
+ IEnumerable<object> IProvideParentValues.ParentObjects
+ {
+ get
+ {
+ if (Node == null || Context == null)
+ yield break;
+ var n = Node;
+ object obj = null;
+ var context = Context;
+ while (n.Parent != null && context != null)
+ {
+ if (n.Parent is IElementNode)
+ {
+ if (context.Values.TryGetValue(n.Parent, out obj))
+ yield return obj;
+ else
+ {
+ context = context.ParentContext;
+ continue;
+ }
+ }
+ n = n.Parent;
+ }
+ }
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget, IReferenceProvider
+ {
+ readonly object[] objectAndParents;
+ readonly object targetProperty;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("SimpleValueTargetProvider(object[] objectAndParents) is obsolete as of version 2.3.4. Please use SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) instead.")]
+ public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null)
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty)
+ {
+ if (objectAndParents == null)
+ throw new ArgumentNullException(nameof(objectAndParents));
+ if (objectAndParents.Length == 0)
+ throw new ArgumentException();
+
+ this.objectAndParents = objectAndParents;
+ this.targetProperty = targetProperty;
+ }
+
+ IEnumerable<object> IProvideParentValues.ParentObjects
+ => objectAndParents;
+
+ object IProvideValueTarget.TargetObject
+ => objectAndParents[0];
+
+ object IProvideValueTarget.TargetProperty
+ => targetProperty;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object FindByName(string name)
+ {
+ for (var i = 0; i < objectAndParents.Length; i++) {
+ var bo = objectAndParents[i] as BindableObject;
+ if (bo == null) continue;
+ var ns = NameScope.GetNameScope(bo) as INameScope;
+ if (ns == null) continue;
+ var value = ns.FindByName(name);
+ if (value != null)
+ return value;
+ }
+ return null;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XamlTypeResolver : IXamlTypeResolver
+ {
+ readonly Assembly currentAssembly;
+ readonly GetTypeFromXmlName getTypeFromXmlName;
+ readonly IXmlNamespaceResolver namespaceResolver;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, Assembly currentAssembly)
+ : this(namespaceResolver, XamlParser.GetElementType, currentAssembly)
+ {
+ }
+
+ internal XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, GetTypeFromXmlName getTypeFromXmlName,
+ Assembly currentAssembly)
+ {
+ this.currentAssembly = currentAssembly;
+ if (namespaceResolver == null)
+ throw new ArgumentNullException();
+ if (getTypeFromXmlName == null)
+ throw new ArgumentNullException();
+
+ this.namespaceResolver = namespaceResolver;
+ this.getTypeFromXmlName = getTypeFromXmlName;
+ }
+
+ Type IXamlTypeResolver.Resolve(string qualifiedTypeName, IServiceProvider serviceProvider)
+ {
+ XamlParseException e;
+ var type = Resolve(qualifiedTypeName, serviceProvider, out e);
+ if (e != null)
+ throw e;
+ return type;
+ }
+
+ bool IXamlTypeResolver.TryResolve(string qualifiedTypeName, out Type type)
+ {
+ XamlParseException exception;
+ type = Resolve(qualifiedTypeName, null, out exception);
+ return exception == null;
+ }
+
+ Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider, out XamlParseException exception)
+ {
+ exception = null;
+ var split = qualifiedTypeName.Split(':');
+ if (split.Length > 2)
+ return null;
+
+ string prefix, name;
+ if (split.Length == 2)
+ {
+ prefix = split[0];
+ name = split[1];
+ }
+ else
+ {
+ prefix = "";
+ name = split[0];
+ }
+
+ IXmlLineInfo xmlLineInfo = null;
+ if (serviceProvider != null)
+ {
+ var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ if (lineInfoProvider != null)
+ xmlLineInfo = lineInfoProvider.XmlLineInfo;
+ }
+
+ var namespaceuri = namespaceResolver.LookupNamespace(prefix);
+ if (namespaceuri == null)
+ {
+ exception = new XamlParseException(string.Format("No xmlns declaration for prefix \"{0}\"", prefix), xmlLineInfo);
+ return null;
+ }
+
+ return getTypeFromXmlName(new XmlType(namespaceuri, name, null), xmlLineInfo, currentAssembly, out exception);
+ }
+
+ internal delegate Type GetTypeFromXmlName(
+ XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, out XamlParseException exception);
+ }
+
+ internal class XamlRootObjectProvider : IRootObjectProvider
+ {
+ public XamlRootObjectProvider(object rootObject)
+ {
+ RootObject = rootObject;
+ }
+
+ public object RootObject { get; }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XmlLineInfoProvider : IXmlLineInfoProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XmlLineInfoProvider(IXmlLineInfo xmlLineInfo)
+ {
+ XmlLineInfo = xmlLineInfo;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IXmlLineInfo XmlLineInfo { get; }
+ }
+
+ class ReferenceProvider : IReferenceProvider
+ {
+ readonly INode _node;
+ internal ReferenceProvider(INode node)
+ => _node = node;
+
+ public object FindByName(string name)
+ {
+ var n = _node;
+ object value = null;
+ while (n != null) {
+ if ((value = (n as IElementNode)?.Namescope?.FindByName(name)) != null)
+ return value;
+ n = n.Parent;
+ }
+ return null;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete]
+ public class NameScopeProvider : INameScopeProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public INameScope NameScope { get; set; }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XmlNamespaceResolver : IXmlNamespaceResolver
+ {
+ readonly Dictionary<string, string> namespaces = new Dictionary<string, string>();
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
+ {
+ throw new NotImplementedException();
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string LookupNamespace(string prefix)
+ {
+ string result;
+ if (namespaces.TryGetValue(prefix, out result))
+ return result;
+ return null;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string LookupPrefix(string namespaceName)
+ {
+ throw new NotImplementedException();
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Add(string prefix, string ns)
+ {
+ namespaces.Add(prefix, ns);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+using System.Xml;
+
+namespace Tizen.NUI.Xaml
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class XmlLineInfo : IXmlLineInfo
+ {
+ readonly bool _hasLineInfo;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XmlLineInfo()
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XmlLineInfo(int linenumber, int lineposition)
+ {
+ _hasLineInfo = true;
+ LineNumber = linenumber;
+ LinePosition = lineposition;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool HasLineInfo()
+ {
+ return _hasLineInfo;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public int LineNumber { get; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public int LinePosition { get; }
+ }
+}
\ No newline at end of file
/// </summary>
/// <param name="targetProperty">The BindableProperty on which to set a binding.</param>
/// <param name="binding">The binding to set.</param>
- internal void SetBinding(BindableProperty targetProperty, BindingBase binding)
+ /// 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 void SetBinding(BindableProperty targetProperty, BindingBase binding)
{
SetBinding(targetProperty, binding, false);
}
private bool isCreateByXaml = false;
- internal virtual bool IsCreateByXaml
+ /// Only used by the IL of xaml, will never changed to not hidden.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual bool IsCreateByXaml
{
get
{
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Linq.Expressions;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static class BindableObjectExtensions
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null,
+ string stringFormat = null)
+ {
+ if (self == null)
+ throw new ArgumentNullException("self");
+ if (targetProperty == null)
+ throw new ArgumentNullException("targetProperty");
+
+ var binding = new Binding(path, mode, converter, stringFormat: stringFormat);
+ self.SetBinding(targetProperty, binding);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete]
+ public static void SetBinding<TSource>(this BindableObject self, BindableProperty targetProperty, Expression<Func<TSource, object>> sourceProperty, BindingMode mode = BindingMode.Default,
+ IValueConverter converter = null, string stringFormat = null)
+ {
+ if (self == null)
+ throw new ArgumentNullException("self");
+ if (targetProperty == null)
+ throw new ArgumentNullException("targetProperty");
+ if (sourceProperty == null)
+ throw new ArgumentNullException("sourceProperty");
+
+ Binding binding = Binding.Create(sourceProperty, mode, converter, stringFormat: stringFormat);
+ self.SetBinding(targetProperty, binding);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.ComponentModel;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// <summary>
+ /// A BindableProperty is a backing store for properties allowing bindings on BindableObject.
+ /// </summary>
+ [DebuggerDisplay("{PropertyName}")]
+ [TypeConverter(typeof(BindablePropertyConverter))]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class BindableProperty
+ {
+ /// <summary>
+ /// Delegate for BindableProperty.PropertyChanged.
+ /// </summary>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="oldValue">The old property value.</param>
+ /// <param name="newValue">The new property value.</param>
+ public delegate void BindingPropertyChangedDelegate(BindableObject bindable, object oldValue, object newValue);
+
+ /// <summary>
+ /// Strongly-typed delegate for BindableProperty.PropertyChanged.
+ /// </summary>
+ /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="oldValue">The old property value.</param>
+ /// <param name="newValue">The new property value.</param>
+ public delegate void BindingPropertyChangedDelegate<in TPropertyType>(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue);
+
+ /// <summary>
+ /// Delegate for BindableProperty.PropertyChanging.
+ /// </summary>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="oldValue">The old property value.</param>
+ /// <param name="newValue">The new property value.</param>
+ public delegate void BindingPropertyChangingDelegate(BindableObject bindable, object oldValue, object newValue);
+
+ /// <summary>
+ /// Strongly-typed delegate for BindableProperty.PropertyChanging.
+ /// </summary>
+ /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="oldValue">The old property value.</param>
+ /// <param name="newValue">The new property value.</param>
+ public delegate void BindingPropertyChangingDelegate<in TPropertyType>(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue);
+
+ /// <summary>
+ /// Delegate for BindableProperty.CoerceValue.
+ /// </summary>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="value">The value to coerce.</param>
+ /// <returns>System.Object</returns>
+ public delegate object CoerceValueDelegate(BindableObject bindable, object value);
+
+ /// <summary>
+ /// Strongly-typed delegate for BindableProperty.CoerceValue.
+ /// </summary>
+ /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="value">The value to coerce.</param>
+ /// <returns>TPropertyType</returns>
+ public delegate TPropertyType CoerceValueDelegate<TPropertyType>(BindableObject bindable, TPropertyType value);
+
+ /// <summary>
+ /// Delegate for BindableProperty.DefaultValueCreator.
+ /// </summary>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <returns>System.Object</returns>
+ public delegate object CreateDefaultValueDelegate(BindableObject bindable);
+
+ /// <summary>
+ /// Strongly-typed delegate for BindableProperty.DefaultValueCreator.
+ /// </summary>
+ /// <typeparam name="TDeclarer">The type of the object that delared the property.</typeparam>
+ /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <returns>TPropertyType</returns>
+ public delegate TPropertyType CreateDefaultValueDelegate<in TDeclarer, out TPropertyType>(TDeclarer bindable);
+
+ /// <summary>
+ /// Delegate for BindableProperty.ValidateValue.
+ /// </summary>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="value">The default value.</param>
+ /// <returns>System.Boolean</returns>
+ public delegate bool ValidateValueDelegate(BindableObject bindable, object value);
+
+ /// <summary>
+ /// Strongly-typed delegate for BindableProperty.ValidateValue.
+ /// </summary>
+ /// <typeparam name="TPropertyType">The type of the bound property.</typeparam>
+ /// <param name="bindable">The bindable object that contains the property.</param>
+ /// <param name="value">The default value.</param>
+ /// <returns>System.Boolean</returns>
+ public delegate bool ValidateValueDelegate<in TPropertyType>(BindableObject bindable, TPropertyType value);
+
+ static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type,TypeConverter>
+ {
+ { 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(Vector2), new Vector2TypeConverter() },
+ { typeof(Vector3), new Vector3TypeConverter() },
+ { typeof(Vector4), new Vector4TypeConverter() },
+ { typeof(RelativeVector2), new RelativeVector2TypeConverter() },
+ { typeof(RelativeVector3), new RelativeVector3TypeConverter() },
+ { typeof(RelativeVector4), new RelativeVector4TypeConverter() },
+ };
+
+ //Modification for NUI XAML : user defined converter for DynamicResource can be added
+ static internal Dictionary<Type, TypeConverter> UserCustomConvertTypes = new Dictionary<Type, TypeConverter>
+ {
+ };
+
+ // more or less the encoding of this, without the need to reflect
+ // http://msdn.microsoft.com/en-us/library/y5b434w4.aspx
+ static readonly Dictionary<Type, Type[]> SimpleConvertTypes = new Dictionary<Type, Type[]>
+ {
+ { typeof(sbyte), new[] { typeof(string), typeof(short), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(byte), new[] { typeof(string), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(short), new[] { typeof(string), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(ushort), new[] { typeof(string), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(int), new[] { typeof(string), typeof(long), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(uint), new[] { typeof(string), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(long), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(char), new[] { typeof(string), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
+ { typeof(float), new[] { typeof(string), typeof(double) } },
+ { typeof(ulong), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } }
+ };
+
+ BindableProperty(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
+ ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
+ CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ if (propertyName == null)
+ throw new ArgumentNullException("propertyName");
+ if (ReferenceEquals(returnType, null))
+ throw new ArgumentNullException("returnType");
+ if (ReferenceEquals(declaringType, null))
+ throw new ArgumentNullException("declaringType");
+
+ // don't use Enum.IsDefined as its redonkulously expensive for what it does
+ if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime)
+ throw new ArgumentException("Not a valid type of BindingMode", "defaultBindingMode");
+ if (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.GetTypeInfo().IsValueType)
+ throw new ArgumentException("Not a valid default value", "defaultValue");
+ if (defaultValue != null && !returnType.IsInstanceOfType(defaultValue))
+ throw new ArgumentException("Default value did not match return type", "defaultValue");
+ if (defaultBindingMode == BindingMode.Default)
+ defaultBindingMode = BindingMode.OneWay;
+
+ PropertyName = propertyName;
+ ReturnType = returnType;
+ ReturnTypeInfo = returnType.GetTypeInfo();
+ DeclaringType = declaringType;
+ DefaultValue = defaultValue;
+ DefaultBindingMode = defaultBindingMode;
+ PropertyChanged = propertyChanged;
+ PropertyChanging = propertyChanging;
+ ValidateValue = validateValue;
+ CoerceValue = coerceValue;
+ BindingChanging = bindingChanging;
+ IsReadOnly = isReadOnly;
+ DefaultValueCreator = defaultValueCreator;
+ }
+
+ /// <summary>
+ /// Gets the type declaring the BindableProperty.
+ /// </summary>
+ public Type DeclaringType { get; private set; }
+
+ /// <summary>
+ /// Gets the default BindingMode.
+ /// </summary>
+ public BindingMode DefaultBindingMode { get; private set; }
+
+ /// <summary>
+ /// Gets the default value for the BindableProperty.
+ /// </summary>
+ public object DefaultValue { get; }
+
+ /// <summary>
+ /// Gets a value indicating if the BindableProperty is created form a BindablePropertyKey.
+ /// </summary>
+ public bool IsReadOnly { get; private set; }
+
+ /// <summary>
+ /// Gets the property name.
+ /// </summary>
+ public string PropertyName { get; }
+
+ /// <summary>
+ /// Gets the type of the BindableProperty.
+ /// </summary>
+ public Type ReturnType { get; }
+
+ internal BindablePropertyBindingChanging BindingChanging { get; private set; }
+
+ internal CoerceValueDelegate CoerceValue { get; private set; }
+
+ internal CreateDefaultValueDelegate DefaultValueCreator { get; }
+
+ internal BindingPropertyChangedDelegate PropertyChanged { get; private set; }
+
+ internal BindingPropertyChangingDelegate PropertyChanging { get; private set; }
+
+ internal System.Reflection.TypeInfo ReturnTypeInfo { get; }
+
+ internal ValidateValueDelegate ValidateValue { get; private set; }
+
+ /// <summary>
+ /// Deprecated. Do not use.
+ /// </summary>
+ /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
+ /// <typeparam name="TPropertyType">The type of the property.</typeparam>
+ /// <param name="getter">An expression identifying the getter for the property using this BindableProperty as backing store.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created BindableProperty.</returns>
+ [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ public static BindableProperty Create<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
+ ValidateValueDelegate<TPropertyType> validateValue = null, BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null,
+ BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null, CoerceValueDelegate<TPropertyType> coerceValue = null,
+ CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
+ {
+ return Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, defaultValueCreator: defaultValueCreator);
+ }
+
+ /// <summary>
+ /// Creates a new instance of the BindableProperty class.
+ /// </summary>
+ /// <param name="propertyName">The name of the BindableProperty.</param>
+ /// <param name="returnType">The type of the property.</param>
+ /// <param name="declaringType">The type of the declaring object.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created BindableProperty.</returns>
+ public static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay,
+ ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
+ CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue,
+ defaultValueCreator: defaultValueCreator);
+ }
+
+ /// <summary>
+ /// Deprecated. Do not use.
+ /// </summary>
+ /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
+ /// <typeparam name="TPropertyType">The type of the property.</typeparam>
+ /// <param name="staticgetter">An expression identifying a static method returning the value of the property using this BindableProperty as backing store.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ public static BindableProperty CreateAttached<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue,
+ BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate<TPropertyType> validateValue = null, BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null,
+ BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null, CoerceValueDelegate<TPropertyType> coerceValue = null,
+ CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
+ {
+ return CreateAttached<TDeclarer, TPropertyType>(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null,
+ defaultValueCreator: defaultValueCreator);
+ }
+
+ /// <summary>
+ /// Creates a new instance of the BindableProperty class for an attached property.
+ /// </summary>
+ /// <param name="propertyName">The name of the BindableProperty.</param>
+ /// <param name="returnType">The type of the property.</param>
+ /// <param name="declaringType">The type of the declaring object.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created BindableProperty.</returns>
+ public static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
+ ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
+ CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, false, defaultValueCreator);
+ }
+
+ /// <summary>
+ /// Deprecated. Do not use.
+ /// </summary>
+ /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
+ /// <typeparam name="TPropertyType">The type of the property.</typeparam>
+ /// <param name="staticgetter">An expression identifying a static method returning the value of the property using this BindableProperty as backing store.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created attached read-only BindablePropertyKey.</returns>
+ [Obsolete("CreateAttachedReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ public static BindablePropertyKey CreateAttachedReadOnly<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue,
+ BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate<TPropertyType> validateValue = null,
+ BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null,
+ CoerceValueDelegate<TPropertyType> coerceValue = null, CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
+
+ {
+ return
+ new BindablePropertyKey(CreateAttached<TDeclarer, TPropertyType>(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true,
+ defaultValueCreator));
+ }
+
+ /// <summary>
+ /// Creates a new instance of the BindableProperty class for attached read-only properties.
+ /// </summary>
+ /// <param name="propertyName">The name of the BindableProperty.</param>
+ /// <param name="returnType">The type of the property.</param>
+ /// <param name="declaringType">The type of the declaring object.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created attached read-only BindablePropertyKey.</returns>
+ public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource,
+ ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
+ CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return
+ new BindablePropertyKey(CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true,
+ defaultValueCreator));
+ }
+
+ /// <summary>
+ /// Deprecated. Do not use.
+ /// </summary>
+ /// <typeparam name="TDeclarer">The type of the declaring object.</typeparam>
+ /// <typeparam name="TPropertyType">The type of the property.</typeparam>
+ /// <param name="getter">An expression identifying the getter for the property using this BindableProperty as backing store.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created BindablePropertyKey.</returns>
+ [Obsolete("CreateReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ public static BindablePropertyKey CreateReadOnly<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue,
+ BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate<TPropertyType> validateValue = null,
+ BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null,
+ CoerceValueDelegate<TPropertyType> coerceValue = null, CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
+ {
+ return new BindablePropertyKey(Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, defaultValueCreator));
+ }
+
+ /// <summary>
+ /// Creates a new instance of the BindablePropertyKey class.
+ /// </summary>
+ /// <param name="propertyName">The name of the BindableProperty.</param>
+ /// <param name="returnType">The type of the property.</param>
+ /// <param name="declaringType">The type of the declaring object.</param>
+ /// <param name="defaultValue">The default value for the property.</param>
+ /// <param name="defaultBindingMode">The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.</param>
+ /// <param name="validateValue">A delegate to be run when a value is set. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanged">A delegate to be run when the value has changed. This parameter is optional. Default is null.</param>
+ /// <param name="propertyChanging">A delegate to be run when the value will change. This parameter is optional. Default is null.</param>
+ /// <param name="coerceValue">A delegate used to coerce the range of a value. This parameter is optional. Default is null.</param>
+ /// <param name="defaultValueCreator">A Func used to initialize default value for reference types.</param>
+ /// <returns>A newly created BindablePropertyKey.</returns>
+ public static BindablePropertyKey CreateReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource,
+ ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
+ CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return
+ new BindablePropertyKey(new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue,
+ isReadOnly: true, defaultValueCreator: defaultValueCreator));
+ }
+
+ [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ internal static BindableProperty Create<TDeclarer, TPropertyType>(Expression<Func<TDeclarer, TPropertyType>> getter, TPropertyType defaultValue, BindingMode defaultBindingMode,
+ ValidateValueDelegate<TPropertyType> validateValue, BindingPropertyChangedDelegate<TPropertyType> propertyChanged, BindingPropertyChangingDelegate<TPropertyType> propertyChanging,
+ CoerceValueDelegate<TPropertyType> coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false,
+ CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
+ {
+ if (getter == null)
+ throw new ArgumentNullException("getter");
+
+ Expression expr = getter.Body;
+
+ var unary = expr as UnaryExpression;
+ if (unary != null)
+ expr = unary.Operand;
+
+ var member = expr as MemberExpression;
+ if (member == null)
+ throw new ArgumentException("getter must be a MemberExpression", "getter");
+
+ var property = (PropertyInfo)member.Member;
+
+ ValidateValueDelegate untypedValidateValue = null;
+ BindingPropertyChangedDelegate untypedBindingPropertyChanged = null;
+ BindingPropertyChangingDelegate untypedBindingPropertyChanging = null;
+ CoerceValueDelegate untypedCoerceValue = null;
+ CreateDefaultValueDelegate untypedDefaultValueCreator = null;
+ if (validateValue != null)
+ untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value);
+ if (propertyChanged != null)
+ untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
+ if (propertyChanging != null)
+ untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
+ if (coerceValue != null)
+ untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value);
+ if (defaultValueCreator != null)
+ untypedDefaultValueCreator = o => defaultValueCreator((TDeclarer)o);
+
+ return new BindableProperty(property.Name, property.PropertyType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged,
+ untypedBindingPropertyChanging, untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator);
+ }
+
+ internal static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue,
+ BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging,
+ CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging,
+ defaultValueCreator: defaultValueCreator);
+ }
+
+ [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")]
+ internal static BindableProperty CreateAttached<TDeclarer, TPropertyType>(Expression<Func<BindableObject, TPropertyType>> staticgetter, TPropertyType defaultValue, BindingMode defaultBindingMode,
+ ValidateValueDelegate<TPropertyType> validateValue, BindingPropertyChangedDelegate<TPropertyType> propertyChanged, BindingPropertyChangingDelegate<TPropertyType> propertyChanging,
+ CoerceValueDelegate<TPropertyType> coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false,
+ CreateDefaultValueDelegate<BindableObject, TPropertyType> defaultValueCreator = null)
+ {
+ if (staticgetter == null)
+ throw new ArgumentNullException("staticgetter");
+
+ Expression expr = staticgetter.Body;
+
+ var unary = expr as UnaryExpression;
+ if (unary != null)
+ expr = unary.Operand;
+
+ var methodcall = expr as MethodCallExpression;
+ if (methodcall == null)
+ throw new ArgumentException("staticgetter must be a MethodCallExpression", "staticgetter");
+
+ MethodInfo method = methodcall.Method;
+ if (!method.Name.StartsWith("Get", StringComparison.Ordinal))
+ throw new ArgumentException("staticgetter name must start with Get", "staticgetter");
+
+ string propertyname = method.Name.Substring(3);
+
+ ValidateValueDelegate untypedValidateValue = null;
+ BindingPropertyChangedDelegate untypedBindingPropertyChanged = null;
+ BindingPropertyChangingDelegate untypedBindingPropertyChanging = null;
+ CoerceValueDelegate untypedCoerceValue = null;
+ CreateDefaultValueDelegate untypedDefaultValueCreator = null;
+ if (validateValue != null)
+ untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value);
+ if (propertyChanged != null)
+ untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
+ if (propertyChanging != null)
+ untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
+ if (coerceValue != null)
+ untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value);
+ if (defaultValueCreator != null)
+ untypedDefaultValueCreator = o => defaultValueCreator(o);
+
+ return new BindableProperty(propertyname, method.ReturnType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, untypedBindingPropertyChanging,
+ untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator);
+ }
+
+ internal static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue,
+ BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging,
+ bool isReadOnly, CreateDefaultValueDelegate defaultValueCreator = null)
+ {
+ return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, isReadOnly,
+ defaultValueCreator);
+ }
+
+ internal object GetDefaultValue(BindableObject bindable)
+ {
+ if (DefaultValueCreator != null)
+ return DefaultValueCreator(bindable);
+
+ return DefaultValue;
+ }
+
+ internal bool TryConvert(ref object value)
+ {
+ if (value == null)
+ {
+ return !ReturnTypeInfo.IsValueType || ReturnTypeInfo.IsGenericType && ReturnTypeInfo.GetGenericTypeDefinition() == typeof(Nullable<>);
+ }
+
+ Type valueType = value.GetType();
+ Type type = ReturnType;
+
+ // Dont support arbitrary IConvertible by limiting which types can use this
+ Type[] convertableTo;
+ TypeConverter typeConverterTo;
+ if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1)
+ {
+ value = Convert.ChangeType(value, type);
+ }
+ else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType))
+ {
+ value = typeConverterTo.ConvertFromInvariantString(value.ToString());
+ }
+ else if (UserCustomConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType))
+ {
+ //Modification for NUI XAML : user defined converter for DynamicResource can be added
+ value = typeConverterTo.ConvertFromInvariantString(value.ToString());
+ }
+ else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo()))
+ {
+ var cast = type.GetImplicitConversionOperator(fromType: valueType, toType: type)
+ ?? valueType.GetImplicitConversionOperator(fromType: valueType, toType: type);
+
+ if (cast == null)
+ return false;
+
+ value = cast.Invoke(null, new[] { value });
+ }
+
+ return true;
+ }
+
+ internal delegate void BindablePropertyBindingChanging(BindableObject bindable, BindingBase oldValue, BindingBase newValue);
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Globalization;
+using System.Linq;
+using System.Reflection;
+using System.Xml;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindablePropertyConverter")]
+ [TypeConversion(typeof(BindableProperty))]
+ public sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter
+ {
+ object IExtendedTypeConverter.ConvertFrom(CultureInfo culture, object value, IServiceProvider serviceProvider)
+ {
+ return ((IExtendedTypeConverter)this).ConvertFromInvariantString(value as string, serviceProvider);
+ }
+
+ object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ return null;
+ if (serviceProvider == null)
+ return null;
+ var parentValuesProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
+ var typeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
+ if (typeResolver == null)
+ return null;
+ IXmlLineInfo lineinfo = null;
+ var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ if (xmlLineInfoProvider != null)
+ lineinfo = xmlLineInfoProvider.XmlLineInfo;
+ string[] parts = value.Split('.');
+ Type type = null;
+ if (parts.Length == 1)
+ {
+ if (parentValuesProvider == null)
+ {
+ string msg = string.Format("Can't resolve {0}", parts[0]);
+ throw new XamlParseException(msg, lineinfo);
+ }
+ object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault();
+ if (parentValuesProvider.TargetObject is Setter)
+ {
+ var style = parent as Style;
+ var triggerBase = parent as TriggerBase;
+ var visualState = parent as VisualState;
+ if (style != null)
+ type = style.TargetType;
+ else if (triggerBase != null)
+ type = triggerBase.TargetType;
+ else if (visualState != null)
+ type = FindTypeForVisualState(parentValuesProvider, lineinfo);
+ }
+ else if (parentValuesProvider.TargetObject is Trigger)
+ type = (parentValuesProvider.TargetObject as Trigger).TargetType;
+ else if (parentValuesProvider.TargetObject is XamlPropertyCondition && (parent as TriggerBase) != null)
+ type = (parent as TriggerBase).TargetType;
+
+ if (type == null)
+ throw new XamlParseException($"Can't resolve {parts [0]}", lineinfo);
+
+ return ConvertFrom(type, parts[0], lineinfo);
+ }
+ if (parts.Length == 2)
+ {
+ if (!typeResolver.TryResolve(parts[0], out type))
+ {
+ string msg = string.Format("Can't resolve {0}", parts[0]);
+ throw new XamlParseException(msg, lineinfo);
+ }
+ return ConvertFrom(type, parts[1], lineinfo);
+ }
+ throw new XamlParseException($"Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyName.", lineinfo);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override object ConvertFromInvariantString(string value)
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ return null;
+ if (value.Contains(":"))
+ {
+ Console.WriteLine(null, "Can't resolve properties with xml namespace prefix.");
+ return null;
+ }
+ string[] parts = value.Split('.');
+ if (parts.Length != 2)
+ {
+ Console.WriteLine(null, $"Can't resolve {value}. Accepted syntax is Type.PropertyName.");
+ return null;
+ }
+ Type type = Type.GetType("Tizen.NUI." + parts[0]);
+ return ConvertFrom(type, parts[1], null);
+ }
+
+ BindableProperty ConvertFrom(Type type, string propertyName, IXmlLineInfo lineinfo)
+ {
+ string name = propertyName + "Property";
+ FieldInfo bpinfo = type.GetField(fi => fi.Name == name && fi.IsStatic && fi.IsPublic && fi.FieldType == typeof(BindableProperty));
+ if (bpinfo == null)
+ throw new XamlParseException($"Can't resolve {name} on {type.Name}", lineinfo);
+ var bp = bpinfo.GetValue(null) as BindableProperty;
+ var isObsolete = bpinfo.GetCustomAttribute<ObsoleteAttribute>() != null;
+ if (bp != null && bp.PropertyName != propertyName && !isObsolete)
+ throw new XamlParseException($"The PropertyName of {type.Name}.{name} is not {propertyName}", lineinfo);
+ return bp;
+ }
+
+ Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)
+ {
+ var parents = parentValueProvider.ParentObjects.ToList();
+
+ // Skip 0; we would not be making this check if TargetObject were not a Setter
+ // Skip 1; we would not be making this check if the immediate parent were not a VisualState
+
+ // VisualStates must be in a VisualStateGroup
+ if(!(parents[2] is VisualStateGroup)) {
+ throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo);
+ }
+
+ var vsTarget = parents[3];
+
+ // Are these Visual States directly on a VisualElement?
+ if (vsTarget is /*VisualElement*/BaseHandle)
+ {
+ return vsTarget.GetType();
+ }
+
+ if (!(parents[3] is VisualStateGroupList))
+ {
+ throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
+ }
+
+ if (!(parents[4] is Setter))
+ {
+ throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
+ }
+
+ // These must be part of a Style; verify that
+ if (!(parents[5] is Style style))
+ {
+ throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo);
+ }
+
+ return style.TargetType;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <summary>
+ /// The secret key to a BindableProperty, used to implement a BindableProperty with restricted write access.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class BindablePropertyKey
+ {
+ internal BindablePropertyKey(BindableProperty property)
+ {
+ if (property == null)
+ throw new ArgumentNullException("property");
+
+ BindableProperty = property;
+ }
+
+ /// <summary>
+ /// Gets the BindableProperty.
+ /// </summary>
+ public BindableProperty BindableProperty { get; private set; }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.Text;
+using Tizen.NUI.Binding.Internals;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class Binding : BindingBase
+ {
+ internal const string SelfPath = ".";
+ IValueConverter _converter;
+ object _converterParameter;
+
+ BindingExpression _expression;
+ string _path;
+ object _source;
+ string _updateSourceEventName;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Binding()
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Binding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null)
+ {
+ if (path == null)
+ throw new ArgumentNullException("path");
+ if (string.IsNullOrWhiteSpace(path))
+ throw new ArgumentException("path can not be an empty string", "path");
+
+ Path = path;
+ Converter = converter;
+ ConverterParameter = converterParameter;
+ Mode = mode;
+ StringFormat = stringFormat;
+ Source = source;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IValueConverter Converter
+ {
+ get { return _converter; }
+ set
+ {
+ ThrowIfApplied();
+
+ _converter = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ConverterParameter
+ {
+ get { return _converterParameter; }
+ set
+ {
+ ThrowIfApplied();
+
+ _converterParameter = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Path
+ {
+ get { return _path; }
+ set
+ {
+ ThrowIfApplied();
+
+ _path = value;
+ _expression = new BindingExpression(this, !string.IsNullOrWhiteSpace(value) ? value : SelfPath);
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Source
+ {
+ get { return _source; }
+ set
+ {
+ ThrowIfApplied();
+ _source = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string UpdateSourceEventName {
+ get { return _updateSourceEventName; }
+ set {
+ ThrowIfApplied();
+ _updateSourceEventName = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete]
+ public static Binding Create<TSource>(Expression<Func<TSource, object>> propertyGetter, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null,
+ string stringFormat = null)
+ {
+ if (propertyGetter == null)
+ throw new ArgumentNullException("propertyGetter");
+
+ return new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat);
+ }
+
+ internal override void Apply(bool fromTarget)
+ {
+ base.Apply(fromTarget);
+
+ if (_expression == null)
+ _expression = new BindingExpression(this, SelfPath);
+
+ _expression.Apply(fromTarget);
+ }
+
+ internal override void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
+ {
+ object src = _source;
+ var isApplied = IsApplied;
+
+ base.Apply(src ?? newContext, bindObj, targetProperty, fromBindingContextChanged: fromBindingContextChanged);
+
+ if (src != null && isApplied && fromBindingContextChanged)
+ return;
+
+ object bindingContext = src ?? Context ?? newContext;
+ if (_expression == null && bindingContext != null)
+ _expression = new BindingExpression(this, SelfPath);
+
+ _expression?.Apply(bindingContext, bindObj, targetProperty);
+ }
+
+ internal override BindingBase Clone()
+ {
+ return new Binding(Path, Mode) { Converter = Converter, ConverterParameter = ConverterParameter, StringFormat = StringFormat, Source = Source, UpdateSourceEventName = UpdateSourceEventName };
+ }
+
+ internal override object GetSourceValue(object value, Type targetPropertyType)
+ {
+ if (Converter != null)
+ value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
+
+ return base.GetSourceValue(value, targetPropertyType);
+ }
+
+ internal override object GetTargetValue(object value, Type sourcePropertyType)
+ {
+ if (Converter != null)
+ value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
+
+ return base.GetTargetValue(value, sourcePropertyType);
+ }
+
+ internal override void Unapply(bool fromBindingContextChanged = false)
+ {
+ if (Source != null && fromBindingContextChanged && IsApplied)
+ return;
+
+ base.Unapply(fromBindingContextChanged: fromBindingContextChanged);
+
+ if (_expression != null)
+ _expression.Unapply();
+ }
+
+ [Obsolete]
+ static string GetBindingPath<TSource>(Expression<Func<TSource, object>> propertyGetter)
+ {
+ Expression expr = propertyGetter.Body;
+
+ var unary = expr as UnaryExpression;
+ if (unary != null)
+ expr = unary.Operand;
+
+ var builder = new StringBuilder();
+
+ var indexed = false;
+
+ var member = expr as MemberExpression;
+ if (member == null)
+ {
+ var methodCall = expr as MethodCallExpression;
+ if (methodCall != null)
+ {
+ if (methodCall.Arguments.Count == 0)
+ throw new ArgumentException("Method calls are not allowed in binding expression");
+
+ var arguments = new List<string>(methodCall.Arguments.Count);
+ foreach (Expression arg in methodCall.Arguments)
+ {
+ if (arg.NodeType != ExpressionType.Constant)
+ throw new ArgumentException("Only constants can be used as indexer arguments");
+
+ object value = ((ConstantExpression)arg).Value;
+ arguments.Add(value != null ? value.ToString() : "null");
+ }
+
+ Type declarerType = methodCall.Method.DeclaringType;
+ DefaultMemberAttribute defaultMember = declarerType.GetTypeInfo().GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType<DefaultMemberAttribute>().FirstOrDefault();
+ string indexerName = defaultMember != null ? defaultMember.MemberName : "Item";
+
+ MethodInfo getterInfo =
+ declarerType.GetProperties().Where(pi => (pi.GetMethod != null) && pi.Name == indexerName && pi.CanRead && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic).Select(pi => pi.GetMethod).FirstOrDefault();
+ if (getterInfo != null)
+ {
+ if (getterInfo == methodCall.Method)
+ {
+ indexed = true;
+ builder.Append("[");
+
+ var first = true;
+ foreach (string argument in arguments)
+ {
+ if (!first)
+ builder.Append(",");
+
+ builder.Append(argument);
+ first = false;
+ }
+
+ builder.Append("]");
+
+ member = methodCall.Object as MemberExpression;
+ }
+ else
+ throw new ArgumentException("Method calls are not allowed in binding expressions");
+ }
+ else
+ throw new ArgumentException("Public indexer not found");
+ }
+ else
+ throw new ArgumentException("Invalid expression type");
+ }
+
+ while (member != null)
+ {
+ var property = (PropertyInfo)member.Member;
+ if (builder.Length != 0)
+ {
+ if (!indexed)
+ builder.Insert(0, ".");
+ else
+ indexed = false;
+ }
+
+ builder.Insert(0, property.Name);
+
+ // member = member.Expression as MemberExpression ?? (member.Expression as UnaryExpression)?.Operand as MemberExpression;
+ member = member.Expression as MemberExpression ?? (member.Expression is UnaryExpression ? (member.Expression as UnaryExpression).Operand as MemberExpression : null);
+ }
+
+ return builder.ToString();
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <summary>
+ /// An abstract class that provides a BindingMode and a formatting option.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class BindingBase
+ {
+ static readonly ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext> SynchronizedCollections = new ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext>();
+
+ BindingMode _mode = BindingMode.Default;
+ string _stringFormat;
+ object _targetNullValue;
+ object _fallbackValue;
+
+ internal BindingBase()
+ {
+ }
+
+ /// <summary>
+ /// Gets or sets the mode for this binding.
+ /// </summary>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingMode Mode
+ {
+ get { return _mode; }
+ set
+ {
+ if ( value != BindingMode.Default
+ && value != BindingMode.OneWay
+ && value != BindingMode.OneWayToSource
+ && value != BindingMode.TwoWay
+ && value != BindingMode.OneTime)
+ throw new ArgumentException("mode is not a valid BindingMode", "mode");
+
+ ThrowIfApplied();
+
+ _mode = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the string format for this binding.
+ /// </summary>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string StringFormat
+ {
+ get { return _stringFormat; }
+ set
+ {
+ ThrowIfApplied();
+
+ _stringFormat = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object TargetNullValue
+ {
+ get { return _targetNullValue; }
+ set {
+ ThrowIfApplied();
+ _targetNullValue = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object FallbackValue {
+ get => _fallbackValue;
+ set {
+ ThrowIfApplied();
+ _fallbackValue = value;
+ }
+ }
+
+ internal bool AllowChaining { get; set; }
+
+ internal object Context { get; set; }
+
+ internal bool IsApplied { get; private set; }
+
+ /// <summary>
+ /// Stops synchronization on the collection.
+ /// </summary>
+ /// <param name="collection">The collection on which to stop synchronization.</param>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void DisableCollectionSynchronization(IEnumerable collection)
+ {
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
+
+ SynchronizedCollections.Remove(collection);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
+ {
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
+ if (callback == null)
+ throw new ArgumentNullException(nameof(callback));
+
+ SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
+ }
+
+ /// <summary>
+ /// Throws an InvalidOperationException if the binding has been applied.
+ /// </summary>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void ThrowIfApplied()
+ {
+ if (IsApplied)
+ throw new InvalidOperationException("Can not change a binding while it's applied");
+ }
+
+ internal virtual void Apply(bool fromTarget)
+ {
+ IsApplied = true;
+ }
+
+ internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
+ {
+ IsApplied = true;
+ }
+
+ internal abstract BindingBase Clone();
+
+ internal virtual object GetSourceValue(object value, Type targetPropertyType)
+ {
+ if (value == null && TargetNullValue != null)
+ return TargetNullValue;
+ if (StringFormat != null)
+ return string.Format(StringFormat, value);
+
+ return value;
+ }
+
+ internal virtual object GetTargetValue(object value, Type sourcePropertyType)
+ {
+ return value;
+ }
+
+ internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext)
+ {
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
+
+ return SynchronizedCollections.TryGetValue(collection, out synchronizationContext);
+ }
+
+ internal virtual void Unapply(bool fromBindingContextChanged = false)
+ {
+ IsApplied = false;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <summary>
+ /// The direction of changes propagation for bindings.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum BindingMode
+ {
+ /// <summary>
+ /// When used in Bindings, indicates that the Binding should use the DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay.
+ /// </summary>
+ Default,
+
+ /// <summary>
+ /// Indicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions.
+ /// </summary>
+ TwoWay,
+
+ /// <summary>
+ /// Indicates that the binding should only propagate changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values.
+ /// </summary>
+ OneWay,
+
+ /// <summary>
+ /// Indicates that the binding should only propagate changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values.
+ /// </summary>
+ OneWayToSource,
+
+ /// <summary>
+ /// Indicates that the binding will be applied only when the binding context changes and the value will not be monitored for changes with INotifyPropertyChanged.
+ /// </summary>
+ OneTime,
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindingTypeConverter")]
+ [TypeConversion(typeof(Binding))]
+ public sealed class BindingTypeConverter : TypeConverter
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override object ConvertFromInvariantString(string value)
+ {
+ return new Binding(value);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate void CollectionSynchronizationCallback(IEnumerable collection, object context, Action accessMethod, bool writeAccess);
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ColorTypeConverter")]
+ [TypeConversion(typeof(Color))]
+ public class ColorTypeConverter : TypeConverter
+ {
+ // Supported inputs
+ // HEX #rgb, #argb, #rrggbb, #aarrggbb
+ // float array 0.5,0.5,0.5,0.5
+ // Predefined color case insensitive
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override object ConvertFromInvariantString(string value)
+ {
+ if (value != null)
+ {
+ value = value.Trim();
+ if (value.StartsWith("#", StringComparison.Ordinal))
+ {
+ return FromHex(value);
+ }
+
+ string[] parts = value.Split(',');
+ if (parts.Length == 1) //like Red or Color.Red
+ {
+ parts = value.Split('.');
+ if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Color"))
+ {
+ string color = parts[parts.Length - 1];
+ switch (color)
+ {
+ case "Black": return Color.Black;
+ case "White": return Color.White;
+ case "Red": return Color.Red;
+ case "Green": return Color.Green;
+ case "Blue": return Color.Blue;
+ case "Yellow": return Color.Yellow;
+ case "Magenta": return Color.Magenta;
+ case "Cyan": return Color.Cyan;
+ case "Transparent": return Color.Transparent;
+ }
+ }
+ }
+ else if (parts.Length == 4) //like 0.5,0.5,0.5,0.5
+ {
+ 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));
+ }
+ }
+
+ throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Color)}");
+ }
+
+ static uint ToHex(char c)
+ {
+ ushort x = (ushort)c;
+ if (x >= '0' && x <= '9')
+ return (uint)(x - '0');
+
+ x |= 0x20;
+ if (x >= 'a' && x <= 'f')
+ return (uint)(x - 'a' + 10);
+ return 0;
+ }
+
+ static uint ToHexD(char c)
+ {
+ var j = ToHex(c);
+ return (j << 4) | j;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static Color FromRgba(int r, int g, int b, int a)
+ {
+ float red = (float)r / 255;
+ float green = (float)g / 255;
+ float blue = (float)b / 255;
+ float alpha = (float)a / 255;
+ return new Color(red, green, blue, alpha);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static Color FromRgb(int r, int g, int b)
+ {
+ return FromRgba(r, g, b, 255);
+ }
+
+ static Color FromHex(string hex)
+ {
+ // Undefined
+ if (hex.Length < 3)
+ return Color.Black;
+ int idx = (hex[0] == '#') ? 1 : 0;
+
+ switch (hex.Length - idx)
+ {
+ case 3: //#rgb => ffrrggbb
+ var t1 = ToHexD(hex[idx++]);
+ var t2 = ToHexD(hex[idx++]);
+ var t3 = ToHexD(hex[idx]);
+
+ return FromRgb((int)t1, (int)t2, (int)t3);
+
+ case 4: //#argb => aarrggbb
+ var f1 = ToHexD(hex[idx++]);
+ var f2 = ToHexD(hex[idx++]);
+ var f3 = ToHexD(hex[idx++]);
+ var f4 = ToHexD(hex[idx]);
+ return FromRgba((int)f2, (int)f3, (int)f4, (int)f1);
+
+ case 6: //#rrggbb => ffrrggbb
+ return FromRgb((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
+ (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
+ (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])));
+
+ case 8: //#aarrggbb
+ var a1 = ToHex(hex[idx++]) << 4 | ToHex(hex[idx++]);
+ return FromRgba((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
+ (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])),
+ (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])),
+ (int)a1);
+
+ default: //everything else will result in unexpected results
+ return Color.Black;
+ }
+ }
+ }
+}
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract partial class Element : BindableObject, IElement, INameScope, IElementController
{
-
- // public static readonly BindableProperty MenuProperty = BindableProperty.CreateAttached(nameof(Menu), typeof(Menu), typeof(Element), null);
-
- // public static Menu GetMenu(BindableObject bindable)
- // {
- // return (Menu)bindable.GetValue(MenuProperty);
- // }
-
- // public static void SetMenu(BindableObject bindable, Menu menu)
- // {
- // bindable.SetValue(MenuProperty, menu);
- // }
-
internal static readonly ReadOnlyCollection<Element> EmptyChildren = new ReadOnlyCollection<Element>(new Element[0]);
/// <summary>
Dictionary<BindableProperty, string> _dynamicResources;
- IEffectControlProvider _effectControlProvider;
-
- TrackableCollection<Effect> _effects;
-
Guid? _id;
Element _parentOverride;
- IPlatform _platform;
-
string _styleId;
/// <summary>
set { SetValue(ClassIdProperty, value); }
}
- internal IList<Effect> Effects
- {
- get
- {
- if (_effects == null)
- {
- _effects = new TrackableCollection<Effect>();
- _effects.CollectionChanged += EffectsOnCollectionChanged;
- _effects.Clearing += EffectsOnClearing;
- }
- return _effects;
- }
- }
-
/// <summary>
/// Gets a value that can be used to uniquely identify an element through the run of an application.
/// </summary>
}
}
- /// <summary>
- /// For internal use.
- /// </summary>
- internal IPlatform Platform
- {
- get
- {
- if (_platform == null && RealParent != null)
- return RealParent.Platform;
- return _platform;
- }
- set
- {
- if (_platform == value)
- return;
- _platform = value;
- PlatformSet?.Invoke(this, EventArgs.Empty);
- foreach (Element descendant in Descendants())
- {
- descendant._platform = _platform;
- descendant.PlatformSet?.Invoke(this, EventArgs.Empty);
- }
- }
- }
-
/// <summary>
/// For internal use.
/// </summary>
OnParentSet();
- if (RealParent != null)
- {
- IPlatform platform = RealParent.Platform;
- if (platform != null)
- Platform = platform;
- }
-
OnPropertyChanged();
}
}
_changeHandlers.Remove(onchanged);
}
- /// <summary>
- /// For internal use.
- /// </summary>
- internal IEffectControlProvider EffectControlProvider
- {
- get { return _effectControlProvider; }
- set
- {
- if (_effectControlProvider == value)
- return;
- if (_effectControlProvider != null && _effects != null)
- {
- foreach (Effect effect in _effects)
- effect?.SendDetached();
- }
- _effectControlProvider = value;
- if (_effectControlProvider != null && _effects != null)
- {
- foreach (Effect effect in _effects)
- {
- if (effect != null)
- AttachEffect(effect);
- }
- }
- }
- }
-
//void IElementController.SetValueFromRenderer(BindableProperty property, object value) => SetValueFromRenderer(property, value);
/// <summary>
SetValueCore(property, value);
}
- /// <summary>
- /// For internal use.
- /// </summary>
- /// <param name="name">The nameof the effect</param>
- /// <returns>true if attached</returns>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool EffectIsAttached(string name)
- {
- foreach (var effect in Effects)
- {
- if (effect.ResolveId == name)
- return true;
- }
- return false;
- }
-
object INameScope.FindByName(string name)
{
INameScope namescope = GetNameScope();
protected virtual void OnChildAdded(Element child)
{
child.Parent = this;
- if (Platform != null)
- child.Platform = Platform;
child.ApplyBindings(skipBindingContext: false, fromBindingContextChanged:true);
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
-
- if (_effects == null || _effects.Count == 0)
- return;
-
- var args = new PropertyChangedEventArgs(propertyName);
- foreach (Effect effect in _effects)
- {
- effect?.SendOnElementPropertyChanged(args);
- }
}
/// <summary>
{
}
- /// <summary>
- /// For internal use.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler PlatformSet;
-
internal virtual void SetChildInheritedBindingContext(Element child, object context)
{
SetInheritedBindingContext(child, context);
}
}
- void AttachEffect(Effect effect)
- {
- if (_effectControlProvider == null)
- return;
- if (effect.IsAttached)
- throw new InvalidOperationException("Cannot attach Effect to multiple sources");
-
- Effect effectToRegister = effect;
- if (effect is RoutingEffect)
- effectToRegister = ((RoutingEffect)effect).Inner;
- _effectControlProvider.RegisterEffect(effectToRegister);
- effectToRegister.Element = this;
- effect.SendAttached();
- }
-
- void EffectsOnClearing(object sender, EventArgs eventArgs)
- {
- foreach (Effect effect in _effects)
- {
- effect?.ClearEffect();
- }
- }
-
- void EffectsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- switch (e.Action)
- {
- case NotifyCollectionChangedAction.Add:
- foreach (Effect effect in e.NewItems)
- {
- AttachEffect(effect);
- }
- break;
- case NotifyCollectionChangedAction.Move:
- break;
- case NotifyCollectionChangedAction.Remove:
- foreach (Effect effect in e.OldItems)
- {
- effect.ClearEffect();
- }
- break;
- case NotifyCollectionChangedAction.Replace:
- foreach (Effect effect in e.NewItems)
- {
- AttachEffect(effect);
- }
- foreach (Effect effect in e.OldItems)
- {
- effect.ClearEffect();
- }
- break;
- case NotifyCollectionChangedAction.Reset:
- if (e.NewItems != null)
- {
- foreach (Effect effect in e.NewItems)
- {
- AttachEffect(effect);
- }
- }
- if (e.OldItems != null)
- {
- foreach (Effect effect in e.OldItems)
- {
- effect.ClearEffect();
- }
- }
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
INameScope GetNameScope()
{
INameScope namescope = NameScope.GetNameScope(this);
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class ElementEventArgs : EventArgs
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ElementEventArgs(Element element)
+ {
+ if (element == null)
+ throw new ArgumentNullException("element");
+
+ Element = element;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Element Element { get; private set; }
+ }
+}
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IRegisterable
+ {
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Reflection;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class Behavior : BindableObject, IAttachedObject
+ {
+ internal Behavior(Type associatedType)
+ {
+ if (associatedType == null)
+ throw new ArgumentNullException("associatedType");
+ AssociatedType = associatedType;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected Type AssociatedType { get; }
+
+ void IAttachedObject.AttachTo(BindableObject bindable)
+ {
+ if (bindable == null)
+ throw new ArgumentNullException("bindable");
+ if (!AssociatedType.IsInstanceOfType(bindable))
+ throw new InvalidOperationException("bindable not an instance of AssociatedType");
+ OnAttachedTo(bindable);
+ }
+
+ void IAttachedObject.DetachFrom(BindableObject bindable)
+ {
+ OnDetachingFrom(bindable);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual void OnAttachedTo(BindableObject bindable)
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual void OnDetachingFrom(BindableObject bindable)
+ {
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class Behavior<T> : Behavior where T : BindableObject
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected Behavior() : base(typeof(T))
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void OnAttachedTo(BindableObject bindable)
+ {
+ base.OnAttachedTo(bindable);
+ OnAttachedTo((T)bindable);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual void OnAttachedTo(T bindable)
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void OnDetachingFrom(BindableObject bindable)
+ {
+ OnDetachingFrom((T)bindable);
+ base.OnDetachingFrom(bindable);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual void OnDetachingFrom(T bindable)
+ {
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
+ [AcceptEmptyServiceProvider]
+ public sealed class BindingCondition : Condition, IValueProvider
+ {
+ readonly BindableProperty _boundProperty;
+
+ BindingBase _binding;
+ object _triggerValue;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingCondition()
+ {
+ _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingBase Binding
+ {
+ get { return _binding; }
+ set
+ {
+ if (_binding == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Binding once the Condition has been applied.");
+ _binding = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Value
+ {
+ get { return _triggerValue; }
+ set
+ {
+ if (_triggerValue == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Value once the Condition has been applied.");
+ _triggerValue = value;
+ }
+ }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ //This is no longer required
+ return this;
+ }
+
+ internal override bool GetState(BindableObject bindable)
+ {
+ object newValue = bindable.GetValue(_boundProperty);
+ return EqualsToValue(newValue);
+ }
+
+ internal override void SetUp(BindableObject bindable)
+ {
+ if (Binding != null)
+ bindable.SetBinding(_boundProperty, Binding.Clone());
+ }
+
+ internal override void TearDown(BindableObject bindable)
+ {
+ bindable.RemoveBinding(_boundProperty);
+ bindable.ClearValue(_boundProperty);
+ }
+
+ static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
+
+ bool EqualsToValue(object other)
+ {
+ if ((other == Value) || (other != null && other.Equals(Value)))
+ return true;
+
+ object converted = null;
+ if (s_valueConverter != null)
+ converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null);
+ else
+ return false;
+
+ return (other == converted) || (other != null && other.Equals(converted));
+ }
+
+ void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
+ {
+ bool oldState = EqualsToValue(oldValue);
+ bool newState = EqualsToValue(newValue);
+
+ if (newState == oldState)
+ return;
+
+ if (ConditionChanged != null)
+ ConditionChanged(bindable, oldState, newState);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class Condition
+ {
+ Action<BindableObject, bool, bool> _conditionChanged;
+
+ bool _isSealed;
+
+ internal Condition()
+ {
+ }
+
+ internal Action<BindableObject, bool, bool> ConditionChanged
+ {
+ get { return _conditionChanged; }
+ set
+ {
+ if (_conditionChanged == value)
+ return;
+ if (_conditionChanged != null)
+ throw new InvalidOperationException("The same condition instance can not be reused");
+ _conditionChanged = value;
+ }
+ }
+
+ internal bool IsSealed
+ {
+ get { return _isSealed; }
+ set
+ {
+ if (_isSealed == value)
+ return;
+ if (!value)
+ throw new InvalidOperationException("What is sealed can not be unsealed.");
+ _isSealed = value;
+ OnSealed();
+ }
+ }
+
+ internal abstract bool GetState(BindableObject bindable);
+
+ internal virtual void OnSealed()
+ {
+ }
+
+ internal abstract void SetUp(BindableObject bindable);
+ internal abstract void TearDown(BindableObject bindable);
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Setters")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
+ [AcceptEmptyServiceProvider]
+ public sealed class DataTrigger : TriggerBase, IValueProvider
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public DataTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new BindingCondition(), targetType)
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindingBase Binding
+ {
+ get { return ((BindingCondition)Condition).Binding; }
+ set
+ {
+ if (((BindingCondition)Condition).Binding == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Binding once the Trigger has been applied.");
+ OnPropertyChanging();
+ ((BindingCondition)Condition).Binding = value;
+ OnPropertyChanged();
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new IList<Setter> Setters
+ {
+ get { return base.Setters; }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Value
+ {
+ get { return ((BindingCondition)Condition).Value; }
+ set
+ {
+ if (((BindingCondition)Condition).Value == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
+ OnPropertyChanging();
+ ((BindingCondition)Condition).Value = value;
+ OnPropertyChanged();
+ }
+ }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ //This is no longer required
+ return this;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using Tizen.NUI.Binding.Internals;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Actions")]
+ public sealed class EventTrigger : TriggerBase
+ {
+ static readonly MethodInfo s_handlerinfo = typeof(EventTrigger).GetRuntimeMethods().Single(mi => mi.Name == "OnEventTriggered" && mi.IsPublic == false);
+ readonly List<BindableObject> _associatedObjects = new List<BindableObject>();
+
+ EventInfo _eventinfo;
+
+ string _eventname;
+ Delegate _handlerdelegate;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public EventTrigger() : base(typeof(BindableObject))
+ {
+ Actions = new SealedList<TriggerAction>();
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<TriggerAction> Actions { get; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Event
+ {
+ get { return _eventname; }
+ set
+ {
+ if (_eventname == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Event cannot be changed once the Trigger has been applied");
+ OnPropertyChanging();
+ _eventname = value;
+ OnPropertyChanged();
+ }
+ }
+
+ internal override void OnAttachedTo(BindableObject bindable)
+ {
+ base.OnAttachedTo(bindable);
+ if (!string.IsNullOrEmpty(Event))
+ AttachHandlerTo(bindable);
+ _associatedObjects.Add(bindable);
+ }
+
+ internal override void OnDetachingFrom(BindableObject bindable)
+ {
+ _associatedObjects.Remove(bindable);
+ DetachHandlerFrom(bindable);
+ base.OnDetachingFrom(bindable);
+ }
+
+ internal override void OnSeal()
+ {
+ base.OnSeal();
+ ((SealedList<TriggerAction>)Actions).IsReadOnly = true;
+ }
+
+ void AttachHandlerTo(BindableObject bindable)
+ {
+ try
+ {
+ _eventinfo = bindable.GetType().GetRuntimeEvent(Event);
+ _handlerdelegate = s_handlerinfo.CreateDelegate(_eventinfo?.EventHandlerType, this);
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("EventTrigger", "Can not attach EventTrigger to {0}.{1}. Check if the handler exists and if the signature is right.", bindable.GetType(), Event);
+ }
+ if (_eventinfo != null && _handlerdelegate != null)
+ _eventinfo.AddEventHandler(bindable, _handlerdelegate);
+ }
+
+ void DetachHandlerFrom(BindableObject bindable)
+ {
+ if (_eventinfo != null && _handlerdelegate != null)
+ _eventinfo.RemoveEventHandler(bindable, _handlerdelegate);
+ }
+
+ // [Preserve]
+ void OnEventTriggered(object sender, EventArgs e)
+ {
+ var bindable = (BindableObject)sender;
+ foreach (TriggerAction action in Actions)
+ action.DoInvoke(bindable);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Setters")]
+ public sealed class MultiTrigger : TriggerBase
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public MultiTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new MultiCondition(), targetType)
+ {
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<Condition> Conditions
+ {
+ get { return ((MultiCondition)Condition).Conditions; }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new IList<Setter> Setters
+ {
+ get { return base.Setters; }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Reflection;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")]
+ [AcceptEmptyServiceProvider]
+ public sealed class XamlPropertyCondition : Condition, IValueProvider
+ {
+ readonly BindableProperty _stateProperty;
+
+ BindableProperty _property;
+ object _triggerValue;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public XamlPropertyCondition()
+ {
+ _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ 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);
+ }
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ 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);
+ _triggerValue = s_valueConverter.Convert(value, _property.ReturnType, minforetriever, null);
+ }
+ else
+ {
+ _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);
+ }
+ }
+}
--- /dev/null
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ /// 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 DynamicResource
+ {
+ /// 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 DynamicResource(string key)
+ {
+ Key = key;
+ }
+
+ /// 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 Key { get; private set; }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System.ComponentModel;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface IDynamicResourceHandler
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ void SetDynamicResource(BindableProperty property, string key);
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Xml;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public interface INameScope
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ object FindByName(string name);
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ void RegisterName(string name, object scopedElement);
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ void UnregisterName(string name);
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete]void RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo);
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Xml;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class NameScope : INameScope
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope));
+
+ readonly Dictionary<string, object> _names = new Dictionary<string, object>();
+
+ object INameScope.FindByName(string name)
+ {
+ if (_names.ContainsKey(name))
+ return _names[name];
+ return null;
+ }
+
+ void INameScope.RegisterName(string name, object scopedElement)
+ {
+ if (_names.ContainsKey(name))
+ throw new ArgumentException("An element with the same key already exists in NameScope", "name");
+
+ _names[name] = scopedElement;
+ }
+
+ [Obsolete]
+ void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo)
+ {
+ try
+ {
+ ((INameScope)this).RegisterName(name, scopedElement);
+ }
+ catch (ArgumentException)
+ {
+ throw new XamlParseException(string.Format("An element with the name \"{0}\" already exists in this NameScope", name), xmlLineInfo);
+ }
+ }
+
+ void INameScope.UnregisterName(string name)
+ {
+ _names.Remove(name);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static INameScope GetNameScope(BindableObject bindable)
+ {
+ return (INameScope)bindable.GetValue(NameScopeProperty);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void SetNameScope(BindableObject bindable, INameScope value)
+ {
+ bindable.SetValue(NameScopeProperty, value);
+ }
+ }
+}
/// </summary>
// [RenderWith(typeof(_PageRenderer))]
[EditorBrowsable(EditorBrowsableState.Never)]
- public class Page : /*VisualElement*/BaseHandle, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement
+ public class Page : BaseHandle, IPageController, IElementConfiguration<Page>
{
/// <summary>
/// For internal use.
internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create("IgnoresContainerArea", typeof(bool), typeof(Page), false);
- /// <summary>
- /// Identifies the BackgroundImage property.
- /// </summary>
- internal static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create("BackgroundImage", typeof(string), typeof(Page), default(string));
-
/// <summary>
/// Identifies the IsBusy property.
/// </summary>
internal static readonly BindableProperty IsBusyProperty = BindableProperty.Create("IsBusy", typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged());
- /// <summary>
- /// Identifies the Padding property.
- /// </summary>
- internal static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
-
- /// <summary>
- /// Identifies the Title property.
- /// </summary>
- internal static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(Page), null);
-
- /// <summary>
- /// Identifies the Icon property.
- /// </summary>
- internal static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(Page), default(FileImageSource));
-
- readonly Lazy<PlatformConfigurationRegistry<Page>> _platformConfigurationRegistry;
-
Rectangle _containerArea;
- bool _containerAreaSet;
-
bool _hasAppeared;
ReadOnlyCollection<Element> _logicalChildren;
[EditorBrowsable(EditorBrowsableState.Never)]
public Page()
{
- var toolbarItems = new ObservableCollection<ToolbarItem>();
- toolbarItems.CollectionChanged += OnToolbarItemsCollectionChanged;
// ToolbarItems = toolbarItems;
InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged;
- _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Page>>(() => new PlatformConfigurationRegistry<Page>(this));
- }
-
- /// <summary>
- /// Identifies the image used as a background for the Page.
- /// </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 string BackgroundImage
- {
- get { return (string)GetValue(BackgroundImageProperty); }
- set { SetValue(BackgroundImageProperty, value); }
- }
-
- internal FileImageSource Icon
- {
- get { return (FileImageSource)GetValue(IconProperty); }
- set { SetValue(IconProperty, value); }
}
/// <summary>
set { SetValue(IsBusyProperty, value); }
}
- /// <summary>
- /// The space between the content of the Page and it's border.
- /// </summary>
- internal Thickness Padding
- {
- get { return (Thickness)GetValue(PaddingElement.PaddingProperty); }
- set { SetValue(PaddingElement.PaddingProperty, value); }
- }
-
- Thickness IPaddingElement.PaddingDefaultValueCreator()
- {
- return default(Thickness);
- }
-
- void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
- {
- UpdateChildrenLayout();
- }
-
- /// <summary>
- /// The Page's title.
- /// </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 string Title
- {
- get { return (string)GetValue(TitleProperty); }
- set { SetValue(TitleProperty, value); }
- }
-
- internal IList<ToolbarItem> ToolbarItems { get;/* internal set;*/ }
-
/// <summary>
/// For internal use.
/// </summary>
{
if (_containerArea == value)
return;
- _containerAreaSet = true;
+
_containerArea = value;
ForceLayout();
}
internal override ReadOnlyCollection<Element> LogicalChildrenInternal =>
_logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren));
- /// <summary>
- /// Raised when the layout of the Page has changed.
- /// </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 event EventHandler LayoutChanged;
-
/// <summary>
/// ndicates that the Page is about to appear.
/// </summary>
return OnBackButtonPressed();
}
- /// <summary>
- /// Lays out children Elements into the specified area.
- /// </summary>
- /// <param name="x">Left-hand side of layout area.</param>
- /// <param name="y">Top of layout area.</param>
- /// <param name="width">Width of layout area.</param>
- /// <param name="height">Height of layout area.</param>
- /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected virtual void LayoutChildren(double x, double y, double width, double height)
- {
- var area = new Rectangle((int)x, (int)y, (int)width, (int)height);
- Rectangle originalArea = area;
- if (_containerAreaSet)
- {
- area = ContainerArea;
- area.X += (int)Padding.Left;
- area.Y += (int)Padding.Right;
- area.Width -= (int)Padding.HorizontalThickness;
- area.Height -= (int)Padding.VerticalThickness;
- area.Width = Math.Max(0, area.Width);
- area.Height = Math.Max(0, area.Height);
- }
- }
-
/// <summary>
/// When overridden, allows application developers to customize behavior immediately prior to the Page becoming visible.
/// </summary>
var canceled = false;
EventHandler handler = (sender, args) => { canceled = true; };
- Navigation.PopModalAsync().ContinueWith(t => { throw t.Exception; }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());
return !canceled;
}
base.OnParentSet();
}
- /// <summary>
- /// Requests that the children Elements of the Page update their layouts.
- /// </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)]
- protected void UpdateChildrenLayout()
- {
- if (!ShouldLayoutChildren())
- return;
-
- double x = Padding.Left;
- double y = Padding.Top;
-
- for (var i = 0; i < LogicalChildren.Count; i++)
- {
- LayoutChanged?.Invoke(this, EventArgs.Empty);
- }
- }
-
internal virtual void OnChildMeasureInvalidated(BaseHandle child, InvalidationTrigger trigger)
{
var container = this as IPageContainer<Page>;
}
return !any;
}
-
- /// <summary>
- /// Returns the platform-specific instance of this Page, on which a platform-specific method may be called.
- /// </summary>
- /// <typeparam name="T">The platform for which to return an instance.</typeparam>
- /// <returns>The platform-specific instance of this Page</returns>
- internal IPlatformElementConfiguration<T, Page> On<T>() where T : IConfigPlatform
- {
- return _platformConfigurationRegistry.Value.On<T>();
- }
}
}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ /// <summary>
+ /// For internal use.
+ /// </summary>
+ /// <typeparam name="TRegistrable"></typeparam>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class Registrar<TRegistrable> where TRegistrable : class
+ {
+ readonly Dictionary<Type, Type> _handlers = new Dictionary<Type, Type>();
+
+ /// <summary>
+ /// Register.
+ /// </summary>
+ /// <param name="tview">The type of the view</param>
+ /// <param name="trender">The type of the render.</param>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Register(Type tview, Type trender)
+ {
+ //avoid caching null renderers
+ if (trender == null)
+ return;
+ _handlers[tview] = trender;
+ }
+
+ internal TRegistrable GetHandler(Type type)
+ {
+ Type handlerType = GetHandlerType(type);
+ if (handlerType == null)
+ return null;
+
+ object handler = DependencyResolver.ResolveOrCreate(handlerType);
+
+ return (TRegistrable)handler;
+ }
+
+ internal TRegistrable GetHandler(Type type, params object[] args)
+ {
+ if (args.Length == 0)
+ {
+ return GetHandler(type);
+ }
+
+ Type handlerType = GetHandlerType(type);
+ if (handlerType == null)
+ return null;
+
+ return (TRegistrable)DependencyResolver.ResolveOrCreate(handlerType, args);
+ }
+
+ /// <summary>
+ /// For internal use. Returns handler.
+ /// </summary>
+ /// <typeparam name="TOut">The type of the handler</typeparam>
+ /// <param name="type">The type.</param>
+ /// <returns>The handler instance.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TOut GetHandler<TOut>(Type type) where TOut : TRegistrable
+ {
+ return (TOut)GetHandler(type);
+ }
+
+ /// <summary>
+ /// For internal use. Returns handler.
+ /// </summary>
+ /// <typeparam name="TOut">The type of the handler</typeparam>
+ /// <param name="type">The type.</param>
+ /// <param name="args">The args of the type</param>
+ /// <returns>The handler instance.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TOut GetHandler<TOut>(Type type, params object[] args) where TOut : TRegistrable
+ {
+ return (TOut)GetHandler(type, args);
+ }
+
+ /// <summary>
+ /// For internal use. Return the handler of the object.
+ /// </summary>
+ /// <typeparam name="TOut">Thetype</typeparam>
+ /// <param name="obj">The object instance.</param>
+ /// <returns>The handle of the obj.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TOut GetHandlerForObject<TOut>(object obj) where TOut : TRegistrable
+ {
+ if (obj == null)
+ throw new ArgumentNullException(nameof(obj));
+
+ var reflectableType = obj as IReflectableType;
+ var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
+
+ return (TOut)GetHandler(type);
+ }
+
+ /// <summary>
+ /// For inetrnal use. Return the handler of the object.
+ /// </summary>
+ /// <typeparam name="TOut">The type</typeparam>
+ /// <param name="obj">The object instance</param>
+ /// <param name="args">The args of the type</param>
+ /// <returns>The handler of the object.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TOut GetHandlerForObject<TOut>(object obj, params object[] args) where TOut : TRegistrable
+ {
+ if (obj == null)
+ throw new ArgumentNullException(nameof(obj));
+
+ var reflectableType = obj as IReflectableType;
+ var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
+
+ return (TOut)GetHandler(type, args);
+ }
+
+ /// <summary>
+ /// For internal use. Returns the handle type.
+ /// </summary>
+ /// <param name="viewType">The view type.</param>
+ /// <returns>The type of the handle.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type GetHandlerType(Type viewType)
+ {
+ Type type;
+ if (LookupHandlerType(viewType, out type))
+ return type;
+
+ // lazy load render-view association with RenderWithAttribute (as opposed to using ExportRenderer)
+ var attribute = viewType.GetTypeInfo().GetCustomAttribute<RenderWithAttribute>();
+ if (attribute == null)
+ {
+ Register(viewType, null); // Cache this result so we don't have to do GetCustomAttribute again
+ return null;
+ }
+
+ type = attribute.Type;
+
+ if (type.Name.StartsWith("_", StringComparison.Ordinal))
+ {
+ // TODO: Remove attribute2 once renderer names have been unified across all platforms
+ var attribute2 = type.GetTypeInfo().GetCustomAttribute<RenderWithAttribute>();
+ if (attribute2 != null)
+ type = attribute2.Type;
+
+ if (type.Name.StartsWith("_", StringComparison.Ordinal))
+ {
+ Register(viewType, null); // Cache this result so we don't work through this chain again
+ return null;
+ }
+ }
+
+ Register(viewType, type); // Register this so we don't have to look for the RenderWith Attibute again in the future
+
+ return type;
+ }
+
+ /// <summary>
+ /// For internal use. Return the handle type of the object
+ /// </summary>
+ /// <param name="obj">The object instance.</param>
+ /// <returns>The type of the handler.</returns>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type GetHandlerTypeForObject(object obj)
+ {
+ if (obj == null)
+ throw new ArgumentNullException(nameof(obj));
+
+ var reflectableType = obj as IReflectableType;
+ var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType();
+
+ return GetHandlerType(type);
+ }
+
+ bool LookupHandlerType(Type viewType, out Type handlerType)
+ {
+ Type type = viewType;
+
+ while (type != null)
+ {
+ if (_handlers.ContainsKey(type))
+ {
+ handlerType = _handlers[type];
+ return true;
+ }
+
+ type = type.GetTypeInfo().BaseType;
+ }
+
+ handlerType = null;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// For internal use
+ /// </summary>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static class Registrar
+ {
+ static Registrar()
+ {
+ Registered = new Registrar<IRegisterable>();
+ }
+
+ internal static Dictionary<string, Type> Effects { get; } = new Dictionary<string, Type>();
+ internal static Dictionary<string, StyleSheets.StylePropertyAttribute> StyleProperties { get; } = new Dictionary<string, StyleSheets.StylePropertyAttribute>();
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static IEnumerable<Assembly> ExtraAssemblies { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static Registrar<IRegisterable> Registered { get; internal set; }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Xml;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Value")]
+ [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")]
+ public sealed class Setter : IValueProvider
+ {
+ readonly ConditionalWeakTable<BindableObject, object> _originalValues = new ConditionalWeakTable<BindableObject, object>();
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindableProperty Property { get; set; }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Value { get; set; }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (Property == null)
+ {
+ var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ IXmlLineInfo lineInfo = lineInfoProvider != null ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
+ throw new XamlParseException("Property not set", lineInfo);
+ }
+ var valueconverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider;
+
+ Func<MemberInfo> minforetriever =
+ () =>
+ (MemberInfo)Property.DeclaringType.GetRuntimeProperty(Property.PropertyName) ?? (MemberInfo)Property.DeclaringType.GetRuntimeMethod("Get" + Property.PropertyName, new[] { typeof(BindableObject) });
+
+ object value = valueconverter?.Convert(Value, Property.ReturnType, minforetriever, serviceProvider);
+ Value = value;
+ return this;
+ }
+
+ internal void Apply(BindableObject target, bool fromStyle = false)
+ {
+ if (target == null)
+ throw new ArgumentNullException("target");
+ if (Property == null)
+ return;
+
+ object originalValue = target.GetValue(Property);
+ if (!Equals(originalValue, Property.DefaultValue))
+ {
+ _originalValues.Remove(target);
+ _originalValues.Add(target, originalValue);
+ }
+
+ var dynamicResource = Value as DynamicResource;
+ var binding = Value as BindingBase;
+ if (binding != null)
+ target.SetBinding(Property, binding.Clone(), fromStyle);
+ else if (dynamicResource != null)
+ target.SetDynamicResource(Property, dynamicResource.Key, fromStyle);
+ else
+ {
+ if (Value is IList<VisualStateGroup> visualStateGroupCollection)
+ target.SetValue(Property, visualStateGroupCollection.Clone(), fromStyle);
+ else
+ target.SetValue(Property, Value, fromStyle);
+ }
+ }
+
+ internal void UnApply(BindableObject target, bool fromStyle = false)
+ {
+ if (target == null)
+ throw new ArgumentNullException(nameof(target));
+ if (Property == null)
+ return;
+
+ object actual = target.GetValue(Property);
+ if (!Equals(actual, Value) && !(Value is Tizen.NUI.Binding.Binding) && !(Value is DynamicResource))
+ {
+ //Do not reset default value if the value has been changed
+ _originalValues.Remove(target);
+ return;
+ }
+
+ object defaultValue;
+ if (_originalValues.TryGetValue(target, out defaultValue))
+ {
+ //reset default value, unapply bindings and dynamicResource
+ target.SetValue(Property, defaultValue, fromStyle);
+ _originalValues.Remove(target);
+ }
+ else
+ target.ClearValue(Property);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Linq;
+using System.Reflection;
+using System.Globalization;
+
+using Tizen.NUI;
+using Tizen.NUI.Xaml;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
+ public class SizeTypeConverter : TypeConverter
+ {
+ /// 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 override object ConvertFromInvariantString(string value)
+ {
+ if (value != null)
+ {
+ string[] parts = value.Split(',');
+ if (parts.Length == 3)
+ {
+ int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
+ int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
+ int z = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim());
+ return new Size(x, y, z);
+ }
+ }
+
+ throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}");
+ }
+ }
+
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")]
+ public class Size2DTypeConverter : TypeConverter
+ {
+ /// 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 override object ConvertFromInvariantString(string value)
+ {
+ if (value != null)
+ {
+ string[] parts = value.Split(',');
+ if (parts.Length == 2)
+ {
+ int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
+ int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
+ return new Size2D(x, y);
+ }
+ }
+
+ throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}");
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using Tizen.NUI.StyleSheets;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Setters")]
+ public sealed class Style : IStyle
+ {
+ internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass.";
+
+ readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style),
+ propertyChanged: OnBasedOnResourceChanged);
+
+ readonly List<WeakReference<BindableObject>> _targets = new List<WeakReference<BindableObject>>(4);
+
+ Style _basedOnStyle;
+
+ string _baseResourceKey;
+
+ IList<Behavior> _behaviors;
+
+ IList<TriggerBase> _triggers;
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Style([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType)
+ {
+ if (targetType == null)
+ throw new ArgumentNullException("targetType");
+
+ TargetType = targetType;
+ Setters = new List<Setter>();
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool ApplyToDerivedTypes { get; set; }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Style BasedOn
+ {
+ get { return _basedOnStyle; }
+ set
+ {
+ if (_basedOnStyle == value)
+ return;
+ if (!ValidateBasedOn(value))
+ throw new ArgumentException("BasedOn.TargetType is not compatible with TargetType");
+ Style oldValue = _basedOnStyle;
+ _basedOnStyle = value;
+ BasedOnChanged(oldValue, value);
+ if (value != null)
+ BaseResourceKey = null;
+ }
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string BaseResourceKey
+ {
+ get { return _baseResourceKey; }
+ set
+ {
+ if (_baseResourceKey == value)
+ return;
+ _baseResourceKey = value;
+ //update all DynamicResources
+ foreach (WeakReference<BindableObject> bindableWr in _targets)
+ {
+ BindableObject target;
+ if (!bindableWr.TryGetTarget(out target))
+ continue;
+ target.RemoveDynamicResource(_basedOnResourceProperty);
+ if (value != null)
+ target.SetDynamicResource(_basedOnResourceProperty, value);
+ }
+ if (value != null)
+ BasedOn = null;
+ }
+ }
+
+ internal IList<Behavior> Behaviors
+ {
+ get { return _behaviors ?? (_behaviors = new AttachedCollection<Behavior>()); }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool CanCascade { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Class { get; set; }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<Setter> Setters { get; }
+
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<TriggerBase> Triggers
+ {
+ get { return _triggers ?? (_triggers = new AttachedCollection<TriggerBase>()); }
+ }
+
+ void IStyle.Apply(BindableObject bindable)
+ {
+ _targets.Add(new WeakReference<BindableObject>(bindable));
+ if (BaseResourceKey != null)
+ bindable.SetDynamicResource(_basedOnResourceProperty, BaseResourceKey);
+ ApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type TargetType { get; }
+
+ void IStyle.UnApply(BindableObject bindable)
+ {
+ UnApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
+ bindable.RemoveDynamicResource(_basedOnResourceProperty);
+ _targets.RemoveAll(wr =>
+ {
+ BindableObject target;
+ return wr.TryGetTarget(out target) && target == bindable;
+ });
+ }
+
+ internal bool CanBeAppliedTo(Type targetType)
+ {
+ if (TargetType == targetType)
+ return true;
+ if (!ApplyToDerivedTypes)
+ return false;
+ do
+ {
+ targetType = targetType.GetTypeInfo().BaseType;
+ if (TargetType == targetType)
+ return true;
+ } while (targetType != typeof(Element));
+ return false;
+ }
+
+ void ApplyCore(BindableObject bindable, Style basedOn)
+ {
+ if (basedOn != null)
+ ((IStyle)basedOn).Apply(bindable);
+
+ foreach (Setter setter in Setters)
+ setter.Apply(bindable, true);
+ ((AttachedCollection<Behavior>)Behaviors).AttachTo(bindable);
+ ((AttachedCollection<TriggerBase>)Triggers).AttachTo(bindable);
+ }
+
+ void BasedOnChanged(Style oldValue, Style newValue)
+ {
+ foreach (WeakReference<BindableObject> bindableRef in _targets)
+ {
+ BindableObject bindable;
+ if (!bindableRef.TryGetTarget(out bindable))
+ continue;
+
+ UnApplyCore(bindable, oldValue);
+ ApplyCore(bindable, newValue);
+ }
+ }
+
+ Style GetBasedOnResource(BindableObject bindable)
+ {
+ return (Style)bindable.GetValue(_basedOnResourceProperty);
+ }
+
+ static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue)
+ {
+ // Style style = (bindable as /*VisualElement*/BaseHandle).Style;
+ // if (style == null)
+ // return;
+ // style.UnApplyCore(bindable, (Style)oldValue);
+ // style.ApplyCore(bindable, (Style)newValue);
+ }
+
+ void UnApplyCore(BindableObject bindable, Style basedOn)
+ {
+ ((AttachedCollection<TriggerBase>)Triggers).DetachFrom(bindable);
+ ((AttachedCollection<Behavior>)Behaviors).DetachFrom(bindable);
+ foreach (Setter setter in Setters)
+ setter.UnApply(bindable, true);
+
+ if (basedOn != null)
+ ((IStyle)basedOn).UnApply(bindable);
+ }
+
+ bool ValidateBasedOn(Style value)
+ {
+ if (value == null)
+ return true;
+ return value.TargetType.IsAssignableFrom(TargetType);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Reflection;
+
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.Binding
+{
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ContentProperty("Setters")]
+ [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
+ [AcceptEmptyServiceProvider]
+ public sealed class Trigger : TriggerBase, IValueProvider
+ {
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Trigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new XamlPropertyCondition(), targetType)
+ {
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BindableProperty Property
+ {
+ get { return ((XamlPropertyCondition)Condition).Property; }
+ set
+ {
+ if (((XamlPropertyCondition)Condition).Property == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
+ OnPropertyChanging();
+ ((XamlPropertyCondition)Condition).Property = value;
+ OnPropertyChanged();
+ }
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new IList<Setter> Setters
+ {
+ get { return base.Setters; }
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Value
+ {
+ get { return ((XamlPropertyCondition)Condition).Value; }
+ set
+ {
+ if (((XamlPropertyCondition)Condition).Value == value)
+ return;
+ if (IsSealed)
+ throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
+ OnPropertyChanging();
+ ((XamlPropertyCondition)Condition).Value = value;
+ OnPropertyChanged();
+ }
+ }
+
+ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
+ {
+ //This is no longer required
+ return this;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class TriggerAction
+ {
+ internal TriggerAction(Type associatedType)
+ {
+ if (associatedType == null)
+ throw new ArgumentNullException("associatedType");
+ AssociatedType = associatedType;
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected Type AssociatedType { get; private set; }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected abstract void Invoke(object sender);
+
+ internal virtual void DoInvoke(object sender)
+ {
+ Invoke(sender);
+ }
+ }
+
+ internal abstract class TriggerAction<T> : TriggerAction where T : BindableObject
+ {
+ protected TriggerAction() : base(typeof(T))
+ {
+ }
+
+ protected override void Invoke(object sender)
+ {
+ Invoke((T)sender);
+ }
+
+ protected abstract void Invoke(T sender);
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class TriggerBase : BindableObject, IAttachedObject
+ {
+ bool _isSealed;
+
+ internal TriggerBase(Type targetType)
+ {
+ if (targetType == null)
+ throw new ArgumentNullException("targetType");
+ TargetType = targetType;
+
+ EnterActions = new SealedList<TriggerAction>();
+ ExitActions = new SealedList<TriggerAction>();
+ }
+
+ internal TriggerBase(Condition condition, Type targetType) : this(targetType)
+ {
+ Setters = new SealedList<Setter>();
+ Condition = condition;
+ Condition.ConditionChanged = OnConditionChanged;
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<TriggerAction> EnterActions { get; }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IList<TriggerAction> ExitActions { get; }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool IsSealed
+ {
+ get { return _isSealed; }
+ private set
+ {
+ if (_isSealed == value)
+ return;
+ if (!value)
+ throw new InvalidOperationException("What is sealed can not be unsealed.");
+ _isSealed = value;
+ OnSeal();
+ }
+ }
+
+ /// <since_tizen> 6 </since_tizen>
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Type TargetType { get; }
+
+ internal Condition Condition { get; }
+
+ //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger
+ internal IList<Setter> Setters { get; }
+
+ void IAttachedObject.AttachTo(BindableObject bindable)
+ {
+ IsSealed = true;
+
+ if (bindable == null)
+ throw new ArgumentNullException("bindable");
+ if (!TargetType.IsInstanceOfType(bindable))
+ throw new InvalidOperationException("bindable not an instance of AssociatedType");
+ OnAttachedTo(bindable);
+ }
+
+ void IAttachedObject.DetachFrom(BindableObject bindable)
+ {
+ if (bindable == null)
+ throw new ArgumentNullException("bindable");
+ OnDetachingFrom(bindable);
+ }
+
+ internal virtual void OnAttachedTo(BindableObject bindable)
+ {
+ if (Condition != null)
+ Condition.SetUp(bindable);
+ }
+
+ internal virtual void OnDetachingFrom(BindableObject bindable)
+ {
+ if (Condition != null)
+ Condition.TearDown(bindable);
+ }
+
+ internal virtual void OnSeal()
+ {
+ ((SealedList<TriggerAction>)EnterActions).IsReadOnly = true;
+ ((SealedList<TriggerAction>)ExitActions).IsReadOnly = true;
+ if (Setters != null)
+ ((SealedList<Setter>)Setters).IsReadOnly = true;
+ if (Condition != null)
+ Condition.IsSealed = true;
+ }
+
+ void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)
+ {
+ if (newValue)
+ {
+ foreach (TriggerAction action in EnterActions)
+ action.DoInvoke(bindable);
+ foreach (Setter setter in Setters)
+ setter.Apply(bindable);
+ }
+ else
+ {
+ foreach (Setter setter in Setters)
+ setter.UnApply(bindable);
+ foreach (TriggerAction action in ExitActions)
+ action.DoInvoke(bindable);
+ }
+ }
+
+ internal class SealedList<T> : IList<T>
+ {
+ readonly IList<T> _actual;
+
+ bool _isReadOnly;
+
+ public SealedList()
+ {
+ _actual = new List<T>();
+ }
+
+ public void Add(T item)
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ _actual.Add(item);
+ }
+
+ public void Clear()
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ _actual.Clear();
+ }
+
+ public bool Contains(T item)
+ {
+ return _actual.Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ _actual.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return _actual.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return _isReadOnly; }
+ set
+ {
+ if (_isReadOnly == value)
+ return;
+ if (!value)
+ throw new InvalidOperationException("Can't change this back to non readonly");
+ _isReadOnly = value;
+ }
+ }
+
+ public bool Remove(T item)
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ return _actual.Remove(item);
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return ((IEnumerable)_actual).GetEnumerator();
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return _actual.GetEnumerator();
+ }
+
+ public int IndexOf(T item)
+ {
+ return _actual.IndexOf(item);
+ }
+
+ public void Insert(int index, T item)
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ _actual.Insert(index, item);
+ }
+
+ public T this[int index]
+ {
+ get { return _actual[index]; }
+ set
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ _actual[index] = value;
+ }
+ }
+
+ public void RemoveAt(int index)
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException("This list is ReadOnly");
+ _actual.RemoveAt(index);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class TypeConverter
+ {
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual bool CanConvertFrom(Type sourceType)
+ {
+ if (sourceType == null)
+ throw new ArgumentNullException(nameof(sourceType));
+
+ return sourceType == typeof(string);
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")]
+ public virtual object ConvertFrom(object o)
+ {
+ return null;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")]
+ public virtual object ConvertFrom(CultureInfo culture, object o)
+ {
+ return null;
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual object ConvertFromInvariantString(string value)
+ {
+#pragma warning disable 0618 // retain until ConvertFrom removed
+ return ConvertFrom(CultureInfo.InvariantCulture, value);
+#pragma warning restore
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+#define DO_NOT_CHECK_FOR_BINDING_REUSE
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using System.Collections.Generic;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Binding.Internals
+{
+ //FIXME: need a better name for this, and share with Binding, so we can share more unittests
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class TypedBindingBase : BindingBase
+ {
+ IValueConverter _converter;
+ object _converterParameter;
+ object _source;
+ string _updateSourceEventName;
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IValueConverter Converter {
+ get { return _converter; }
+ set {
+ ThrowIfApplied();
+ _converter = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object ConverterParameter {
+ get { return _converterParameter; }
+ set {
+ ThrowIfApplied();
+ _converterParameter = value;
+ }
+ }
+
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Source {
+ get { return _source; }
+ set {
+ ThrowIfApplied();
+ _source = value;
+ }
+ }
+
+ internal string UpdateSourceEventName {
+ get { return _updateSourceEventName; }
+ set {
+ ThrowIfApplied();
+ _updateSourceEventName = value;
+ }
+ }
+
+ internal TypedBindingBase()
+ {
+ }
+ }
+
+ internal sealed class TypedBinding<TSource, TProperty> : TypedBindingBase
+ {
+ readonly Func<TSource, TProperty> _getter;
+ readonly Action<TSource, TProperty> _setter;
+ readonly PropertyChangedProxy [] _handlers;
+
+ public TypedBinding(Func<TSource, TProperty> getter, Action<TSource, TProperty> setter, Tuple<Func<TSource, object>, string> [] handlers)
+ {
+ if (getter == null)
+ throw new ArgumentNullException(nameof(getter));
+
+ _getter = getter;
+ _setter = setter;
+
+ if (handlers == null)
+ return;
+
+ _handlers = new PropertyChangedProxy [handlers.Length];
+ for (var i = 0; i < handlers.Length; i++)
+ _handlers [i] = new PropertyChangedProxy(handlers [i].Item1, handlers [i].Item2, this);
+ }
+
+ readonly WeakReference<object> _weakSource = new WeakReference<object>(null);
+ readonly WeakReference<BindableObject> _weakTarget = new WeakReference<BindableObject>(null);
+ BindableProperty _targetProperty;
+
+ // Applies the binding to a previously set source and target.
+ internal override void Apply(bool fromTarget = false)
+ {
+ base.Apply(fromTarget);
+
+ BindableObject target;
+#if DO_NOT_CHECK_FOR_BINDING_REUSE
+ if (!_weakTarget.TryGetTarget(out target))
+ throw new InvalidOperationException();
+#else
+ if (!_weakTarget.TryGetTarget(out target) || target == null) {
+ Unapply();
+ return;
+ }
+#endif
+ object source;
+ if (_weakSource.TryGetTarget(out source) && source != null)
+ ApplyCore(source, target, _targetProperty, fromTarget);
+ }
+
+ // Applies the binding to a new source or target.
+ internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
+ {
+ _targetProperty = targetProperty;
+ var source = Source ?? Context ?? context;
+ var isApplied = IsApplied;
+
+ if (Source != null && isApplied && fromBindingContextChanged)
+ return;
+
+ base.Apply(source, bindObj, targetProperty, fromBindingContextChanged);
+
+#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
+ BindableObject prevTarget;
+ if (_weakTarget.TryGetTarget(out prevTarget) && !ReferenceEquals(prevTarget, bindObj))
+ throw new InvalidOperationException("Binding instances can not be reused");
+
+ object previousSource;
+ if (_weakSource.TryGetTarget(out previousSource) && !ReferenceEquals(previousSource, source))
+ throw new InvalidOperationException("Binding instances can not be reused");
+#endif
+ _weakSource.SetTarget(source);
+ _weakTarget.SetTarget(bindObj);
+
+ ApplyCore(source, bindObj, targetProperty);
+ }
+
+ internal override BindingBase Clone()
+ {
+ Tuple<Func<TSource, object>, string> [] handlers = _handlers == null ? null : new Tuple<Func<TSource, object>, string> [_handlers.Length];
+ if (handlers != null) {
+ for (var i = 0; i < _handlers.Length; i++)
+ handlers [i] = new Tuple<Func<TSource, object>, string>(_handlers [i].PartGetter, _handlers [i].PropertyName);
+ }
+ return new TypedBinding<TSource, TProperty>(_getter, _setter, handlers) {
+ Mode = Mode,
+ Converter = Converter,
+ ConverterParameter = ConverterParameter,
+ StringFormat = StringFormat,
+ Source = Source,
+ UpdateSourceEventName = UpdateSourceEventName,
+ };
+ }
+
+ internal override object GetSourceValue(object value, Type targetPropertyType)
+ {
+ if (Converter != null)
+ value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
+
+ //return base.GetSourceValue(value, targetPropertyType);
+ if (StringFormat != null)
+ return string.Format(StringFormat, value);
+
+ return value;
+ }
+
+ internal override object GetTargetValue(object value, Type sourcePropertyType)
+ {
+ if (Converter != null)
+ value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
+
+ //return base.GetTargetValue(value, sourcePropertyType);
+ return value;
+ }
+
+ internal override void Unapply(bool fromBindingContextChanged = false)
+ {
+ if (Source != null && fromBindingContextChanged && IsApplied)
+ return;
+
+#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
+ base.Unapply(fromBindingContextChanged:fromBindingContextChanged);
+#endif
+ if (_handlers != null)
+ Unsubscribe();
+
+#if (!DO_NOT_CHECK_FOR_BINDING_REUSE)
+ _weakSource.SetTarget(null);
+ _weakTarget.SetTarget(null);
+#endif
+ }
+
+ // ApplyCore is as slim as it should be:
+ // Setting 100000 values : 17ms.
+ // ApplyCore 100000 (w/o INPC, w/o unnapply) : 20ms.
+ internal void ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget = false)
+ {
+ var isTSource = sourceObject != null && sourceObject is TSource;
+ var mode = this.GetRealizedMode(property);
+ if ((mode == BindingMode.OneWay || mode == BindingMode.OneTime) && fromTarget)
+ return;
+
+ var needsGetter = (mode == BindingMode.TwoWay && !fromTarget) || mode == BindingMode.OneWay || mode == BindingMode.OneTime;
+
+ if (isTSource && (mode == BindingMode.OneWay || mode == BindingMode.TwoWay) && _handlers != null)
+ Subscribe((TSource)sourceObject);
+
+ if (needsGetter) {
+ var value = property.DefaultValue;
+ if (isTSource) {
+ try {
+ value = GetSourceValue(_getter((TSource)sourceObject), property.ReturnType);
+ } catch (Exception ex) when (ex is NullReferenceException || ex is KeyNotFoundException) {
+ }
+ }
+ if (!TryConvert(ref value, property, property.ReturnType, true)) {
+ // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType);
+ return;
+ }
+ target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false);
+ return;
+ }
+
+ var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource;
+ if (needsSetter && _setter != null && isTSource) {
+ var value = GetTargetValue(target.GetValue(property), typeof(TProperty));
+ if (!TryConvert(ref value, property, typeof(TProperty), false)) {
+ // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, typeof(TProperty));
+ return;
+ }
+ _setter((TSource)sourceObject, (TProperty)value);
+ }
+ }
+
+ static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget)
+ {
+ if (value == null)
+ return true;
+ if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value)))
+ return true;
+
+ object original = value;
+ try {
+ value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture);
+ return true;
+ } catch (Exception ex ) when (ex is InvalidCastException || ex is FormatException||ex is OverflowException) {
+ value = original;
+ return false;
+ }
+ }
+
+ class PropertyChangedProxy
+ {
+ public Func<TSource, object> PartGetter { get; }
+ public string PropertyName { get; }
+ public BindingExpression.WeakPropertyChangedProxy Listener { get; }
+ WeakReference<INotifyPropertyChanged> _weakPart = new WeakReference<INotifyPropertyChanged>(null);
+ readonly BindingBase _binding;
+
+ public INotifyPropertyChanged Part {
+ get {
+ INotifyPropertyChanged target;
+ if (_weakPart.TryGetTarget(out target))
+ return target;
+ return null;
+ }
+ set {
+ _weakPart.SetTarget(value);
+ Listener.SubscribeTo(value, OnPropertyChanged);
+ }
+ }
+
+ public PropertyChangedProxy(Func<TSource, object> partGetter, string propertyName, BindingBase binding)
+ {
+ PartGetter = partGetter;
+ PropertyName = propertyName;
+ _binding = binding;
+ Listener = new BindingExpression.WeakPropertyChangedProxy();
+ }
+
+ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (!string.IsNullOrEmpty(e.PropertyName) && string.CompareOrdinal(e.PropertyName, PropertyName) != 0)
+ return;
+ Device.BeginInvokeOnMainThread(() => _binding.Apply(false));
+ }
+ }
+
+ void Subscribe(TSource sourceObject)
+ {
+ for (var i = 0; i < _handlers.Length; i++) {
+ var part = _handlers [i].PartGetter(sourceObject);
+ if (part == null)
+ break;
+ var inpc = part as INotifyPropertyChanged;
+ if (inpc == null)
+ continue;
+ _handlers [i].Part = (inpc);
+ }
+ }
+
+ void Unsubscribe()
+ {
+ for (var i = 0; i < _handlers.Length; i++)
+ _handlers [i].Listener.Unsubscribe();
+ }
+ }
+}
\ No newline at end of file
[EditorBrowsable(EditorBrowsableState.Never)]
public string AssemblyName { get; set; }
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public int Level { get; set; }
+
/// 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 XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
ClrNamespace = clrNamespace;
XmlNamespace = xmlNamespace;
+ Level = 0;
}
}
}
\ No newline at end of file