WPF如何获取RadioButton Content的值
可以通过以下方式获取RadioButton控件的Content属性值:
-
通过控件名称获取RadioButton控件对象,例如:RadioButton radioButton = (RadioButton)FindName("radioButton1");
-
调用RadioButton控件的Content属性获取该控件的Content属性值,例如:string contentValue = radioButton.Content.ToString();
-
在XAML中绑定Content属性到ViewModel的属性,在ViewModel中获取Content属性值,例如:在XAML中绑定Content属性到ViewModel的属性:
在ViewModel中定义RadioButtonContent属性,并在需要使用Content属性值的地方获取该属性值,例如:
private string _radioButtonContent; public string RadioButtonContent { get { return _radioButtonContent; } set { _radioButtonContent = value; OnPropertyChanged("RadioButtonContent"); } }
// 在需要使用Content属性值的地方获取该属性值 string contentValue = RadioButtonContent;
原文地址: https://www.cveoy.top/t/topic/bpfS 著作权归作者所有。请勿转载和采集!