对如何通过WPF来创建一个listBox,并同后台数据链接,实现数据驱动实施更新UI界面,做一个简单的样例介绍。(简陋的UI和一塌糊涂的命名还请大家见谅)
首先现在XAML中创建UI如下图。
<Window x:Class="listBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:listBox"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Text="请输入学生ID:" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="STUid" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="请输入学生姓名:" Grid.Row="3" Grid.Column="0"