Hi Guys and Gals!
I answered my question myself. I share it with you. May be would be of interest to someone.
It seems setting the DataContext does nothing. I've fixed it. Now it works fine.
Here is the code:
CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Metadata.Edm;
using Microsoft.Windows.Controls;
using FirebirdSql.Data.FirebirdClient;
namespace WpfBrowserApplication2
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
FbConnection MyConnection = new FbConnection("User=SYSDBA;Password=masterkey;Database=c:\\temp\\MyData.FDB;DataSource=localhost; Port=3050;Dialect=3; Charset=NONE;Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;");
MyConnection.Open();
DataSet employee = new DataSet();
FbDataAdapter da = new FbDataAdapter("select * from EMPLOYEE ", MyConnection);
da.Fill(stoki, "EMPLOYEE");
int recordnum = employee.Tables[0].Rows.Count;
Label1.Text =" EMPLOYEE RecordCount=" + recordnum.ToString();
Binding MyBinding = new Binding();
MyBinding.Source = employee.Tables[0];
dataGrid1.ItemsSource = employee.Tables[0].Rows;
dataGrid1.SetBinding(DataGrid.ItemsSourceProperty, MyBinding);
}
}
}
In order to access the DataGrid class from code you should add a refference in the project to WPF Toolkit dll which is (usually) in the Program Files\WPF Toolkit directory.
and the XAML part
CODE
<Page x:Class="WpfBrowserApplication2.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
Loaded="Page_Loaded" Title="Page1" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<my:DataGrid Name="dataGrid1" CanUserAddRows="True" CanUserDeleteRows="True" >
</my:DataGrid>
<TextBlock Name="Label1" Text="Test" Grid.Row="1"/>
</Grid>
</Page>
In fact the binding from XAML could be easier - I can add
CODE
ItemsSource="{Binding EMPLOYEE}"
to the DataGrid.
Here are some links that I used to resolve my issue:
1.
http://windowsclient.net/wpf/wpf35/wpf-35s...alkthrough.aspx2.
http://www.codeproject.com/KB/WPF/WPFDataG...es.aspx#dataset3.
http://dedjo.blogspot.com/2007/03/creating...-from-code.htmlThis post has been edited by dmarinov: 26 Jun, 2009 - 02:00 AM