0
如何從mvvm light wpf的listview中獲取selecteditem?MVVM light listview selecteditem
我有一個集合,並創建了一個選定的項目屬性,但我無法獲得所選項目的綁定權限。
這是我的視圖模型:
ObservableCollection<DTO.Dossier.Dossier> _dossiers;
public ObservableCollection<DTO.Dossier.Dossier> Dossiers
{
get { return _dossiers; }
set
{
_dossiers = value;
RaisePropertyChanged("Dossiers");
}
}
private DTO.Dossier.Dossier _selectedDossier;
public DTO.Dossier.Dossier SelectedDossier
{
get { return _selectedDossier; }
set
{
if (_selectedDossier != value)
_selectedDossier = value;
RaisePropertyChanged("SelectedDossier");
}
}
這是爲ListView的XAML:
<ListView ItemsSource="{Binding Dossiers}" Margin="0,5,0,0" Name="LstDossiers" SelectedItem="{Binding SelectedDossier, Mode=OneWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding SelectDossierCommand}"
CommandParameter="{Binding SelectedDossier,
ElementName=LstDossiers}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.View>
<GridView>
<GridViewColumn Header="Id"
DisplayMemberBinding="{Binding Id}" />
<GridViewColumn Header="Omschrijving"
DisplayMemberBinding="{Binding Omschrijving}" />
</GridView>
</ListView.View>
</ListView>
該命令工作,但到SelectedDossier綁定是不是。
更改BindingMode到雙向! – Jawahar
Off course ..謝謝Mr Lovalova :) – Kaizer