ソースxmlに書き戻すためにネストされたスタックパネルからテキストボックスにアクセスする方法を教えてください。ネストされたスタックパネルからデータを取得する
スタックパネルを表示しやすくするため、また結果を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-sharp-finding-controls-panel-inside-a-panel/17750097#17750097 – TripleD