Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / EXaml / EXamlExtensions.cs
index 13ddacf..ff2df56 100755 (executable)
@@ -31,6 +31,7 @@ namespace Tizen.NUI.EXaml
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static TXaml LoadFromEXamlPath<TXaml>(this TXaml view, string path)
         {
+            MainAssembly = view.GetType().Assembly;
             //This EXaml file will be converted by Tizen.NUI.XamlBuild from the .xaml
             string xamlScript = GetXamlFromPath(path);
             LoadEXaml.Load(view, xamlScript);
@@ -39,7 +40,7 @@ namespace Tizen.NUI.EXaml
 
         /// Internal used, will never be opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static TXaml LoadFromEXamlPath<TXaml>(this TXaml view, Type callingType)
+        public static T LoadFromEXamlPath<T>(this T view, Type callingType)
         {
             if (null == callingType)
             {
@@ -79,6 +80,59 @@ namespace Tizen.NUI.EXaml
 
         /// Internal used, will never be opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
+        public static T LoadFromEXamlByRelativePath<T>(this T view, string eXamlPath)
+        {
+            if (null == eXamlPath)
+            {
+                return view;
+            }
+
+            MainAssembly = view.GetType().Assembly;
+
+            string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
+
+            Tizen.Log.Fatal("NUI", "the resource path: " + resource);
+            int windowWidth = NUIApplication.GetDefaultWindow().Size.Width;
+            int windowHeight = NUIApplication.GetDefaultWindow().Size.Height;
+
+            string likelyResourcePath = resource + eXamlPath;
+
+            //Find the xaml file in the layout folder
+            if (File.Exists(likelyResourcePath))
+            {
+                StreamReader reader = new StreamReader(likelyResourcePath);
+                var xaml = reader.ReadToEnd();
+                reader.Close();
+                reader.Dispose();
+
+                LoadEXaml.Load(view, xaml);
+            }
+            else
+            {
+                throw new Exception($"Can't find examl file {eXamlPath}");
+            }
+
+            return view;
+        }
+
+        /// Used for TCT and TC coverage, will never be opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static T LoadFromEXaml<T>(this T view, string eXamlStr)
+        {
+            if (null == eXamlStr)
+            {
+                return view;
+            }
+
+            MainAssembly = view.GetType().Assembly;
+
+            LoadEXaml.Load(view, eXamlStr);
+
+            return view;
+        }
+
+        /// Internal used, will never be opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static Assembly MainAssembly
         {
             get;