0
我有兩個combobox的標準研究,它工作正常。 我有一個按鈕顯示全部:清除組合框和數據網格顯示所有元素。在WPF中搜索後清除組合框?
問題是:當我單擊Button Dispaly All時,組合框必須是空的,前兩個測試是正確的(Combobox是空的,並且Datagrid顯示所有元素),之後... I有兩個Combobox列表是空的!
1)在不選擇在組合框(元件只是dispaly數據網格):我在數據網格6層的元件,它被correct..and組合框爲空:enter image description here
2) 選擇搜索後條件(選擇Combobox中的兩個元素),我得到的結果是正確的:(例如:我只有3個結果,它是正確的動作)
3) 當我點擊Display All按鈕時正確):Combobox中的列表爲空! : 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>
視圖模型:
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");
}
}