0
你能够帮助我如何访问从嵌套堆栈面板的文本框写回到我的源xml。从嵌套堆栈面板Retreiving数据
我动态创建堆叠面板,因为它可以更容易地显示,因为结果可以是1行或50行。 这个源文件是一个已被反序列化的XML文件,但我只需要处理这个是Children [7]的1节,它总是固定的。
一旦写入到堆栈面板,用户可以调整文本框中的文本,然后我可以读回来并适当调整XML源。
这里是我如何填充stackpanels,但你可以看到有多个实例,那么多的StackPanel孩子:
XmlDoc = Deserialize();
if(XmlDoc != null)
{
var docWindow = new Window();
docWindow.Width = 900;
docWindow.Height = 600;
var stackPanelMain = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(10,10,10,10) };
stackPanelMain.Children.Add(new Label { Content = XmlDoc.Sections.Field.Children[7].Name, FontSize = 20 });
foreach(var value in XmlDoc.Sections.Field.Children[7].Instances)
{
var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
stackPanel.Children.Add(new Label { Content = value.Children[0].TextValue.Text });
var stackPanelFields = new StackPanel { Orientation = Orientation.Horizontal };
stackPanelFields.Children.Add(new TextBox { Width = 200, Height = 40, Text = value.Children[1].TextValue.Text});
stackPanelFields.Children.Add(new Image { Width = 200, Height = 40 }); // yet to be created
stackPanelFields.Children.Add(new TextBox { Width = 200, Height = 40, Text = string.Format("{0}/{1}/{2}", value.Children[2].TextValue.Text, value.Children[3].TextValue.Text, value.Children[4].TextValue.Text) });
stackPanelFields.Children.Add(new Image { Width = 200, Height = 40 }); //yet to be created
stackPanel.Children.Add(stackPanelFields);
stackPanelMain.Children.Add(stackPanel);
}
docWindow.Content = stackPanelMain;
}
在用户已经调整了文本我需要把它写回xml文件重复遍历所有文本框,然后开始写入值。 这是我卡在如何从所有的孩子访问所有的文本框,我一直在寻找这样的事情:
int xmlInstance = 0;
foreach (var tb in stackPanelMain.Children.OfType<TextBox>())
{
XmlDoc.Sections.Field.Children[7].Instances[xmlInstance].Children[1].TextValue.Text = tb.Text;
XmlDoc.Sections.Field.Children[7].Instances[xmlInstance].Children[1].TextValue.IsVerified = true;
xmlInstance++;
}
但是它只是对付1名儿童。
如何访问堆叠面板中的所有子文本框?或者的确,如果有更好的方式来显示和检索这些数据,我会非常欣赏一个指针。
在此先感谢。
想我可能已经找到了答案终于在这里,花了一些搜索,但这个工作对我来说:http://stackoverflow.com/questions/17745505/WPF-C-尖锐调查-控制 - 从面板的内-A-面板/ 17750097#17750097 – TripleD