WPF Display Design Data instead of a DataTable returned by method

439 views Asked by At

I need help in displaying sample data. Currently I have a DataTable that is provided as input in the window constructor. My setup is the following:

The window class

public partial class Project_Status_Window : Window {

    //Required for the datacontext
    public DataTable status { get; }


    public Project_Status_Window(DataTable status) {
        InitializeComponent();
        this.status = status;
        this.Show();
    }
}//End of Window Class

This is a fairly simple class. The status property is set in the constructor. In the formatting side of things I want the new window that is created to display some of the columns of the DataTable and format other columns based on values of columns that are not displayed. In my XAML I declare a DataGrid as follows:

     <DataGrid x:Name="Status_Table_Viewer"
                      DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}"
                      ItemsSource="{Binding status.DefaultView}" Grid.Row="0"
                      SelectionMode="Extended" SelectionUnit="Cell" ScrollViewer.CanContentScroll="True"
                      AutoGenerateColumns="False" HorizontalAlignment="Stretch" IsReadOnly="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Order_Number}"  Header="Order Number"/>
                    <DataGridTextColumn Binding="{Binding Order_Line}" Header="Order Line"/>
                    <!-- More Columns and formating that is irrelevant -->
                </DataGrid.Columns>
     </DataGrid>

However further this setup is time consuming for me to develop. I have found some articles in order to display data but those do not seem to apply in my case.

0

There are 0 answers