Thursday, April 27, 2017

wpf datagrid simple bind

<Window x:Class="ldapTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ldapTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
        <StackPanel>
            <DataGrid Name="grid1"></DataGrid>
        </StackPanel>
</Window>


        public MainWindow()
        {
            InitializeComponent();
            grid1.ItemsSource = new ObservableCollection<MyData>()
                                    {
                                        new MyData("x@y.z", "my1"),
                                        new MyData("m2@a.b","my2")
                                    };
           
        }


        public class MyData
        {
            public string Email { get; set; }
            public string Name { get; set; }

            public MyData(string email, string name)
            {
                Email = email;
                Name = name;
            }
        }

No comments: