에서 항목 찾기하지만 난 그렇게 할 수있는 방법을 모르겠어요. 내 ObservableCollection에를 들어C#을 - 내가 <strong>ObservableCollection에</strong>를 사용하여 바인더 제본 한 내 <strong>목록 상자</strong>에 대한 <strong>"검색"</strong> 기능을 추가하기 위해 노력하고있어 ObservableCollection에
:
ObservableCollection<ItemProperties> ItemCollection { get; set; }
public class ItemProperties : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ItemProperties() { }
private string m_ID;
public string ID
{
get { return m_ID; }
set
{
m_ID = value;
OnPropertyChanged("ID");
}
}
private string m_Title;
public string Title
{
get { return m_Title; }
set
{
m_Title = value;
OnPropertyChanged("Title");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(name));
}
}
나는 목록 상자 내 항목을로드 :
string[] fileNames = isf.GetDirectoryNames("Files/*.*");
ItemCollection = new ObservableCollection<ItemProperties>();
foreach (var Directory in fileNames)
{
// code which reads and loads the text files to string which then is added to the Collection
}
ItemCollection.Add(new ItemProperties { ID = a_ID, Title = a_Title});
IEnumerable<ItemProperties> query = ItemCollection.OrderBy(Dat => Dat.Title);
listBox1.ItemsSource = query;
는 지금은 텍스트 상자를 할 수있는 버튼이 있습니다. TextBox가 활성화되어 있고 입력 할 때 listBox1은 입력 한 내용 만 표시해야합니다. 입력 한 내용이 존재하지 않으면 목록 상자에 항목이 표시되지 않아야합니다. 예컨대 : 어떻게 이렇게 그와 같은 기능을 할 수 있습니까? Windows Phone 앱 검색과 같아야합니다. (상황에 맞는 메뉴를 사용하여)
삭제 방법 : 내가 삭제 버튼을 클릭하면
var contextMenuOpenedIndex = listBox1.Items.IndexOf((sender as MenuItem).DataContext);
ItemCollection.RemoveAt(contextMenuOpenedIndex);
, 내가 정말 삭제하려는 하나를 유지하는 다른 항목을 삭제합니다.
내 머리 꼭대기에서 벗어나는 'TextBox'는 사용자가 입력 할 때마다 발생하는 '변경됨'이벤트와 유사합니다. 거기에 상자에 들어있는 내용으로 전체 목록을 필터링 할 수 있습니다. 입력 할 때 변경해야합니다. – Omada