我有过
<Button>
<Grid>
<TextBlock/>
<Image/>
</Grid>
</Button>我可以使用以下命令访问按钮名称
tbUserSelection.Text = ((Button)sender).Name;是否也可以通过这种方式访问文本块的文本?
谢谢
菲利普
发布于 2020-11-20 00:19:33
你可以在Grid的Children集合中找到它:
Button button = (Button)sender;
TextBlock textBlock = (button.Content as Grid)?.Children.OfType<TextBlock>().FirstOrDefault();发布于 2020-11-20 00:13:15
只需指定Name或x:Name并使用它。
https://stackoverflow.com/questions/64915543
复制相似问题