所以,我在XAML中有两个按钮:
<Button x:Name="but1" />
<Button Click="button_Click" Tag="but1" />
我希望在按下第二个按钮时找到第一个按钮并将其添加到ListBox中,如下所示:
private void button_Click(object sender, RoutedEventArgs e)
{
//this is only how I imagine this to be
string buttonName = (sender as Button).Tag.ToString();
Button findedButton = Find(buttonName);
ListBox1.Items.Add(findedButton);
}
答案 0 :(得分:0)
object item = LayoutRoot.FindName(buttonName);
if(item is Button)
{
Button btn=(Button)item;
}