I’m new to WPF and data binding. After wandering around the web for a good practical solution, all I could find were (in my opinion) overly complicated solutions to a problem that will most probably be fixed in the future.
Problem
It seems that when adding or removing elements from an observable collection, data binding works. However, when an element within the collection changes value, the GUI element is not updated.
Solution
For this, I made a new collection class that would implement the ObservableCollection with a Refresh() method which would just raise the collection change event.
Aim - Simplify the process of updating the GUI
My XAML Code
- <Button Content="Add" HorizontalAlignment="Left" Margin="366,69,0,0" VerticalAlignment="Top" Width="75" Click="AddDate" />
- <ListBox Name="MyListBox" HorizontalAlignment="Left" Height="95" Margin="131,84,0,0" VerticalAlignment="Top" Width="197">
- <ListBox.ItemTemplate>
- <DataTemplate>
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="{Binding Now}"></TextBlock>
- <CheckBox IsChecked="{Binding IsChecked}"></CheckBox>
- </StackPanel>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- <Button Content="Mark All" HorizontalAlignment="Left" Margin="366,94,0,0" VerticalAlignment="Top" Width="75" Click="MarkAll" />
- <Button Content="Unmark All" HorizontalAlignment="Left" Margin="366,119,0,0" VerticalAlignment="Top" Width="75" Click="UnMarkAll" />
Class file

CsharpestPosted Nov 11, 2018, 11:45 PM
This was just what I was looking for. Simple and elegant solution. Thanks!