ComboBox
ユーザーの種類に応じて投資のリストを検索するために使用されるフォームをコントロールしたいと思います。起動時にデータベースから投資のコレクション全体 (現在 3,000 ほどの項目) をキャッシュすると、これを簡単に行うことができますが、必要でない場合はキャッシュしないことをお勧めします。
私が実装しようとしている動作は次のとおりです。
- ユーザーは、編集可能な ComboBox にテキストを入力します。
- ユーザーが各文字を入力すると、データベース検索機能がトリガーされ、連続するキーストロークごとに検索結果が絞り込まれます。
- 検索結果が更新されると、ドロップダウン パネルが開き、関連する一致が表示されます
のプロパティを myの(string) プロパティにバインドし、 のプロパティを myのText
( generic List ) プロパティにバインドしようとしました。これを行うと、プロパティは からオートコンプリートされますが、ドロップダウンは空に見えます。ComboBox
InvestmentName
ViewModel
ItemsSource
ComboBox
InvestmentList
ViewModel
Text
ItemsSource
TextBox
の上に積み重ねたを使用してこれらの結果を達成できましたListBox
が、あまりエレガントではなく、より多くの画面領域を占有します。有効な検索項目があるときにプロパティが「true」に設定されていると、 はフォーカスを盗みますが、 のTextBox
上に積み重ねて動作させることもできました。また、これに 2 つのコントロールを使用するのも視覚的にあまりよろしくありません。ComboBox
ComboBox
IsDropDownOpen
思い通りに機能するようになるのに本当に近づいているように感じますが、私を逃してしまうものがあります.
このコントロールの XAML は次のとおりです。
<ComboBox Height="23" Width="260" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left"
ItemsSource="{Binding InvestmentList}" DisplayMemberPath="FullName"
IsDropDownOpen="{Binding DoShowInvestmentList}"
ItemsPanel="{DynamicResource ItemsTemplate}" IsEditable="True"
Text="{Binding Path=InvestmentName, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
関連するViewModel
プロパティは次のとおりです。
private bool _doShowInvestmentList;
public bool DoShowInvestmentList
{
get { return _doShowInvestmentList; }
set { if (_doShowInvestmentList != value) { _doShowInvestmentList = value; RaisePropertyChanged("DoShowInvestmentList"); } }
}
private List<PFInvestment> _investmentList;
public List<PFInvestment> InvestmentList
{
get { return _investmentList; }
set { if (_investmentList != value) { _investmentList = value; RaisePropertyChanged("InvestmentList"); } }
}
private string _investmentName;
public string InvestmentName
{
get { return _investmentName; }
set
{
if (_investmentName != value)
{
_investmentName = value;
this.InvestmentList = DataAccess.SearchInvestmentsByName(value).ToList();
if (this.InvestmentList != null && this.InvestmentList.Count > 0)
this.DoShowInvestmentList = true;
else
this.DoShowInvestmentList = false;
RaisePropertyChanged("InvestmentName");
}
}
}
私はこれについてかなりの調査を行いましたが、まだ答えを見つけていません。