在 WPF 中,你可以使用'RadioButton'控件的'IsChecked'属性来判断哪个'RadioButton'被选中。以下是在'MainWindow.xaml.cs'代码中获取选中的'RadioButton'控件的示例:

首先,确保你已经在'MainWindow.xaml.cs'代码文件中导入以下命名空间:

using System.Windows.Controls;

然后,在代码中你可以通过检查'RadioButton'对象的'IsChecked'属性来确定哪个'RadioButton'被选中。假设你有两个'RadioButton'控件,分别命名为'radioButton1'和'radioButton2',可以按照以下方式获取选中的'RadioButton'控件:

// 判断 radioButton1 是否被选中
if (radioButton1.IsChecked == true)
{
    // radioButton1 被选中
}

// 判断 radioButton2 是否被选中
if (radioButton2.IsChecked == true)
{
    // radioButton2 被选中
}

通过检查'IsChecked'属性,如果其值为'true'表示'RadioButton'被选中,你可以在相应的条件语句中执行特定的操作。

请根据你的实际情况使用适当的'RadioButton'控件名称和条件语句。

这样,你就可以在'MainWindow.xaml.cs'代码中判断哪个'RadioButton'控件被选中了。

WPF 如何获取选中的 RadioButton 控件

原文地址: https://www.cveoy.top/t/topic/B4F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录