public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
- static private Dictionary<object, Dictionary<resChangeCb, int>> resourceChangeCallbackDict = new Dictionary<object, Dictionary<resChangeCb, int>>();
- static public void AddResourceChangedCallback(object handle, resChangeCb cb)
- {
- Dictionary<resChangeCb, int> cbDict;
- resourceChangeCallbackDict.TryGetValue(handle, out cbDict);
-
- if (null == cbDict)
- {
- cbDict = new Dictionary<resChangeCb, int>();
- resourceChangeCallbackDict.Add(handle, cbDict);
- }
-
- if (false == cbDict.ContainsKey(cb))
- {
- cbDict.Add(cb, 0);
- }
- }
+ internal event EventHandler<ResourcesChangedEventArgs> XamlResourceChanged;
internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
{
base.OnResourcesChanged(sender, e);
-
- foreach (KeyValuePair<object, Dictionary<resChangeCb, int>> resourcePair in resourceChangeCallbackDict)
- {
- foreach (KeyValuePair<resChangeCb, int> cbPair in resourcePair.Value)
- {
- cbPair.Key(sender, e);
- }
- }
+ XamlResourceChanged?.Invoke(sender, e);
}
public ResourceDictionary XamlResources
value = Activator.CreateInstance(type, defaultParams.ToArray());
}
- if (value is Element)
+ if (value is Element element)
{
if (null != Application.Current)
{
- Application.AddResourceChangedCallback(value, (value as Element).OnResourcesChanged);
+ Application.Current.XamlResourceChanged += element.OnResourcesChanged;
}
- if (value is BindableObject)
- {
- ((BindableObject)value).IsCreateByXaml = true;
- }
+ element.IsCreateByXaml = true;
}
}
}
{
//non-default ctor
object ret = Activator.CreateInstance(nodeType, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, null, arguments, CultureInfo.CurrentCulture);
- if (ret is Element)
+ if (ret is Element element)
{
if (null != Application.Current)
{
- Application.AddResourceChangedCallback(ret, (ret as Element).OnResourcesChanged);
+ Application.Current.XamlResourceChanged += element.OnResourcesChanged;
}
- if (ret is BindableObject)
- {
- ((BindableObject)ret).IsCreateByXaml = true;
- }
+ element.IsCreateByXaml = true;
}
return ret;
}
else
{
value = Activator.CreateInstance(nodeType);
- if (value is Element)
+ if (value is Element element)
{
if (null != Application.Current)
{
- Application.AddResourceChangedCallback(value, (value as Element).OnResourcesChanged);
+ Application.Current.XamlResourceChanged += element.OnResourcesChanged;
}
- if (value is BindableObject)
- {
- ((BindableObject)value).IsCreateByXaml = true;
- }
+ element.IsCreateByXaml = true;
}
}
{
bindableObject.bindingContext = newValue;
bindableObject.FlushBinding();
+
+ if (newValue is BindableObject targetBindableObject)
+ {
+ targetBindableObject.IsCreateByXaml = true;
+ }
}
}),
defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
if (this.TryGetResource(key, out value))
OnResourceChanged(property, value);
- Tizen.NUI.Application.AddResourceChangedCallback(this, (this as Element).OnResourcesChanged);
+ if (null != Application.Current)
+ {
+ Application.Current.XamlResourceChanged += OnResourcesChanged;
+ }
}
internal event EventHandler ParentSet;