1

Topic: WPF - Why works without OnPropertyChanged?

I understand with WPF XAML: <ListBox Name = "lstLog" runManager:ListBoxExtenders.AutoScrollToCurrentItem= "True" IsSynchronizedWithCurrentItem = "True" ItemsSource = "{Binding MemLogEvents}"/> ViewModel very simple private ObservableCollection <string> _memLogEvents; public ObservableCollection <string> MemLogEvents {get {return _memLogEvents;} set {_memLogEvents = value; OnPropertyChanged (nameof (MemLogEvents));}}//.... Some code here private void GetMemLogEvent (object sender, MemLogEventArgs eventArgs) {MemLogEvents. Add (eventArgs.Log); OnPropertyChanged (nameof (MemLogEvents));} GetMemLogEvent All is caused on  a new line in a broad gull works, but there are two questions: - From a setter method OnPropertyChanged is never caused,  I understand. Assignment there goes only time. From GetMemLogEvent the same method is caused permanently. If to remove OnPropertyChanged from everywhere broad gulls and continue to appear in ListBox. Whence ListBox takes the notification message about  contents? - How to adjust, that ListBox the automatic machine  down to an emphasis? I tried to use Extender for ListBox that found, but is ineffectual. Thanks!... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

2

Re: WPF - Why works without OnPropertyChanged?

Hello, RainBoy, you wrote: RB> - From a setter method OnPropertyChanged is never caused,  I understand. Assignment there goes only time. From GetMemLogEvent the same method is caused permanently. If to remove OnPropertyChanged from everywhere broad gulls and continue to appear in ListBox. Whence ListBox takes the notification message about  contents? Because OnPropertyChanged does not concern adding/removal of elements. In it is engaged INotifyCollectionChanged, which  in ObservableCollection RB> - How to adjust, that ListBox the automatic machine  down to an emphasis? I tried to use Extender for ListBox that found, but is ineffectual. I would try to cause ScrollIntoView when it is necessary.

3

Re: WPF - Why works without OnPropertyChanged?

Hello, vmpire, you wrote: V> Because OnPropertyChanged does not concern adding/removal of elements. In it is engaged INotifyCollectionChanged which  in ObservableCollection I changed ObservableCollection on normal List which does not implement INotifyCollectionChanged - the same result, all works. V> I would try to cause ScrollIntoView when it is necessary. Thanks, I will look... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

4

Re: WPF - Why works without OnPropertyChanged?

Hello, RainBoy, you wrote: RB> I changed ObservableCollection on normal List which does not implement INotifyCollectionChanged - the same result, all works. And thus did not cause OnPropertyChanged (nameof (MemLogEvents)) and all worked? Then I do not know

5

Re: WPF - Why works without OnPropertyChanged?

V> And thus did not cause OnPropertyChanged (nameof (MemLogEvents)) and all worked? Then I do not know Is not present, did not cause.... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

6

Re: WPF - Why works without OnPropertyChanged?

Hello, RainBoy, you wrote: RB> - From a setter method OnPropertyChanged is never caused,  I understand. Assignment there goes only time. From GetMemLogEvent the same method is caused permanently. If to remove OnPropertyChanged from everywhere broad gulls and continue to appear in ListBox. Whence ListBox takes the notification message about  contents? ItemsSource = "{Binding MemLogEvents}" ListBox it is anchored to field MemLogEvents of yours ViewModel, instead of to a copy of object ViewModel. Therefore at element adding in it (MemLogEvents), there "inside ObservableCollection" works the OnPropertyChanged which leads to update ListBox. Such version goes?

7

Re: WPF - Why works without OnPropertyChanged?

L> ListBox it is anchored to field MemLogEvents of yours ViewModel, instead of to a copy of object ViewModel. Therefore at element adding in it (MemLogEvents), there "inside ObservableCollection" works the OnPropertyChanged which leads to update ListBox. Such version goes? Not absolutely I understand, where it "there inside". And if to change Observable on normal List <> all continues to work. I only understand, for me it is not clear.... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

8

Re: WPF - Why works without OnPropertyChanged?

Hello, RainBoy, you wrote: RB> - From a setter method OnPropertyChanged is never caused,  I understand. Assignment there goes only time. From GetMemLogEvent the same method is caused permanently. If to remove OnPropertyChanged from everywhere broad gulls and continue to appear in ListBox. Whence ListBox takes the notification message about  contents? About ObservableCollection already explained, and about List <T> it is trusted hardly. Here it is better to throw the full source codes with an example. RB> - how to adjust, that ListBox the automatic machine  down to an emphasis? I tried to use Extender for ListBox that found, but is ineffectual. Binding in WPF does not work with lists directly, and uses abstraction ICollectionView. Under a cowl everyone  the collection receives the collection view. It can be requested, causing GetDefaultView. With the help collection view it is possible to control UI the list from view model without a binding to specific type . For this purpose it is necessary to install CurrentItem, using any of methods MoveCurrentTo*. In your case like approaches MoveCurrentToLast. However, I advise, if it is necessary explicit control of a current element, it is necessary to do at once property with type ICollectionView, and in model to envelop List through ListCollectionView.

9

Re: WPF - Why works without OnPropertyChanged?

Hello, MxMsk, you wrote: MM> Hello, RainBoy, you wrote: RB>> it is constant. If to remove OnPropertyChanged from everywhere broad gulls and continue to appear in ListBox. Whence ListBox takes the notification message about  contents? MM> about ObservableCollection already explained, and about List <T> it is trusted hardly. Here it is better to throw the full source codes with an example. <Window x:Class = "ICC.RunManager. MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006 … esentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" xmlns:esri = "http://schemas.esri.com/arcgis/runtime/2013" xmlns:local = "clr-namespace:ICC.RunManager. Classes" xmlns:mc = "http://schemas.openxmlformats.org/marku … ility/2006" xmlns:runManager = "clr-namespace:ICC.RunManager. Classes" xmlns:viewModels = "clr-namespace:ICC.RunManager. ViewModels" Title = "ICC Run Manager" Width = "880" Height = "600" mc:Ignorable = "d"> <Window. DataContext> <! - datacontext assigned to the new instance of MainWindowViewModel-> <viewModels:MainWindowViewModel x:Name = "mainWindowViewModel"/> </Window. DataContext> <DockPanel LastChildFill = "True"> <Menu Name = "mnuMain" DockPanel. Dock = "Top"> <MenuItem Name = "menuItemFile" Header = "File"/> <MenuItem Name = "menuItemView" Header = "View"/> <MenuItem Name = "menuItemEdit" Header = "Edit"/> <MenuItem Name = "menuItemHelp" Header = "Help"/> </Menu> <ToolBar Height = "16" DockPanel. Dock = "Top"/> <StackPanel Height = "16" DockPanel. Dock = "Bottom"/> <Button Width = "100" DockPanel. Dock = "Left"/> <GroupBox Height = "150" DockPanel. Dock = "Bottom" Header = "Log"> <ListBox Name = "lstLog" runManager:ListBoxExtenders.AutoScrollToCurrentItem= "True" IsSynchronizedWithCurrentItem = "True" ItemsSource = "{Binding ElementName=mainWindowViewModel, Path=MemLogEvents}"/> </GroupBox> <! - Put ESRI map here-> </DockPanel> </Window> using Esri. ArcGISRuntime; using System; using System. Diagnostics; using System. Linq; using System. Windows; using ICC.Common; using ICC.RunManager. ViewModels; namespace ICC.RunManager {public partial class MainWindow: Window {public MainWindow () {InitializeComponent ();//datacontext assigned in XAML//MainWindowViewModel viewModel = new MainWindowViewModel ();//this. DataContext = viewModel;}}} using System; using System. Collections. Generic; using System. Collections. ObjectModel; using System. Linq; using System. Text; using System. Threading. Tasks; using ICC.Common; namespace ICC.RunManager. ViewModels {class MainWindowViewModel: BaseViewModel {//ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable private readonly Logger _logger; private List <string> _memLogEvents; public List <string> MemLogEvents {get {return _memLogEvents;} set {_memLogEvents = value;//OnPropertyChanged (nameof (MemLogEvents));} }///<summary>///Default constructor///</summary> public MainWindowViewModel () {_logger = Logger. GetInstance ();//subscribe viewModel to the log events _logger. MemLog + = this. GetMemLogEvent;//init log collection _memLogEvents = new List <string> ();//grab all previous logs List <MemLogEventArgs> memLogList = _logger. GetMemLogList (true); foreach (var memLogItem in memLogList) {this. GetMemLogEvent (this, memLogItem);}} private void GetMemLogEvent (object sender, MemLogEventArgs eventArgs) {MemLogEvents. Add (eventArgs.Log); OnPropertyChanged (nameof (MemLogEvents));} }} using System; using System. Collections. Generic; using System. Linq; using System. Text; using System. Threading. Tasks; using ICC.Common; namespace ICC.RunManager. Classes {public class BaseClass {private readonly Logger _logger = Logger. GetInstance (); private readonly AppHelper _appHelper = new AppHelper (); public void Run () {_logger. WriteLine (""); _logger. WriteLine ("****************************************************************************************"); _logger. WriteLine ("* *"); _logger. WriteLine ("* Application started *"); _logger. WriteLine ("* ICC Run Manager *"); _logger. WriteLine ("* *"); _logger. WriteLine ("****************************************************************************************"); _logger. WriteLine (""); _logger. WriteLine ("Application Name:" + _appHelper. GetApplicationName () + ".exe ver." + _appHelper. GetApplicationVersionInfo ().ProductVersion); _logger. WriteLine ("Run Path:" + AppSettings. ApplicationPath); _logger. WriteLine ("");} public void Close () {_logger. WriteLine (""); _logger. WriteLine ("****************************************************************************************"); _logger. WriteLine ("* *"); _logger. WriteLine ("* Application terminated *"); _logger. WriteLine ("* *"); _logger. WriteLine ("****************************************************************************************"); _logger. WriteLine (""); _logger. CloseLogFile ();}}} Making comments on all OnPropertyChanged all the same works... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>