Hi, apologies in advance for the noob question, I've only been using WPF for a few weeks and SQL Server for a few days, but I can't find out how to do this anywhere on the web so far.
I have a database on SQL Server with one table in it 'User', and have an application that can display data (Username) from that table in a ListView using Bindings which works fine.
However, if the database has items added/deleted etc by something other than the application, the changes are not automatically reflected in the ListView. I thought Bindings would take care of this, but maybe that's only if the application itself modifies the data?
XAML:
<Window.Resources>
<DataTemplate x:Key="ShowUser" DataType="{x:Type db:User}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Username}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
...
<ListView Grid.Row="2" x:Name="TheListView" ItemTemplate="{StaticResource ShowUser}">
Code behind:
public MainWindow()
{
InitializeComponent();
MyDBEntities db = new MyDBEntities();
var users = from u in db.Users
select u;
IListSource query = (IListSource)users;
TheListView.ItemsSource = query.GetList();
}
What do I need to do to get the ListView dynamically updating when the database contents are changed by something other than the application itself?
Thanks in advance, Daniel