2011-03-16 11 views
1

私はwpf c#アプリケーションでこの編集可能なコンボボックスを持っています。ユーザーがドロップダウンリストを使用しているときに 'SelectionChanged'イベントを正しく使用できます。wpfの編集可能なコンボボックスの「送信」イベントですか?

しかし、ユーザーが入力ボックスに入力したテキストを「提出」すると、イベントを取得する方法がわかりません。私は 'TextInput'イベントを試しましたが、それは決して誘発されないようです(私はちょうどDebug.WriteLine("test");の関数を呼び出します)

私はPreviewTextInputを試しましたが、それは各文字に対してトリガされます。私はユーザーが望むものを入力し、Enterキーを押すか、コントロールをクリックするようなものを探しています。

アイデア?

答えて

1

Textプロパティを基になるDataContextにバインドします。

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication1"> 
    <Window.DataContext>        
    <local:Contact/> 
    </Window.DataContext> 
    <StackPanel> 
    <ComboBox Text="{Binding MyValue}" IsEditable="True"/> 
    <TextBlock Text="{Binding MyValue}"/> 
    </StackPanel> 
</Window> 

基礎となるオブジェクトを実装する必要がありINotifyPropertyChanged

public class Contact : INotifyPropertyChanged 
{ 
    private string _MyValue; 
    public string MyValue 
    { 
    get { return _MyValue; } 
    set 
    { 
     _MyValue = value; 
     if (PropertyChanged != null) 
     PropertyChanged(this, new PropertyChangedEventArgs("MyValue")); 
    } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 
} 
関連する問題