SeiveList という名前の ObservableCollection があります。リストからすべての SeiveIdSize を取得し (最後のものは役に立たないため)、Combobox の DataContext を設定します。追加した
seiveCmb.DataContext = GlobalUtils.SeiveList;
seiveCmb.DisplayMemberPath = // WHAT SHOULD GO HERE. hOW TO ONLY SHOW SeiveIdSize
// XML
<ComboBox Name="seiveCmb" ItemsSource="{Binding}" Grid.Column="1" Grid.Row="1" Margin="2" SelectedIndex="0" ></ComboBox>
セバスチャンの提案に従って編集:現在、コンボボックスのリストを試してみました。私のSeiveクラス:
public class Seive : INotifyPropertyChanged
{
// Other Members
private bool isSelected;
public bool IsSelected
{
get { return isSelected; }
set
{
isSelected = value;
OnPropertyChanged("IsSelected");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string p)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(p));
}
}
私の Window .xaml ファイルで:
<Window.Resources>
<CollectionViewSource Source="{Binding Path=comboSeives}"
x:Key="comboSeivesFiltered"
Filter="ComboSeiveFilter">
</CollectionViewSource>
</Window.Resources>
<ComboBox Name="seiveCmb" ItemsSource="{Binding Source={StaticResource comboSeivesFiltered}}" DisplayMemberPath="SeiveIdSize"
Grid.Column="1" Grid.Row="1" Margin="2" SelectedIndex="0"
></ComboBox>
ウィンドウ内.csファイル:
public ObservableCollection<Seive> comboSeives { get; set; }
// Initial original data in Window_Loaded method
comboSeives = GlobalUtils.SeiveList;
public void ComboSeiveFilter(object sender, FilterEventArgs e)
{
Seive sv = e.Item as Seive;
// Add items those is != "TOTAL" and isSelected == false
if (sv.SeiveIdSize != "TOTAL" && sv.IsSelected == false)
e.Accepted = true;
else
e.Accepted = false;
}
ID が "TOTAL" の場合、または isSelected が false (つまり、グリッドに追加されていない) の場合、true のみが返され、グリッドに追加されます。初期のすべてのレコードは isSelected = false です。
これは、このサイトの説明とヘルプから私が理解したことです。これを実装しました。しかし、ランタイムでは、コンボボックスに何も表示されません。フィルターメソッドにブレークを追加してデバッグしようとしましたが、そこに到達することはありません。上記のコードからどこが間違っているか指摘していただけますか。
どんな助けも感謝しています。
ありがとう