2011-12-28 5 views
2

私はICommand-Class ReadPersonsを定義しました。これは特定のwhere節を持つデータベースからすべてのpersonオブジェクトを読み込みます。ICommandにパラメータを渡すには?

ボタンを押してコマンドを実行していて、where句がテキストボックスに挿入されています。

質問:テキストボックスからテキストをExecute-Commandに渡すにはどうすればよいですか?

MainWindow.xaml:

<Button Command="{Binding ReadPersons}">Read persons</Button> 
    <TextBox Name="textBoxWhereClause" /> 

ReadPersons.cs:

public void Execute(object parameter) 
    { 
     // Read all persons with my where-clause 
     string whereClause = ??? //todo 
    } 

答えて

3

はいすることができます。

<Button Command="{Binding ReadPersons}" 
     CommandParameter="{Binding Text, ElementName=textBoxWhereClause}"> 
      Read persons</Button> 
+0

GOTCHA!どうもありがとうございました! – PeterP

+0

パラメータ値をキャッチするICommandメソッドには何が書き込まれますか? –

0
<Button Command="{Binding ReadPersons}" CommandParameter="{Binding SomeProperty}" Content="Read Persons"/> 
関連する問題