What is better to use? Instead of SelectionChanged use SelectedItem
private Game _SelectedItem; public Game SelectedItem { get { return _SelectedItem; } set { _SelectedItem = value; OnPropertyChanged(); System.Windows.MessageBox.Show(((Game)value).Creator); } } or so
<ListBox ItemsSource="{Binding Games}" Background="#FF292D32" HorizontalContentAlignment="Stretch"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding ItemChanged}" CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}}" /> </i:EventTrigger> </i:Interaction.Triggers>
Что лучше использовать?- what does it mean better? - tym32167OnPropertyChanged()in the setter is the norm. To call some UI things like a dialog box in the view model is not normal and is generally wrong. - tym32167 2:44<ListBox .... SelectedItem="{Binding SelectedItem}" ....2) Setters and getters for all recommendations should be as simple as possible, the simpler the better. If you start writing logic noodles in setters, get unsupported mess in the code 3) Write a special class to display windows, call this class from the model - tym32167