Insofar as you did not provided the code that shows how you created the StaticResource I'll assume that you want to bind Settings directly from xaml.
Bind Settings.Default from XAML
In the first instance, add XML namespace that is pointing to namespace where the Settings class is declared:
xmlns:properties="clr-namespace:WpfSettings.Properties"
Then you can bind your collection from settings as follows:
ItemsSource="{Binding Source={x:Static properties:Settings.Default}, Path=Collection}"
Since you bind directly to the collection that is declared directly in settings, WPF is not aware of collection updates if it does not implement INotifyCollectionChanged
. To solve this problem you could create ObservableCollection
in settings.
Create ObservableCollection in settings
Open settings in XML editor and add new setting as follows:
<Setting Name="Collection" Type="System.Collections.ObjectModel.ObservableCollection<System.String>" Scope="User">
<Value Profile="(Default)" />
</Setting>
Then add the default value in settings editor (source):
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
In the end, it might look like this:
<Setting Name="Collection" Type="System.Collections.ObjectModel.ObservableCollection<System.String>" Scope="User">
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" /></Value>
</Setting>
Whenever you add items to your Collection setting, the ListBox will also be updated.