Beruflich Dokumente
Kultur Dokumente
In Focus
First C# Corner
0 7 276.8k
DataBindingInListControlInWPF.rar
Download Free .NET & JAVA Files API
Here we look an example of simple data binding in WPF. In this example I use a class for Data Binding.
Here we look at the program.
<Grid x:Name="StuInfo">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="77"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
</Grid>
Step2: After that we create two TextBlocks and Two TextBoxes in our program and we also create a Button
(Next) to see the Next Record according to the program.
https://www.c-sharpcorner.com/UploadFile/mahakgupta/simple-data-binding-in-wpf/ 1/5
4/26/2019 Simple Data Binding in WPF
In Focus
First C# Corner
Step3: Now we add a Loaded Event handler in the .cs page. This event will be called when the client wants
to load the application:
}
}
Step5: Now we write the following code in the Loded Event Handler:
https://www.c-sharpcorner.com/UploadFile/mahakgupta/simple-data-binding-in-wpf/ 2/5
4/26/2019 Simple Data Binding in WPF
In Focus
this.StuInfo.DataContext = s;
First
} C# Corner
Step6: Now we add another Event Handler, which is for the Next Button:
public Window1()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
this.button1.Click += new RoutedEventHandler(button1_Click);
}
void button1_Click(object sender, RoutedEventArgs e)
{
Stu s = new Stu();
{
s.fname = "Juhi";
s.lname = "Gupta";
};
this.StuInfo.DataContext = s;
}
Here we add another data in our program. When we click on the Next Button, the output will be:
https://www.c-sharpcorner.com/UploadFile/mahakgupta/simple-data-binding-in-wpf/ 3/5
4/26/2019 Simple Data Binding in WPF
In Focus
First C# Corner
ASK A QUESTION CONTRIBUTE
Mahak Gupta
102 4.4m 2
0 7
Type your comment here and press Enter Key (Minimum 10 characters)
cool
Asfend Yar Feb 03, 2016
441 3.9k 297.3k 0 0 Reply
EDIT: nevermind
K May 07, 2013
1779 1 0 0 0 Reply
@ Arjun The answer depends on the context actually.if its which objects we can bind to then it can
be any FrameWork Element but the property must be a Dependency property.and furthermore
https://www.c-sharpcorner.com/UploadFile/mahakgupta/simple-data-binding-in-wpf/ 4/5
4/26/2019 Simple Data Binding in WPF
In Focus the other context how we want to bind the data (I mean at compiletime or at runtime )then there
First C# Corner
is Static and Dynamic binding.actually binding in WPF is a huge topic but a very important one. I
hope this may be small help to you.
ASK A QUESTION CONTRIBUTE
tarun tripathi May 10, 2012
1765 15 0 0 0 Reply
It's a very helpful for beginners keep it up. I have a question to you that what's the need of WPF
when we have GDI, GDI+ and DirectX?
Shrutz Mhatz Apr 11, 2012
1753 27 17.8k 0 0 Reply
We want to know how can be fetch data row by row from table in WPF?
Abhishek Dubey Apr 10, 2012
247 7.3k 1.8m 0 0 Reply
TRENDING UP
05 For Vs Foreach In C#
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners
C# Tutorials
©2019 C# Corner. All contents are copyright of their authors.
https://www.c-sharpcorner.com/UploadFile/mahakgupta/simple-data-binding-in-wpf/ 5/5