2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
20 using System.Collections.Generic;
22 namespace Tizen.NUI.Binding
25 /// Selects DataTemplate objects by data type and container.
27 /// <since_tizen> 9 </since_tizen>
28 public abstract class DataTemplateSelector : DataTemplate
30 Dictionary<Type, DataTemplate> _dataTemplates = new Dictionary<Type, DataTemplate>();
33 /// Returns a DataTemplate for item by calling
34 /// OnSelectTemplate(Object, BindableObject) and verifying its result.
36 /// <param name="item">The data for which to return a template.</param>
37 /// <param name="container">An optional container object in which
38 /// the developer may have opted to store DataTemplateSelector objects.</param>
39 /// <returns>A developer-defined DataTemplate that can be used to display item.</returns>
40 public DataTemplate SelectTemplate(object item, BindableObject container)
42 DataTemplate dataTemplate = null;
43 if (_dataTemplates.TryGetValue(item.GetType(), out dataTemplate))
48 dataTemplate = OnSelectTemplate(item, container);
49 if (dataTemplate is DataTemplateSelector)
50 throw new NotSupportedException(
51 "DataTemplateSelector.OnSelectTemplate must not return another DataTemplateSelector");
57 /// The developer overrides this method to return a valid data template for the specified item.
58 /// This method is called by SelectTemplate(Object, BindableObject).
60 /// <param name="item">The data for which to return a template.</param>
61 /// <param name="container">An optional container object in which
62 /// the developer may have opted to store DataTemplateSelector objects.</param>
63 /// <returns>A developer-defined DataTemplate that can be used to display item.</returns>
64 /// <since_tizen> 9 </since_tizen>
65 protected abstract DataTemplate OnSelectTemplate(object item, BindableObject container);