MVVM 모델을 따르고있는 WPF 응용 프로그램을 개발 중입니다. observable 컬렉션을 필터링하려고하는데이 메서드는 값을 반환하지 않습니다. public void UpdatePopList(), is 이 코드는 올바른 방법으로 작성되었거나 수정이 필요하며 데이터를 필터링하는 다른 방법이 있습니까?관찰 할 수있는 컬렉션 필터 WPF 및 다른 방법으로 필터하려면
private string selectmu;
public string Selectmu
{
get
{
return selectmu;
}
set
{
selectmu = value;
RaisePropertyChanged("Selectmu");
}
}
private ObservableCollection<CREntity> _CRmappings2 = new ObservableCollection<CREntity>();
public List<CREntity> CRPopentities
{
get;
set;
}
// Obeservable collection property for access
public ObservableCollection<CREntity> CRmappings2
{
get { return _CRmappings2; }
set
{
_CRmappings2 = value;
RaisePropertyChanged("CRmappings2");
}
}
public void UpdatePopList()
{
CRPopentities = CRPopentities.Where(p => p.MU_Identifier == selectmu).ToList();
}
}
이 UI를 바인딩 코드
<md:PopupBox.ToggleContent>
<md:PackIcon Kind="DotsHorizontal" Margin="4 0 4 0" Width="24" Height="24"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=md:PopupBox}, Path=Foreground}" />
</md:PopupBox.ToggleContent>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Opened">
<command:EventToCommand Command="{Binding DataContext.popSW, RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding MU_Identifier}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!--<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ElementName=CRDataGrid, Path= SelectedItem.MU_Identifier}" />-->
<DataGrid x:Name="dataGrid1" Grid.Column="1" Grid.Row="2" AutoGenerateColumns="False" ItemsSource="{Binding Path=CRPopentities, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Software Versions" Binding="{Binding Path=SW_Version}" ></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</md:PopupBox>
난 당신이 'CRmappings2'를 바인더 제본 있지만 엔티티 클래스를 필터링하는 UI에서 생각하는 데 도움이됩니다. 필터링해야하는 ObservableCollection이어야합니까? – Eldho
@ Eldho 네가 옳았다. 나는 이것을 관찰 할 수있는 콜렉션을 필터링하기 위해 이것을 바꿨다. CRPopentities = CRmappings2.Where (p => p.MU_Identifier == selectmu) .ToList(); --- 쿼리 당 여러 레코드가 맞아야합니까? ToList()를 사용하기 때문에 단일 레코드 만 반환합니다. –
나는 그것이'MU_Identifier'를 가진 다중 레코드를 포함하지 않는다고 생각한다. ToList()가 정확합니다. 디버깅 할 수 있습니다. – Eldho