2012-04-17 6 views
1

これを使用して文字列から私のカスタムコントロールに渡すと、カスタムコントロールでどのようにキャプチャできますか?あなたがそれを行う方法アプリケーションのプロパティを使用してテキストボックスの文字列をカスタムコントロールに渡す

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

答えて

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

+0

のため、この記事をチェックアウトが、私は 'App.Current.Properties [ "TextBoxString"] = textBox1.Textを置けば;' 私のメインウィンドウの私のボタンの 'myProperty = App.Current.Properties [" TextBoxString "];'私のカスタムコントロールでは暗黙のうちにオブジェクトを文字列に変換できないと言っていますか? –

+1

@KirstyWhiteが答えを編集したばかりです。myPropertyに割り当てる前に、文字列にキャストする必要があります – Habib

関連する問題