What I want to do is access the database via a query (already have one made, but heres the issue:
namespace WpfApp3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class ViewData : Window
{
public ViewData()
{
InitializeComponent();
}
private void ShowData(object sender, RoutedEventArgs e)
{
CustomerEntities1 db = new CustomerEntities1();
if (report.IsInitialized)
{
var report = from values in db.Customers
select values;
valueGrid.ItemsSource = report.ToList();
}
else if (sortName.IsInitialized)
{
var sortName = from values in db.Addresses
select values;
valueGrid.ItemsSource = sortName.ToList();
}
}
}
}
I Do not understand how the bindings in WPF work, and Im having issues when running the code. It only runs the top portion of the if condition. Any ideas what binding I should use where if clicked, it is considered true, and runs the condition when met. Once the condition is met, it should remove the old one, and replace it with the new query for the DataGrid. Thank You
CodePudding user response:
i think you should Clear the valueGrid before you bind the new List.
CodePudding user response:
So in WPF the UI Components (valueGrid
) in your case are usually notified if the Data changes (CustomerEntities1
) on Initialization and IF and ONLY IF the Source implements INotifyPropertyChanged
. you should therefore consider implementing this interface in ally or ViewModels, assuming you are using the MVVM pattern.