This code create a new gridview in wpf application. its working good.

<Grid>
        <DataGrid x:Name="MyDataGrid" x:Uid="MyDataGrid" AutoGenerateColumns="False" 
                       AlternationCount="2" SelectionMode="Single" Height="175" VerticalAlignment="Bottom" Background="White" Margin="12,0,12,12" CanUserAddRows="False" CanUserDeleteRows="False">
            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Name}"
                                    Header="Name" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Email}" 
                                    Header="Email" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=DOB}"
                                    Header="DOB" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Address1}"
                                    Header="Address1" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=City}"
                                    Header="City" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Country}"
                                    Header="Country" Width="SizeToHeader" />
                <DataGridTemplateColumn Header="Edit">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Edit" Click="EditButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Delete">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Delete" Click="DeleteButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>                    
                </DataGridTemplateColumn>               
            </DataGrid.Columns>
        </DataGrid>
        <Label Content="Printer Configuration" FontSize="16" Foreground="Blue" Height="28" HorizontalAlignment="Left" Margin="8,5,0,0" Name="Title" VerticalAlignment="Top" Width="272" />
        <Button Content="Add Printer" Height="23" HorizontalAlignment="Left" Margin="409,12,0,0" Name="btnAddPrinter" VerticalAlignment="Top" Width="141" Background="Blue" Foreground="White" FontSize="13" Click="btnAddEmploy_Click" />
    </Grid>
Just copy this code and past your wpf xaml file side of the window after that
public void LoadEmploys()
        {
string employconfigFolder="D:\\Employ.xml"
            var doc = new XmlDocument();
            doc.Load(employconfigFolder);

            XmlNodeList employ = doc.GetElementsByTagName("Employ");

            List<EmployAttribute> authors = new List<EmployAttribute>();

            foreach (XmlNode item in employ)
            {
                bool defaultPrinter = false;

                authors.Add(new PrinterAttribute()
                {
                    Name = item.Attributes["Name"].Value,
                    Email = item.Attributes["Email"].Value,
                    DOB = item.Attributes["DOB"].Value,
                    Address1 = item.Attributes["Address1"].Value,
                    City = item.Attributes["City"].Value,
                    Country = item.Attributes["Country"].Value,
                });
            }
            MyDataGrid.ItemsSource = authors;
        }



 public class EmployAttribute
        {
            public string Name { get; set; }
            public string Email { get; set; }
            public string DOB { get; set; }
            public string Address1 { get; set; }
            public bool City { get; set; }
            public bool Country { get; set; }
        }
you can call LoadEmploys() method in your window_Loaded() its working fine.

0 comments

Related Posts Plugin for WordPress, Blogger...