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