0
Listbox에 제품 정보를 표시하는 프로그램을 작성 중입니다. ProductName을 입력 할 때 자동으로 목록을 필터링하는 검색 용 텍스트 상자가 있습니다. 내 C# 코드를 여러 번 실행하고 실제로 필터를 볼 수 있지만 시각적으로 필터 또는 '새로 고침'화면에 가져올 수 없습니다.필터링하는 동안 목록 상자 항목이 업데이트되지 않는 이유는 무엇입니까?
C# 코드 :
private ICollectionView _ProductInfoView;
public ICollectionView ProductInfoView
{
get{return this._ProductInfoView;}
set
{
this._ProductInfoView=value;
this.onPropertyChnage("ProductInfoView");
}
}
private void RibbonSetupProduct_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.hidePanels();
new Task(() =>
{
this.Dispatcher.Invoke(new Action(() =>
{
ObservableCollection<ModelProductInformation> productInfoCollection = new ObservableCollection<ModelProductInformation>(from ProductInfo in new GTS_ERPEntities().ProductInformations select new ModelProductInformation { ProductID = ProductInfo.ProductID, ProductName = ProductInfo.ProductName , Remark=ProductInfo.Remark});
this.ProductInfoView = CollectionViewSource.GetDefaultView(productInfoCollection);
new ProductInfoSearch(ProductInfoView, this.TestTextBox);
}
), DispatcherPriority.DataBind);
}
).Start();
this.PanelProducts.Visibility = Visibility.Visible;
}
class ProductInfoSearch
{
public ProductInfoSearch(ICollectionView filteredList, TextBox textEdit)
{
string filterText = string.Empty;
filteredList.Filter = delegate(object obj)
{
if (String.IsNullOrEmpty(filterText))
{
return true;
}
ModelProductInformation str = obj as ModelProductInformation;
if (str.ProductName==null)
{
return true;
}
if (str.ProductName.ToUpper().Contains(filterText.ToUpper()))
{
return true;
}
else
{
return false;
}
};
textEdit.TextChanged += delegate
{
filterText = textEdit.Text;
filteredList.Refresh();
};
}
}
XAML :
<dxe:ListBoxEdit x:Name="ProductInfoList" Margin="1.666,1,8,8" Grid.Column="2" Grid.Row="2" Grid.RowSpan="5" DisplayMember="ProductName" DataContext="{Binding ProductInfoView, ElementName=window}" ItemsSource="{Binding}"/>
나는 내 문제 중 하나를 데이터 바인딩 또는 작업() 안의 것 같다.
작업 항목을 제거했지만 여전히 작동하지 않습니다. 다른 해결책이 있습니다. –
인스턴스 생성을 한 번 시도하고 productInfoCollection을 클래스 멤버로 시도 했습니까? 과거에 productInfoCollection에서했던 것처럼 ICollection에서 로컬 변수를 사용할 때 몇 가지 문제가있었습니다. – blindmeis
내 문제가 해결되었습니다. 목록 상자에 문제가 있습니다. Developer Express ListBoxEdit을 사용했습니다. 그것은 작동하지 않습니다. 나는 이유를 모른다. 이제 ListBox를 사용하여 잘 작동하고 답변도 정확합니다. 고맙습니다. –