示例#1
0
        public override Fragment GetItem(int position)
        {
            var info = FragmentInfos.ElementAt(position);

            info.Fragment.DataContext = info.ViewModel;
            return(info.Fragment);
        }
示例#2
0
        private void Resolve(XElement xElement, ViewComponentBase parentComponent)
        {
            var name = xElement.Name;

            if (string.Equals(name.LocalName, "placeholder", StringComparison.OrdinalIgnoreCase))
            {
                var placeHolderId = xElement.Attribute("id").Value;
                var fragmentInfo  = FragmentInfos.FirstOrDefault(
                    item => string.Equals(item.PlaceHolderId, placeHolderId, StringComparison.OrdinalIgnoreCase));
                if (fragmentInfo == null)
                {
                    throw new Exception("缺少placeHolderId为" + placeHolderId + "的知识片段数据");
                }
                ViewComponent component = new ViewComponent(fragmentInfo);
                component.OrginalEditConfig           = xElement.ToString();
                component.BeforeLoadDataEventHandler += Component_BeforeLoadDataEventHandler;
                component.LoadDataEventHandler       += Component_LoadDataEventHandler;
                component.AfterLoadDataEventHandler  += Component_AfterLoadDataEventHandler;
                AssignmentXmlAttributeToComponent(xElement, component);
                parentComponent.AddChild(component);

                if (ViewComponents == null)
                {
                    ViewComponents = new Dictionary <string, ViewComponent>(StringComparer.OrdinalIgnoreCase);
                }
                component.Id = "v" + (ViewComponents.Count + 1).ToString();
                if (ViewComponents.ContainsKey(component.Id))
                {
                    throw new Exception("存在同名的组件");
                }
                ViewComponents.Add(component.Id, component);
            }
            else
            {
                var parentCom = new ViewComponentContainer();
                AssignmentXmlAttributeToComponent(xElement, parentCom);
                parentCom.OrginalEditConfig = xElement.ToString();
                parentComponent.AddChild(parentCom);
                //如果子孙节点存在placeholder,继续
                if (xElement.Descendants("placeholder").Any())
                {
                    foreach (var childElement in xElement.Elements())
                    {
                        Resolve(childElement, parentCom);
                    }
                }
            }
        }