Kay*_*Lee 5 c# wpf button textblock
aTextBlock在 aButton里面content。
我想要Text的财产TextBlock。请告知我如何解决这个问题。
下面的代码仅返回ct为System.Windows.Controls.TextBlock
string ct = (sender as Button).Content.ToString();
Run Code Online (Sandbox Code Playgroud)
当然,这Content确实Button是TextBlock System.Windows.Controls.TextBlock
我在 stackoverflow 中发现的非常相似的案例,但人们只提供了错误的答案。
由于您应该考虑使用该属性,Content如下所示:ButtonTextBlock(sender as Button).ContentTextBlockText
string ct = ((sender as Button).Content as TextBlock).Text;
Run Code Online (Sandbox Code Playgroud)