/// <summary> /// 对模板进行构造。 /// </summary> /// <param name="args"></param> public void Construct(InstanceArgs args) { if (args == null) { return; } this.args = args; Items.Clear(); Caption = args.caption; itemlist = new object[args.items.Count]; DeleteButton.Visibility = args.deleteable ? Visibility.Visible : Visibility.Collapsed; SaveButton.Visibility = args.onlywrite ? Visibility.Visible : Visibility.Collapsed; ConstructCustomButton(); for (int i = 0; i < args.items.Count; ++i) { var cachei = i; var thi = args.items[i]; if (thi.type == "text") { var item = new HeaderSuperText(); item.Header = thi.header; item.Editable = args.onlywrite ? EditAbleStatus.Writeonly : thi.editable; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; Items.Add(item); item.Submit += (s, e) => { var data = $@"{{ ""{args.items[cachei].name}"":""{e.text}"" }}"; Task.Run(() => { var res = args.api[args.url][args.instance].Update(data); if (!res.statuslike("2**")) { NavigatorPage.MsgSystem.Show((sr, er) => { }, "发生错误", res.content, Visibility.Hidden, new string[] { "确认" }); Dispatcher.Invoke(() => (s as Utils.HeaderSuperText).Text = ""); } }); return(e.text); }; } else if (thi.type == "multitext") { var item = new HeaderSuperText(); item.Header = thi.header; item.Editable = args.onlywrite ? EditAbleStatus.Writeonly : thi.editable; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; item.Multiable = true; itemlist[i] = item; Items.Add(item); item.Submit += (s, e) => { var data = $@"{{ ""{args.items[cachei].name}"":""{(s as HeaderSuperText).toJsonString()}"" }}"; Task.Run(() => { var res = args.api[args.url][args.instance].Update(data); if (!res.statuslike("2**")) { NavigatorPage.MsgSystem.Show((sr, er) => { }, "发生错误", res.content, Visibility.Hidden, new string[] { "确认" }); Dispatcher.Invoke(() => (s as Utils.HeaderSuperText).Text = ""); } }); return(e.text); }; } else if (thi.type == "choice") { var item = new HeaderSuperChoice(); item.Header = thi.header; item.Editable = args.onlywrite ? EditAbleStatus.Writeonly : thi.editable; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; item.Choices = thi.data as KeyValuePair <string, string>[]; Items.Add(item); item.Submit += (s, e) => { var data = $@"{{ ""{args.items[cachei].name}"":""{e.key}"" }}"; Task.Run(() => { var res = args.api[args.url][args.instance].Update(data); if (!res.statuslike("2**")) { NavigatorPage.MsgSystem.Show((sr, er) => { }, "发生错误", res.content, Visibility.Hidden, new string[] { "确认" }); Dispatcher.Invoke(() => (s as Utils.HeaderSuperChoice).SelectedIndex = -1); } }); return(e.selected); }; } else if (thi.type == "multi") { var item = new HeaderSuperMultiChoice(); item.Header = thi.header; item.Editable = args.onlywrite ? EditAbleStatus.Writeonly : thi.editable; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; item.ItemSource = thi.data as KeyValuePair <string, string>[]; Items.Add(item); item.Submit += (s, e) => { var data = $@"{{ ""{args.items[cachei].name}"":""{(s as HeaderSuperMultiChoice).toJsonString()}"" }}"; Task.Run(() => { var res = args.api[args.url][args.instance].Update(data); if (!res.statuslike("2**")) { NavigatorPage.MsgSystem.Show((sr, er) => { }, "发生错误", res.content, Visibility.Hidden, new string[] { "确认" }); Dispatcher.Invoke(() => (s as Utils.HeaderSuperMultiChoice).ClearContent()); } }); return(e.value); }; } } }
/// <summary> /// 对UI进行构造。 /// </summary> /// <param name="args"></param> public void Construct(CreateArgs args) { if (args == null) { return; } this.args = args; Items.Clear(); itemlist = new object[args.items.Count]; for (int i = 0; i < args.items.Count; ++i) { var cachei = i; var thi = args.items[i]; if (thi.type == "text") { var item = new HeaderSuperText(); item.Header = thi.header; item.Editable = EditAbleStatus.Writeonly; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; Items.Add(item); } else if (thi.type == "choice") { var item = new HeaderSuperChoice(); item.Header = thi.header; item.Editable = EditAbleStatus.Writeonly; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; item.Choices = thi.data as KeyValuePair <string, string>[]; Items.Add(item); } else if (thi.type == "multi") { var item = new HeaderSuperMultiChoice(); item.Header = thi.header; item.Editable = EditAbleStatus.Writeonly; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; item.ItemSource = thi.data as KeyValuePair <string, string>[]; Items.Add(item); } else if (thi.type == "multitext") { var item = new HeaderSuperText(); item.Header = thi.header; item.Multiable = true; item.Editable = EditAbleStatus.Writeonly; item.ColumnWidth = thi.columnwidth ?? args.columnwidth; item.AllFontSize = thi.fontsize ?? args.fontsize; item.Margin = thi.margin ?? args.margin; itemlist[i] = item; Items.Add(item); } } }