繁体   English   中英

WPF 是否有保存单选按钮内容的方法,然后通过事件处理程序发送保存内容

[英]Does WPF have a way of saving radio button content and then sent the save content through a event handler

我想知道 WPF 是否可以保存单选按钮内容并使用事件处理程序将内容发送到文本文件。 我需要在事件处理程序中完成所有这些还是我可以调用某个类?

    public void method(){
string s = "Test1&Test2&Test3&Test4";

string[] s = Spliting.Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries);

List<RadioButton> radioButtonList = new List<RadioButton>();

        radioButtonList.Add(radioButton);
        radioButtonList.Add(radioButton1);

    for (int i = 0; i < radioButtonList.Count; i++)
{

//some code that insert string into the radio button (done)
//when i use streamwriter inside here, it give me this in the text file
//System.Windows.Controls.RadioButton Content IsChecked:False <- this can be turn to true if i put variable.Checked = true
}

private void radioButton_Checked(object sender, RoutedEventArgs e)
    {

        if (radioButton.IsChecked == true)
        {
            StreamWriter streamwriters = new StreamWriter ("Sent.txt", false);
            streamwriters.Close();
        }
        else if (radioButton1.IsChecked == true)
        {
            StreamWriter streamwriters = new StreamWriter("Sent.txt", false);
            streamwriters.Close();
        }

或者WPF有一个方法可以自动将内容保存到变量中。 我错过了什么吗?

我希望单选按钮检查单选按钮并将内容发送到文本文件中。

如果您只想将使用单选按钮显示的文本保存到文件中,则:

private void radioButton1_Checked(object sender, EventArgs e)
{
    string radioButtonContent = ((RadioButton)sender).Text;
    string savePath = @"C:\sent.txt"; // or wherever

    File.WriteAllText(savePath, radioButtonContent);
}

暂无
暂无

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

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