使用应用程序属性将文本框字符串传递给自定义控

时间:2012-04-17 16:41:55

标签: c# wpf custom-controls

如果我使用它将

我的主窗口传递给我的自定义控件,那么我将如何在自定义控件中捕获它?

    private void btnGeneral_Click(object sender, RoutedEventArgs e)
    {
        string myText = (string)Application.Current.Properties[textBox1.Text];
    }

1 个答案:

答案 0 :(得分:1)

你是怎么做到的:

//To Set:    
App.Current.Properties["TextBoxString"] = textBox1.Text;
//To Get:
string myProperty = (string) App.Current.Properties["TextBoxString"];

查看本文Accessing the Application object in a WPF application