void pft_OpenPageInfo(object sender, OpenPageInfoEventArgs e) { //-->获取控件 XElement _xe_page = XElement.Parse(e.PageDirectorySub.PageContent.Trim()); if (null == _xe_page) { return; } XElement _xe_xaml = _xe_page.Element("xaml"); XElement _xe_xml = _xe_page.Element("xml"); string xaml = _xe_xaml != null && _xe_xaml.FirstNode != null?_xe_xaml.FirstNode.ToString() : ""; string xml = _xe_xml != null && _xe_xml.FirstNode != null?_xe_xml.FirstNode.ToString() : ""; //-->xml操作 _XmlTemplate_CurrentPage = XmlTemplate.DecodeXml(xml); //-->获取xaml _XamlTemplate = XamlTemplate.DecodeXml(xaml); _PageInfo = Wrapper.CreateUIElement <UserControl>(xaml); LoadControls(); if (null != OpenPageInfo) { OpenPageInfo(this, e); } }
/// <summary> /// 释放资源 /// </summary> public void Dispose() { this.pft.OpenPageInfo -= pft_OpenPageInfo; this.ct.SelectedItemChanged -= ct_SelectedItemChanged; this.lboxProperty.SelectionChanged -= lboxProperty_SelectionChanged; _XmlTemplate_CurrentPage = null; _XamlTemplate = null; _PageInfo = null; _ControlInfo = null; ct.Dispose(); }
/// <summary> /// 结构函数 /// </summary> public PageWorkArea() { InitializeComponent(); IsUpdate = false; _XmlTemplate = new XmlTemplate(); _XamlTemplate = new XamlTemplate(); DesignPage.ControlPosition += PageDesign_ControlPosition; DesignPage.ControlDelete += DesignPage_ControlDelete; txtXaml.LostFocus += txtXaml_LostFocus; txtXml.LostFocus += txtXml_LostFocus; }
/// <summary> /// 重绘 /// </summary> internal void Redraw() { if (null == PageInfo || this.PageInfo.PageContent.IsNullOrEmpty()) { return; } XElement _xe_page = XElement.Parse(this.PageInfo.PageContent.Trim()); if (null == _xe_page) { return; } XElement _xe_xaml = _xe_page.Element("xaml"); XElement _xe_xml = _xe_page.Element("xml"); string xaml = _xe_xaml != null && _xe_xaml.FirstNode != null?_xe_xaml.FirstNode.ToString() : ""; // _xe_xaml.GetElementValue("xaml"); string xml = _xe_xml != null && _xe_xml.FirstNode != null?_xe_xml.FirstNode.ToString() : ""; _XmlTemplate = XmlTemplate.DecodeXml(xml); _XamlTemplate = XamlTemplate.DecodeXml(xaml); UserControl uc = Wrapper.CreateUIElement(xaml) as UserControl; if (null == uc) { return; } this.LayoutRoot.Children.Add(uc); //-->给复合控件设置标题内容,和运行时接口。 SetCompositeCtrlTitleOrInterface(); //-->给控件注册事件 RegisterControl(); //-->加载初化操作。 LoadInitControl(); }
void Xaml_LostFocus(string orgValue, string changeXaml) { if (changeXaml.IsNullOrEmpty() || changeXaml.Equals(orgValue)) { return; } //-->判断控件是否可用。 FrameworkElement fe = Wrapper.LoadXaml <FrameworkElement>(changeXaml); if (null == fe) { _XamlTemplate = new XamlTemplate(); this.Xaml_Template = _XamlTemplate.ParseXml().ToString(); return; } XamlTemplate new_xamlTemplate = XamlTemplate.DecodeXml(changeXaml); //-->判断程序集是否有改变 this._XamlTemplate.AssemblyCollection.AddRange(new_xamlTemplate.AssemblyCollection); XamlCanvasTemplate old_Xaml_CanvasTemplate = this._XamlTemplate.CanvasTemplate; //-->判断画布的大小,背景色是否不同 foreach (var cp in new_xamlTemplate.CanvasTemplate.CanvasPropertyDict) { if (old_Xaml_CanvasTemplate.CanvasPropertyDict.ContainsKey(cp.Key)) { if (!old_Xaml_CanvasTemplate.CanvasPropertyDict[cp.Key].Equals(cp.Value)) { //-->内容有改变 old_Xaml_CanvasTemplate.CanvasPropertyDict[cp.Key] = cp.Value; } } else { old_Xaml_CanvasTemplate.CanvasPropertyDict.Add(cp.Key, cp.Value); } } //-->判断控件 foreach (var child in new_xamlTemplate.CanvasTemplate.Children) { FrameworkElement _news_ctrl = fe.FindName(child.Key) as FrameworkElement; ((fe as UserControl).Content as Panel).Children.Remove(_news_ctrl); if (old_Xaml_CanvasTemplate.Children.ContainsKey(child.Key)) { if (!old_Xaml_CanvasTemplate.Children[child.Key].Equals(child.Value)) { //-->删除原来的控件 this.DesignPage.DeleteChilren(child.Key); //-->2、增加新的控件 this.DesignPage.AddChild(_news_ctrl, !_IsOpenPage); DesignPage.UpdateDesignRectangle(_news_ctrl); old_Xaml_CanvasTemplate.Children[child.Key] = child.Value; } continue; } this.DesignPage.AddChild(_news_ctrl, !_IsOpenPage); old_Xaml_CanvasTemplate.Children.Add(child.Key, child.Value); //-->初始一下内容 if (_news_ctrl is ICompositeCtrl) { var ci = _IDesignFramework.GetControlInfoByControlName(_news_ctrl.Name); if (null == ci) { continue; } //-->查找 metadata 里 row里的信息 var ctrlMetaData = _IDesignFramework.GetMetaDataInfoByTableName(ci.MetaData); if (null == ctrlMetaData || null == ctrlMetaData.Item || 0 == ctrlMetaData.Item.Count) { continue; } //--> metaData Column var colXml = ctrlMetaData.Item.Where(p => p.column_name.Equals(ci.ColumnName)).GetFirst <MetaDataColumnInfo>(); if (null == colXml) { continue; } var _newCtrlMetaData = new MetaDataInfo(); _newCtrlMetaData.table_type = ctrlMetaData.table_type; _newCtrlMetaData.table_name = ctrlMetaData.table_name; _newCtrlMetaData.table_comment = ctrlMetaData.table_comment; _newCtrlMetaData.Item = new List <MetaDataColumnInfo>(); _newCtrlMetaData.Item.Add(colXml); CtrlPlatformCommandInfo ctrlCmd = new CtrlPlatformCommandInfo(); ctrlCmd.ControlInfo = ci; ctrlCmd.MetaDataInfo = _newCtrlMetaData; (_news_ctrl as ICompositeCtrl).InitTitle(ctrlCmd); } } //-->如果是高、宽改变了,得修改xml文件信息 this._XmlTemplate.BaseInfo.PageHeight = new_xamlTemplate.Height; this._XmlTemplate.BaseInfo.PageWidth = new_xamlTemplate.Width; _XamlTemplate.Height = new_xamlTemplate.Height; _XamlTemplate.Width = new_xamlTemplate.Width; Xml_Template = _XmlTemplate.ParseXml().ToString(); _XamlTemplate = new_xamlTemplate; this.Xaml_Template = changeXaml; DesignPage.UpdatePropertyGrid(); }
private XamlTypeConverter(Type type) { var underlyingType = Nullable.GetUnderlyingType(type) ?? type; _xamlTemplate = TypeTemplates.GetValueOrCreate(underlyingType, () => new XamlTemplate(underlyingType)); }