In my main window.xaml i have a button which opens searchwindow.xaml
private void Search_Click(object sender, RoutedEventArgs e)
{
if (dt.Rows.Count > 0)
{
new SearchWindow(){DataContext = dt.DefaultView}.Show();
}
}
In the searchWindow.Xaml is there is button 'BIND' and a datagrid . I want to databind the data grid with the dat context table that has been sent from MainWindow.xaml on clicking the BIND button...How can i do it...Thank you
Loading
akpaga akpagaPosted May 7, 2013, 12:09 PM
Deaclaring the Datatable dtable was the crux of my solution .
Code on The searchWidnow.Xaml
public partial class SearchWindow : Window
{
public DataTable dtable { get; set; }
public SearchWindow( )
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// var dt = MainWindow.DataContextProperty;
}
private void bind_Click(object sender, RoutedEventArgs e)
{
var dt = this.dtable;
dGrid2.DataContext = dt.DefaultView;
}
Then on the mainwindow.xaml.cs page
In the button click event that opens searcwindow.xaml
if (dt.Rows.Count > 0)
{
SearchWindow searchWindow = new SearchWindow() { DataContext = dt.DefaultView };
searchWindow.dtable = dt;
searchWindow.Show();
}