ここでは、MVVMフレームワークの代替案があります。
私のXAMLファイル:
<ComboBox Name="cmbContains" IsEditable="True" IsTextSearchEnabled="false" ItemsSource="{Binding pData}" DisplayMemberPath="wTitle" Text="{Binding SearchText ,Mode=TwoWay}" >
<ComboBox.Triggers>
<EventTrigger RoutedEvent="TextBoxBase.TextChanged">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsDropDownOpen">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ComboBox.Triggers>
</ComboBox>
私のCSファイル:
//ItemsSource - pData
//There is a string attribute - wTitle included in the fooClass (DisplayMemberPath)
private ObservableCollection<fooClass> __pData;
public ObservableCollection<fooClass> pData {
get { return __pData; }
set { Set(() => pData, ref __pData, value);
RaisePropertyChanged("pData");
}
}
private string _SearchText;
public string SearchText {
get { return this._SearchText; }
set {
this._SearchText = value;
RaisePropertyChanged("SearchText");
//Update your ItemsSource here with Linq
pData = new ObservableCollection<fooClass>{pData.ToList().Where(.....)};
}
}
あなたはTextChangedイベントは、ドロップがダウンがあったら、編集可能なコンボボックスが文字列(検索テキスト) に結合されて見ることができます双方向バインディングが値を更新します。 セット{}に入る間に、ItemsSourceがcsファイルで変更されました。構文。
A gist with the code above
これは優れています。私は投票していませんでした。あなたの答えはMeta http://meta.stackoverflow.com/questions/327540/was-my-edit-removing-noise-and-a-link-wrongについて話されていますので、たくさんの人が訪れるようになります。 – JRSofty