コード例 #1
0
        public static void BindTo <TNavigationItem>(this INavigationItemContainer <TNavigationItem> component,
                                                    IEnumerable dataSource, Action <NavigationBindingFactory <TNavigationItem> > factoryAction)
            where TNavigationItem : NavigationItem <TNavigationItem>, INavigationItemContainer <TNavigationItem>, new()
        {
            NavigationBindingFactory <TNavigationItem> factory = new NavigationBindingFactory <TNavigationItem>();

            factoryAction(factory);

            foreach (object dataItem in dataSource)
            {
                TNavigationItem item = new TNavigationItem();
                component.Items.Add(item);
                Bind(item, dataItem, factory);
            }
        }
コード例 #2
0
        public static void Bind <TNavigationItem>(TNavigationItem component, object dataItem,
                                                  NavigationBindingFactory <TNavigationItem> factory)
            where TNavigationItem : NavigationItem <TNavigationItem>, INavigationItemContainer <TNavigationItem>, new()
        {
            INavigationBinding <TNavigationItem> binding = factory.container.Where(b => b.Type.IsAssignableFrom(dataItem.GetType())).First();

            binding.ItemDataBound(component, dataItem);
            IEnumerable children = binding.Children(dataItem);

            if (children != null)
            {
                foreach (var childDataItem in children)
                {
                    TNavigationItem item = new TNavigationItem();
                    component.Items.Add(item);

                    Bind(item, childDataItem, factory);
                }
            }
        }