我想通过 Foreach 创建许多按钮,这些按钮打印 Uri 的属性。但我不知道该怎么做。你能告诉我怎么做吗?这是我的代码:
private void CreateButtons()
{
Uri uri = new Uri("/Pages/PageTest.xaml?Name=Stephen&Age=17",UriKind.Relative);
foreach(var pi in typeof(Uri).GetProperties())
{
//create button
Button btn = new Button();
btn.Content = pi.Name;
btn.Margin = new Thickness(0,0,0,12);
//i think this is bug, but i don't know,how to do
btn.Click += (se,ev)=>
{
MessageBox.Show(pi.GetValue(btn,null).ToString());
}
stackPanel.Children.Add(btn);
}
}