WPF Data Bindings



Playing with some new toys today — I am trying to use WPF anywhere I would otherwise use the WinForms technology.

So I am supposed to check diskspace on some remote hosts (Windows Server 2003) and I don’t want to constantly login;  Whatever, it’s an excuse to learn something.

So I want to display free space percents of “mapped drives” when I click on this program.

The object I use to display is a  ListView.  In WPF, a listview is slightly different (from WinForms), but it’s versatile.

I found some older examples that set the display values as a “column” and in WPF you can bind the columns to class properties.

So, in the XAML, you just say what property binds to the column using “DisplayMemberBinding” and the squiggly brackets…:

 Grid.Row=“2” >
<GridViewColumn Header=“Drive” DisplayMemberBinding=”{Binding DriveLetter}/>
<GridViewColumn Header=“Free Space” DisplayMemberBinding=”{Binding DiskFreeSpace}/>
<GridViewColumn Header=“Size” DisplayMemberBinding=”{Binding Size}/>
<GridViewColumn Header=“Percent Free” DisplayMemberBinding=”{Binding PercentFree}/>
<GridViewColumn Header=“UNC Name” DisplayMemberBinding=”{Binding UNCName}/>
<GridViewColumn Header=“Mapped” DisplayMemberBinding=”{Binding Mapped}/>

Then, the ListView populates with the values.

Proactive technologist.

Posted in New, WPF

What do you think?