2つのコンボボックスの基準で研究していますが、うまくいきます。 私はボタンを表示しています:ComboboxとDataGridをクリアすると、すべての要素が再び表示されます。WPFで検索後にComboBoxをクリアしますか?
問題は、Button Dispaly AllをクリックするとComboboxが空でなければならないということです。最初の2つのテストは正しいです(Comboboxは空で、DataGridはすべての要素を表示します)。 2つのコンボボックスのリストが空です!
1)コンボボックスの要素(単にdispalyデータグリッド)を選択しなければ:私はデータグリッド内の6つの要素を持っているが、それはcorrect..andされるコンボボックスが空である:enter image description here
2) は後に検索を選択します(コンボボックスの2つの要素を選択)、結果は正しい:(例:3つの結果しかないが、正しい動作)
3) 2つのテストの後にボタンをクリックすると正しい):コンボボックスのリストが空です! : enter image description here
XAML:
<Window x:Class="WPFAuthentification.Views.BusinesseventsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >
<Label Content="Entity Type" />
<ComboBox Name="comboCodeType"
ItemsSource="{Binding EntityLevelEnum}"
SelectedItem="{Binding EntityType, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, TargetNullValue=''}"
/>
<Label Content="Criticality" />
<ComboBox Name="comboType"
ItemsSource="{Binding LevelCriticalityEnum}"
SelectedItem="{Binding Criticality, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, TargetNullValue=''}" />
<Button Content="Dislplay all" ToolTip="Display All Business Events"
VerticalAlignment="Top" Command="{Binding Initialize}" />
<DataGrid Name="businesseventsalarms"
ItemsSource="{Binding BusinessEventsList}" SelectedItem="{Binding SelectedBusinessevent}" ... >
</Window>
のViewModel:
public BusinesseventsViewModel()
{
businessEventsList = new ObservableCollection<BusinessEventClass>(WCFclient.getAllBusinessEvent());
levelCriticalityEnum = new ObservableCollection<Level_Criticality>(Enum.GetValues(typeof(Level_Criticality)).Cast<Level_Criticality>());
entityLevelEnum = new ObservableCollection<BusinessEntityLevel>(Enum.GetValues(typeof(BusinessEntityLevel)).Cast<BusinessEntityLevel>());
//Function of Button Display All
initialize = new RelayCommand<string>(initFunc);
}
private void initFunc(object obj)
{
entityLevelEnum.Clear();
levelCriticalityEnum.Clear();
OnPropertyChanged("EntityLevelEnum");
OnPropertyChanged("LevelCriticalityEnum");
}
private string entityType;
public string EntityType
{
get { return entityType; }
set
{
entityType = value;
businessEventsList = filterByCriteria(entityType, criticality);
OnPropertyChanged("BusinessEventsList");
OnPropertyChanged("EntityType");
}
}
private string criticality;
public string Criticality
{
get { return criticality; }
set
{
criticality = value;
businessEventsList = filterByCriteria(entityType, criticality);
OnPropertyChanged("BusinessEventsList");
OnPropertyChanged("Criticality");
}
}
public ObservableCollection<BusinessEventClass> filterByCriteria(string entityType, string criticality)
{
BusinessEventsList = new ObservableCollection<BusinessEventClass>(WCFclient.getAllBusinessEvent());
ObservableCollection<BusinessEventClass> updatedList = new ObservableCollection<BusinessEventClass>();
if ((entityType != null && entityType != "") && (Criticality != null))
{
updatedList = new ObservableCollection<BusinessEventClass>(BusinessEventsList.Where(a => a.EntityType.ToString().ToLower().Equals(criticality)
&& a.Critciality.ToString().Equals(criticality));
}
return updatedList;
}
}
//List of all BusinessEvents
public ObservableCollection<BusinessEventClass> BusinessEventsList
{
get { return businessEventsList; }
set
{
businessEventsList = value;
OnPropertyChanged("BusinessEventsList");
}
}
//List of LevelCriticalityEnum
private ObservableCollection<Level_Criticality> levelCriticalityEnum;
public ObservableCollection<Level_Criticality> LevelCriticalityEnum
{
get { return levelCriticalityEnum; }
set
{
levelCriticalityEnum = value;
OnPropertyChanged("TypeEnum");
}
}
//List of EntityLevelEnum
private ObservableCollection<BusinessEntityLevel> entityLevelEnum;
public ObservableCollection<BusinessEntityLevel> EntityLevelEnum
{
get { return entityLevelEnum; }
set
{
entityLevelEnum = value;
OnPropertyChanged("TypeEnum");
}
}