Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have been trying for weeks to find a decent article that explains WPF Binding simply and with a working example that actually explains what is happening. Yes there are lots of examples out there but lots of those refer to older versions of everything involved.

I am trying to write an application, that is not web based, uses WPF and VB on VS2012.

In this bit of code i am updating a screen field directly, but i want to learn how to update a variable in memory and it update on the screen automatically, how do i get from here to there - In stages with simple explanations

I WAS a traditional programmer in languages such as Pascal, various flavours of Basic and various Assemblers but never C and certainly not OO

XML
<Window x:Class="MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="Test Bind" 
        Height="299" Width="500" WindowStartupLocation="CenterScreen">

    <DockPanel HorizontalAlignment="Stretch" LastChildFill="False" VerticalAlignment="Stretch">
        <DockPanel DockPanel.Dock="Top" Height="64">
            <Button Content="Button" Height="64" VerticalAlignment="Top" Width="75" Click="Button_Click" />
            <TextBox Height="64" Width="120" Text="TextBox1" x:Name="clickcount" />
            <TextBox Height="64" Width="120"  x:Name="textBox2" Text="{Binding Test, Mode=Default}" />
        </DockPanel>
    </DockPanel>

</Window>


VB
Class MainWindow
  Public Shared clcount As Integer = 0

  Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    clcount = clcount + 1
    Me.clickcount.Text = clcount.ToString
  End Sub    
End Class
Posted
Comments
[no name] 31-Jul-13 15:42pm    
Probably the best you will get is links to articles in this forum, on this subject. Just so you are prepared :-) http://www.codeproject.com/Articles/23772/WPF-A-Beginner-s-Guide-Part-5-of-n
Gerald Connolly 31-Jul-13 16:42pm    
Thanks for the pointer, i had already found that page. It is informative but its from 2008, ie 5 years old, things have moved on a bit since then.
[no name] 31-Jul-13 17:14pm    
The data binding is data binding. It's the same now as it was then.
[no name] 31-Jul-13 15:48pm    
Sorry about the duplicates. Not sure what happened there.

1 solution

To bind the variable stored in memory and on changing the value of variable screen value should be reflected ......... there is dependency property in WPF or you can use INotifyPropertyChanged interface.

First you should understand about dependency property and INotifyPropertyChanged then it will be easy for you.

If you need demo application i can elaborate further.
 
Share this answer
 
Comments
Gerald Connolly 1-Aug-13 14:00pm    
How does that look? are you saying i can just do that in WPF?
Raman Midha 2-Aug-13 9:03am    
yes you can do in wpf only ..
Gerald Connolly 3-Aug-13 7:43am    
Yes, but how?
i am looking for a simple example so i can get my head round this stuff!
Raman Midha 3-Aug-13 14:46pm    
ok let me know your mail id ..... i will send you sample application.
Gerald Connolly 4-Aug-13 4:29am    
i am loath to put my email in plain view, is there a private messaging system on here?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900