[NUI][Test] xaml indexer sample
authordongsug.song <dongsug.song@samsung.com>
Wed, 23 Feb 2022 04:25:03 +0000 (13:25 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 10 Mar 2022 08:03:31 +0000 (17:03 +0900)
test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.cs [new file with mode: 0644]
test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml [new file with mode: 0644]
test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml.cs [new file with mode: 0644]

diff --git a/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.cs b/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.cs
new file mode 100644 (file)
index 0000000..43db4c2
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright(c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using System;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace NUITizenGallery
+{
+    internal class XamlIndexerTest : IExample
+    {
+        Window window;
+
+        public void Activate()
+        {
+            window = NUIApplication.GetDefaultWindow();
+            window.GetDefaultNavigator().Push(new XamlIndexerTestPage());
+            Console.WriteLine($"type of MyIndexer={MyIndexer.Instance["1"]}, MyIndexer.Instance[2].Width={MyIndexer.Instance["2"].Width}");
+        }
+        public void Deactivate()
+        {
+            window.GetDefaultNavigator().Pop();
+        }
+    }
+}
diff --git a/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml b/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml
new file mode 100644 (file)
index 0000000..7acfe4e
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ContentPage x:Class="NUITizenGallery.XamlIndexerTestPage"
+  xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
+  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+  xmlns:e="clr-namespace:NUITizenGallery;"
+  WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
+  HeightSpecification="{Static LayoutParamPolicies.MatchParent}">
+
+    <!-- AppBar is top-side bar with navigation content, title, and action. If you not set any contents, back button is automatically added. -->
+    <ContentPage.AppBar>
+        <AppBar x:Name="appBar" Title="XamlIndexerTestPage"/>
+    </ContentPage.AppBar>
+
+    <!-- Content is main placeholder of ContentPage. Add your content into this view. -->
+    <ContentPage.Content>
+        <View WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
+              HeightSpecification="{Static LayoutParamPolicies.MatchParent}">
+        <View.Layout>
+            <LinearLayout LinearOrientation="Vertical" CellPadding="10,10" LinearAlignment="Begin"/>
+        </View.Layout>
+            <TextLabel BackgroundColor="Red" Size="{e:MyIndexerExtension Key=1}" Text="idx=1"/>
+            <TextLabel BackgroundColor="Yellow" Size="{e:MyIndexerExtension Key=2}" Text="idx=2"/>
+        </View>
+    </ContentPage.Content>
+
+</ContentPage>
diff --git a/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml.cs b/test/NUITizenGallery/Examples/XamlIndexerTest/XamlIndexerTest.xaml.cs
new file mode 100644 (file)
index 0000000..d4c4203
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using System;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using Tizen.NUI.Xaml;
+
+namespace NUITizenGallery
+{
+    public partial class XamlIndexerTestPage : ContentPage
+    {
+        public XamlIndexerTestPage()
+        {
+            InitializeComponent();
+        }
+    }
+
+    public class MyIndexer
+    {
+        public Size this[string index]
+        {
+            get
+            {
+                switch (index)
+                {
+                    case "0":
+                    default:
+                        return new Size(0, 0, 0);
+                        break;
+                    case "1":
+                        return new Size(100, 100, 0);
+                        break;
+                    case "2":
+                        return new Size(200, 200, 0);
+                        break;
+
+                }
+            }
+        }
+        static private MyIndexer instance;
+
+        static public MyIndexer Instance
+        {
+            get
+            {
+                if (null == instance)
+                {
+                    instance = new MyIndexer();
+                }
+                return instance;
+            }
+        }
+    }
+
+    internal class MyIndexerExtension : IMarkupExtension<Size>
+    {
+        public string Key
+        {
+            get;
+            set;
+        }
+        
+        //used for XamlC, in csproj <NeedInjection>True</NeedInjection>
+        public Size ProvideValue(IServiceProvider serviceProvider)
+        {
+            //should be same implementation with IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) below.
+            return MyIndexer.Instance[Key];
+        }
+        
+        //used for EXaml, in csproj <NeedInjection>False</NeedInjection>
+        object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+        {
+            //should be same implementation with ProvideValue(IServiceProvider serviceProvider) above.
+            return MyIndexer.Instance[Key];
+        }
+    }
+}