Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在网格中有一个控件,并且想访问该网格。我无法访问后面代码中的网格,但我可以访问控件的实例。有没有办法使用控件的实例获取网格父级?
假设您的控件是 Grid 中的一个按钮,并且您通过 click 事件访问此 Button,这就是您访问 Grid 的方式。
private void button1_Click(object sender, RoutedEventArgs e) { Grid x = (sender as Button).Parent as Grid; }