-/*
+/*
* Copyright(c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
#if !PROFILE_WEARABLE
+using System.Collections.Generic;
using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.Components
{
// It is a C# version of res/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml
internal class DefaultThemeCreator : IThemeCreator
{
- public Theme Create()
+ public ResourceDictionary CreateThemeResource() => new ResourceDictionary()
+ {
+ ["ButtonBackgroundColorNormal"] = new Color(0.88f, 0.88f, 0.88f, 1),
+ ["ButtonBackgroundColorPressed"] = new Color(0.77f, 0.77f, 0.77f, 1),
+ ["ButtonBackgroundColorDisabled"] = new Color(0.88f, 0.88f, 0.88f, 1),
+ ["ButtonTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
+ ["ButtonTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
+ ["ButtonTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
+ ["CheckBoxIconBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
+ ["CheckBoxIconBackgroundImageSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
+ ["CheckBoxIconBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_n.png",
+ ["CheckBoxIconImageResourceUrlPressed"] = "",
+ ["CheckBoxIconImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_s.png",
+ ["CheckBoxIconImageResourceUrlOther"] = "",
+ ["CheckBoxTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
+ ["CheckBoxTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
+ ["CheckBoxTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
+ ["DropDownBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
+ ["DropDownBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_n.png",
+ ["DropDownIconImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_dropdown_button_icon.png",
+ ["DropDownListBackgroundImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_dropdown_list_bg.png",
+ ["DropDownDataItemBackgroundColorPressed"] = new Color(0.05f, 0.63f, 0.9f, 1),
+ ["DropDownDataItemBackgroundColorSelected"] = new Color(0.8f, 0.8f, 0.8f, 1),
+ ["DropDownDataItemBackgroundColorNormal"] = new Color(1, 1, 1, 1),
+ ["PopupBackgroundColor"] = new Color(0.9f, 0.9f, 0.9f, 1),
+ ["PopupImageShadowUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_popup_shadow.png",
+ ["PopupButtonBackgroundColorNormal"] = new Color(1, 1, 1, 1),
+ ["PopupButtonBackgroundColorPressed"] = new Color(1, 1, 1, 0.5f),
+ ["PopupButtonOverlayBackgroundColorNormal"] = new Color(1, 1, 1, 1),
+ ["PopupButtonOverlayBackgroundColorPressed"] = new Color(0, 0, 0, 0.1f),
+ ["PopupButtonOverlayBackgroundColorSelected"] = new Color(1, 1, 1, 1),
+ ["PopupButtonTextColor"] = new Color(0.05f, 0.63f, 0.9f, 1),
+ ["ProgressTrackBackgroundColor"] = new Color(0, 0, 0, 0.1f),
+ ["ProgressBufferBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 0.3f),
+ ["ProgressProgressBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 1),
+ ["RadioButtonIconBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_p.png",
+ ["RadioButtonIconBackgroundImageSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_s.png",
+ ["RadioButtonIconBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_n.png",
+ ["RadioButtonTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
+ ["RadioButtonTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
+ ["RadioButtonTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
+ ["SliderTrackColor"] = new Color(0, 0, 0, 0.1f),
+ ["SliderProgressColor"] = new Color(0.5f, 0.63f, 0.9f, 1),
+ ["SliderThumbImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_n.png",
+ ["SliderThumbBackgroundImageNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_bg_p.png",
+ ["SliderThumbBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_bg_p.png",
+ ["SwitchTrackImageResourceUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_n.png",
+ ["SwitchTrackImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_s.png",
+ ["SwitchTrackImageResourceUrlDisabled"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_d.png",
+ ["SwitchTrackImageResourceUrlDisabledSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_ds.png",
+ ["SwitchThumbImageResourceUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
+ ["SwitchThumbImageResourceUrlDisabled"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_d.png",
+ ["SwitchThumbImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
+ ["SwitchTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
+ ["SwitchTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
+ ["SwitchTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
+ ["TabBackgroundColor"] = Color.Yellow,
+ ["TabUnderLineBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 1.0f),
+ ["TabTextColorNormal"] = Color.Black,
+ ["TabTextColorSelected"] = new Color(0.05f, 0.63f, 0.9f, 1),
+ ["ToastBackgroundColor"] = new Color(0, 0, 0, 0.8f),
+ ["PaginationIndicatorImageUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_pagination_normal_dot.png",
+ ["PaginationIndicatorImageUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_pagination_focus_dot.png",
+ ["ScrollbarTrackColor"] = new Color(1, 1, 1, 0.15f),
+ ["ScrollbarThumbColor"] = new Color(0.6f, 0.6f, 0.6f, 1.0f),
+ };
+
+ public Theme Create() => Create(null);
+
+ public Theme Create(IEnumerable<KeyValuePair<string, string>> changedResources)
{
var theme = new Theme() { Id = "Tizen.NUI.Theme.Common" };
+ theme.SetChangedResources(changedResources);
+ theme.Resources = CreateThemeResource();
+ theme.OnThemeResourcesChanged();
+
theme.AddStyleWithoutClone("Tizen.NUI.Components.Button", new ButtonStyle()
{
Size = new Size(100, 45),
BackgroundColor = new Selector<Color>()
{
- Normal = new Color(0.88f, 0.88f, 0.88f, 1),
- Pressed = new Color(0.77f, 0.77f, 0.77f, 1),
- Disabled = new Color(0.88f, 0.88f, 0.88f, 1),
+ Normal = (Color)theme.Resources["ButtonBackgroundColorNormal"],
+ Pressed = (Color)theme.Resources["ButtonBackgroundColorPressed"],
+ Disabled = (Color)theme.Resources["ButtonBackgroundColorDisabled"],
},
Text = new TextLabelStyle()
{
PointSize = 12,
TextColor = new Selector<Color>()
{
- Normal = new Color(0.22f, 0.22f, 0.22f, 1),
- Pressed = new Color(0.11f, 0.11f, 0.11f, 1),
- Disabled = new Color(0.66f, 0.66f, 0.66f, 1),
+ Normal = (Color)theme.Resources["ButtonTextColorNormal"],
+ Pressed = (Color)theme.Resources["ButtonTextColorPressed"],
+ Disabled = (Color)theme.Resources["ButtonTextColorDisabled"],
}
}
});
},
BackgroundImage = new Selector<string>()
{
- Pressed = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
- Other = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_n.png",
+ Pressed = (string)theme.Resources["CheckBoxIconBackgroundImagePressed"],
+ Selected = (string)theme.Resources["CheckBoxIconBackgroundImageSelected"],
+ Other = (string)theme.Resources["CheckBoxIconBackgroundImageOther"],
},
ResourceUrl = new Selector<string>()
{
- Pressed = "",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_s.png",
- Other = "",
+ Pressed = (string)theme.Resources["CheckBoxIconImageResourceUrlPressed"],
+ Selected = (string)theme.Resources["CheckBoxIconImageResourceUrlSelected"],
+ Other = (string)theme.Resources["CheckBoxIconImageResourceUrlOther"],
},
},
Text = new TextLabelStyle()
PointSize = 12,
TextColor = new Selector<Color>()
{
- Normal = new Color(0.22f, 0.22f, 0.22f, 1),
- Pressed = new Color(0.11f, 0.11f, 0.11f, 1),
- Disabled = new Color(0.66f, 0.66f, 0.66f, 1),
+ Normal = (Color)theme.Resources["CheckBoxTextColorNormal"],
+ Pressed = (Color)theme.Resources["CheckBoxTextColorPressed"],
+ Disabled = (Color)theme.Resources["CheckBoxTextColorDisabled"],
}
}
});
theme.AddStyleWithoutClone("Tizen.NUI.Components.Popup", new PopupStyle()
{
Size = new Size(500, 280),
- BackgroundColor = new Color(0.9f, 0.9f, 0.9f, 1),
+ BackgroundColor = (Color)theme.Resources["PopupBackgroundColor"],
ImageShadow = new ImageShadow()
{
- Url = FrameworkInformation.ResourcePath + "nui_component_default_popup_shadow.png",
+ Url = (string)theme.Resources["PopupImageShadowUrl"],
Border = new Rectangle(24, 24, 24, 24),
Extents = new Vector2(48, 48)
},
Size = new Size(0, 80),
BackgroundColor = new Selector<Color>()
{
- Normal = new Color(1, 1, 1, 1),
- Pressed = new Color(1, 1, 1, 0.5f),
+ Normal = (Color)theme.Resources["PopupButtonBackgroundColorNormal"],
+ Pressed = (Color)theme.Resources["PopupButtonBackgroundColorPressed"],
},
Overlay = new ImageViewStyle()
{
BackgroundColor = new Selector<Color>()
{
- Pressed = new Color(0, 0, 0, 0.1f),
- Other = new Color(1, 1, 1, 1),
+ Normal = (Color)theme.Resources["PopupButtonOverlayBackgroundColorNormal"],
+ Pressed = (Color)theme.Resources["PopupButtonOverlayBackgroundColorPressed"],
+ Other = (Color)theme.Resources["PopupButtonOverlayBackgroundColorSelected"],
},
},
Text = new TextLabelStyle()
{
- TextColor = new Color(0.05f, 0.63f, 0.9f, 1),
+ TextColor = (Color)theme.Resources["PopupButtonTextColor"],
}
}
});
Size = new Size(200, 5),
Track = new ImageViewStyle()
{
- BackgroundColor = new Color(0, 0, 0, 0.1f),
+ BackgroundColor = (Color)theme.Resources["ProgressTrackBackgroundColor"],
},
Buffer = new ImageViewStyle()
{
- BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 0.3f),
+ BackgroundColor = (Color)theme.Resources["ProgressBufferBackgroundColor"],
},
Progress = new ImageViewStyle()
{
- BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 1),
+ BackgroundColor = (Color)theme.Resources["ProgressProgressBackgroundColor"],
},
});
},
BackgroundImage = new Selector<string>()
{
- Pressed = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_p.png",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_s.png",
- Other = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_n.png",
+ Pressed = (string)theme.Resources["RadioButtonIconBackgroundImagePressed"],
+ Selected = (string)theme.Resources["RadioButtonIconBackgroundImageSelected"],
+ Other = (string)theme.Resources["RadioButtonIconBackgroundImageOther"],
}
},
Text = new TextLabelStyle()
PointSize = 12,
TextColor = new Selector<Color>()
{
- Normal = new Color(0.22f, 0.22f, 0.22f, 1),
- Pressed = new Color(0.11f, 0.11f, 0.11f, 1),
- Disabled = new Color(0.66f, 0.66f, 0.66f, 1),
+ Normal = (Color)theme.Resources["RadioButtonTextColorNormal"],
+ Pressed = (Color)theme.Resources["RadioButtonTextColorPressed"],
+ Disabled = (Color)theme.Resources["RadioButtonTextColorDisabled"],
}
}
});
TrackThickness = 5,
Track = new ImageViewStyle()
{
- BackgroundColor = new Color(0, 0, 0, 0.1f),
+ BackgroundColor = (Color)theme.Resources["SliderTrackColor"],
},
Progress = new ImageViewStyle()
{
- BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 1),
+ BackgroundColor = (Color)theme.Resources["SliderProgressColor"],
},
Thumb = new ImageViewStyle()
{
Size = new Size(50, 50),
- ResourceUrl = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_n.png",
+ ResourceUrl = (string)theme.Resources["SliderThumbImageResourceUrl"],
BackgroundImage = new Selector<string>()
{
- Normal = "",
- Pressed = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_bg_p.png",
+ Normal = (string)theme.Resources["SliderThumbBackgroundImageNormal"],
+ Pressed = (string)theme.Resources["SliderThumbBackgroundImagePressed"],
}
},
});
Size = new Size(96, 60),
ResourceUrl = new Selector<string>()
{
- Normal = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_n.png",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_s.png",
- Disabled = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_d.png",
- DisabledSelected = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_ds.png",
+ Normal = (string)theme.Resources["SwitchTrackImageResourceUrlNormal"],
+ Selected = (string)theme.Resources["SwitchTrackImageResourceUrlSelected"],
+ Disabled = (string)theme.Resources["SwitchTrackImageResourceUrlDisabled"],
+ DisabledSelected = (string)theme.Resources["SwitchTrackImageResourceUrlDisabledSelected"],
}
},
Thumb = new ImageViewStyle()
Size = new Size(60, 60),
ResourceUrl = new Selector<string>()
{
- Normal = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
- Disabled = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_d.png",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
+ Normal = (string)theme.Resources["SwitchThumbImageResourceUrlNormal"],
+ Disabled = (string)theme.Resources["SwitchThumbImageResourceUrlDisabled"],
+ Selected = (string)theme.Resources["SwitchThumbImageResourceUrlSelected"],
}
},
Text = new TextLabelStyle()
PointSize = 12,
TextColor = new Selector<Color>()
{
- Normal = new Color(0.22f, 0.22f, 0.22f, 1),
- Pressed = new Color(0.11f, 0.11f, 0.11f, 1),
- Disabled = new Color(0.66f, 0.66f, 0.66f, 1),
+ Normal = (Color)theme.Resources["SwitchTextColorNormal"],
+ Pressed = (Color)theme.Resources["SwitchTextColorPressed"],
+ Disabled = (Color)theme.Resources["SwitchTextColorDisabled"],
}
}
});
theme.AddStyleWithoutClone("Tizen.NUI.Components.Tab", new TabStyle()
{
Size = new Size(480, 80),
- BackgroundColor = Color.Yellow,
+ BackgroundColor = (Color)theme.Resources["TabBackgroundColor"],
UnderLine = new ViewStyle()
{
Size = new Size(0, 6),
- BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 1),
+ BackgroundColor = (Color)theme.Resources["TabUnderLineBackgroundColor"],
},
Text = new TextLabelStyle()
{
PointSize = 16,
TextColor = new Selector<Color>()
{
- Normal = Color.Black,
- Selected = new Color(0.05f, 0.63f, 0.9f, 1),
+ Normal = (Color)theme.Resources["TabTextColorNormal"],
+ Selected = (Color)theme.Resources["TabTextColorSelected"],
}
}
});
theme.AddStyleWithoutClone("Tizen.NUI.Components.Toast", new ToastStyle()
{
Size = new Size(480, 80),
- BackgroundColor = new Color(0, 0, 0, 0.8f),
+ BackgroundColor = (Color)theme.Resources["ToastBackgroundColor"],
Text = new TextLabelStyle()
{
Padding = new Extents(12, 12, 8, 8)
{
IndicatorImageUrl = new Selector<string>()
{
- Normal = FrameworkInformation.ResourcePath + "nui_component_default_pagination_normal_dot.png",
- Selected = FrameworkInformation.ResourcePath + "nui_component_default_pagination_focus_dot.png",
+ Normal = (string)theme.Resources["PaginationIndicatorImageUrlNormal"],
+ Selected = (string)theme.Resources["PaginationIndicatorImageUrlSelected"],
}
});
{
TrackThickness = 6,
ThumbThickness = 6,
- TrackColor = new Color(1, 1, 1, 0.15f),
- ThumbColor = new Color(0.6f, 0.6f, 0.6f, 1),
+ TrackColor = (Color)theme.Resources["ScrollbarTrackColor"],
+ ThumbColor = (Color)theme.Resources["ScrollbarThumbColor"],
TrackPadding = 4
});
/// </para>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public class Theme : BindableObject, IResourcesProvider
+ public class Theme : BindableObject
{
private readonly Dictionary<string, ViewStyle> map;
+ private IEnumerable<KeyValuePair<string, string>> changedResources = null;
private string baseTheme;
- private string resource;
- private string xamlFile;
-
- /// <summary>
- /// The resource file path that is used in the theme.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string Resource
- {
- get => resource;
- set
- {
- if (resource == value) return;
- resource = value;
-
- Reload();
- }
- }
+ ResourceDictionary resources;
/// <summary>Create an empty theme.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
throw new ArgumentNullException(nameof(xamlFile), "The xaml file path cannot be null or empty string");
}
- LoadFromXaml(xamlFile);
- }
-
- /// <summary>
- /// Create a new theme from the xaml file with theme resource.
- /// </summary>
- /// <param name="xamlFile">An absolute path to the xaml file.</param>
- /// <param name="themeResource">An absolute path to the theme resource file.</param>
- /// <exception cref="ArgumentNullException">Thrown when the given xamlFile or themeResource is null or empty string.</exception>
- /// <exception cref="System.IO.IOException">Thrown when there are file IO problems.</exception>
- /// <exception cref="Exception">Thrown when the content of the xaml file is not valid xaml form.</exception>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Theme(string xamlFile, string themeResource) : this()
- {
- if (string.IsNullOrEmpty(xamlFile))
- throw new ArgumentNullException(nameof(xamlFile), "The xaml file path cannot be null or empty string");
- if (string.IsNullOrEmpty(themeResource))
- throw new ArgumentNullException(nameof(themeResource), "The theme resource file path cannot be null or empty string");
-
- resource = themeResource;
- XamlResources.SetAndLoadSource(new Uri(themeResource), themeResource, Assembly.GetAssembly(GetType()), null);
-
- LoadFromXaml(xamlFile);
+ try
+ {
+ using (var reader = XmlReader.Create(xamlFile))
+ {
+ XamlLoader.Load(this, reader);
+ }
+ }
+ catch (System.IO.IOException)
+ {
+ Tizen.Log.Error("NUI", $"Could not load \"{xamlFile}\".\n");
+ throw;
+ }
+ catch (Exception)
+ {
+ Tizen.Log.Error("NUI", $"Could not parse \"{xamlFile}\".\n");
+ Tizen.Log.Error("NUI", "Make sure the all used assemblies (e.g. Tizen.NUI.Components) are included in the application project.\n");
+ Tizen.Log.Error("NUI", "Make sure the type and namespace are correct.\n");
+ throw;
+ }
}
/// <summary>
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsResourcesCreated { get; } = true;
+ public bool IsResourcesCreated => resources != null;
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
- public ResourceDictionary XamlResources { get; set; } = new ResourceDictionary();
+ internal ResourceDictionary Resources
+ {
+ get
+ {
+ if (resources != null)
+ return resources;
+ resources = new ResourceDictionary();
+ ((IResourceDictionary)resources).ValuesChanged += OnThemeResourcesChanged;
+ return resources;
+ }
+ set
+ {
+ if (resources == value)
+ return;
+
+ if (resources != null)
+ {
+ ((IResourceDictionary)resources).ValuesChanged -= OnThemeResourcesChanged;
+ }
+ resources = value;
+ if (resources != null)
+ {
+ // This callback will be removed when Resource.Source is assigned.
+ ((IResourceDictionary)resources).ValuesChanged += OnThemeResourcesChanged;
+ }
+ }
+ }
/// <summary>
/// For Xaml use only.
var result = new Theme()
{
Id = this.Id,
+ Resources = Resources
};
foreach (var item in this)
if (theme == null)
throw new ArgumentNullException(nameof(theme));
- this.xamlFile = theme.xamlFile;
-
if (Id == null) Id = theme.Id;
foreach (var item in theme)
map[item.Key] = item.Value;
}
}
+
+ if (theme.resources != null)
+ {
+ foreach (var res in theme.resources)
+ {
+ Resources[res.Key] = res.Value;
+ }
+ }
}
/// <summary>
/// </summary>
internal void AddStyleWithoutClone(string styleName, ViewStyle value) => map[styleName] = value;
- internal void Reload()
+ internal void SetChangedResources(IEnumerable<KeyValuePair<string, string>> changedResources)
{
- if (xamlFile == null)
- throw new InvalidOperationException("Cannot reload without xaml file.");
-
- map.Clear();
- if (Resource != null)
- {
- XamlResources.Clear();
- XamlResources.SetAndLoadSource(new Uri(Resource), Resource, Assembly.GetAssembly(GetType()), null);
- }
-
- LoadFromXaml(xamlFile);
+ this.changedResources = changedResources;
}
- private void LoadFromXaml(string xamlFile)
+ internal void OnThemeResourcesChanged(object sender, ResourcesChangedEventArgs e) => OnThemeResourcesChanged();
+
+ internal void OnThemeResourcesChanged()
{
- try
+ if (changedResources != null)
{
- using (var reader = XmlReader.Create(xamlFile))
+ // To avoid loop in infinite, remove OnThemeResourcesChanged callback.
+ ((IResourceDictionary)resources).ValuesChanged -= OnThemeResourcesChanged;
+ foreach (var changedResource in changedResources)
{
- this.xamlFile = xamlFile;
- XamlLoader.Load(this, reader);
+ if (resources.TryGetValue(changedResource.Key, out object resourceValue))
+ {
+ string changedValue = changedResource.Value;
+
+ // check NUIResourcePath
+ string[] changedValues = changedValue.Split('/');
+ if (changedValues[0] == "NUIResourcePath")
+ {
+ changedValue = changedValues[1];
+ }
+
+ Type toType = resourceValue.GetType();
+ resources[changedResource.Key] = changedValue.ConvertTo(toType, () => toType.GetTypeInfo(), null);
+ }
}
}
- catch (System.IO.IOException)
- {
- Tizen.Log.Error("NUI", $"Could not load \"{xamlFile}\".\n");
- throw;
- }
- catch (Exception)
- {
- Tizen.Log.Error("NUI", $"Could not parse \"{xamlFile}\".\n");
- Tizen.Log.Error("NUI", "Make sure the all used assemblies (e.g. Tizen.NUI.Components) are included in the application project.\n");
- Tizen.Log.Error("NUI", "Make sure the type and namespace are correct.\n");
- throw;
- }
}
}
}