简体   繁体   English

如何获取选中按钮的内容

[英]How to get the content of the selected button

I am looking for a JavaScript equivalent我正在寻找一个 JavaScript 等价物

document.getElementById("Button").innerHTML

in C # WPF.在 C# WPF 中。

I need to get button content by x:Name我需要通过 x:Name 获取按钮内容

You can do this in the code behind (eg myView.xaml.cs ) of your xaml (eg myView.xaml ) file.您可以在 xaml(例如myView.xaml )文件的后面代码(例如myView.xaml.cs )中执行此操作。

Something like this像这样的东西

string text = Button1.Content.ToString();

Welcome to SO.欢迎来到 SO。

If the button is an element on the page and has the name "myButton" then you can access its content from within the parent class as myButton.Content .如果按钮是页面上的一个元素并且名称为“myButton”,那么您可以从父类中以myButton.Content访问其内容。

我想这就是你要找的:

string buttonContent = ((Button)FindName("Button1"))?.Content.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM