Friday, November 28, 2008

WPF OneWay Binding Part 3

In this part we will bind to a class. We will start off by creating a grid to display the properties of the class. Finally we will show how to get the form to update itself when a value changes in the class.


Lets start off creating a class that shows some info about the computer. Here is the class.

Public Class ComputerInfo

Public ReadOnly Property UserName() As String
Get
Return Environment.UserName
End Get
End Property
Public ReadOnly Property ComputerName() As String
Get
Return Environment.MachineName
End Get
End Property
Public ReadOnly Property UpTime() As Integer
Get
Return Environment.TickCount
End Get
End Property


End Class



Ok lets register the class with the form.

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFOneWayBindToVariable"
Title="WPFOneWayBindToVariable" Height="300" Width="300"
>




Now lets create a grid with 2 columns and 3 rows to show the class in.












Lets put the data in the grid we just created.

No comments: