Note that there are some explanatory texts on larger screens.

plurals
  1. POListbox bound to an ObservableCollection doesn't update
    primarykey
    data
    text
    <p>I am using a ObservableCollection to store the Environment Variables of Windows.</p> <pre><code>class VariableVieWModel { ObservableCollection&lt;VariableModel&gt; vars; public ObservableCollection&lt;VariableModel&gt; Variables { get { return vars; } set { vars = value; } } public VariableViewModel() { Reload(); } public void Reload() { // Code to retrieve vars } } </code></pre> <p>This ObservableCollection is bound to a ListBox.</p> <p>I have added a button in the GUI to reload the Variables whichi, on click, it calls the Reload() procedure.</p> <p>ListBox content, however, does not change and I cannot add anymore items to the list afer calling Reload().</p> <p>Under the constructor everything is working fine.</p> <p>ListBox XAML :</p> <pre><code>&lt;ListBox x:Name="lbVariables" Grid.Column="0" Margin="0,0,5,0" ItemsSource="{Binding Source={StaticResource variablesViewModel}, Path=Variables}" IsSynchronizedWithCurrentItem="True"&gt; </code></pre> <p>I tried using also PropertyChanged as UpdateSource trigger and set most of the Modes.</p> <pre><code>public void Reload() { vars = new ObservableCollection&lt;VariableModel&gt;(); RegistryKey systemVarKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"); string[] systemVars = systemVarKey.GetValueNames(); foreach (string var in systemVars) { vars.Add(new VariableModel() { Name = var, Values = (systemVarKey.GetValue(var, null, RegistryValueOptions.DoNotExpandEnvironmentNames) as string).Split(';').ToList&lt;string&gt;(), Target = EnvironmentVariableTarget.Machine }); } systemVarKey.Close(); RegistryKey userVarKey = Registry.CurrentUser.OpenSubKey(@"Environment"); string[] userVars = userVarKey.GetValueNames(); foreach (string var in userVars) { vars.Add(new VariableModel() { Name = var, Values = (userVarKey.GetValue(var, null, RegistryValueOptions.DoNotExpandEnvironmentNames) as string).Split(';').ToList&lt;string&gt;(), Target = EnvironmentVariableTarget.User }); } userVarKey.Close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload