首先,我真的是一个初学者。我主要在 WinForm 上工作,所以我从未听说过 WPF 上的数据绑定。
试图从博客和 MSDN 中学习,但我无法掌握。数据绑定只是我对 WPF 的困惑之一,但它是我现在需要了解的主要内容。
假设我得到了这些类:CustomerDL.vb(数据访问层)CustomerBL.vb(业务层)FormCustomer.xaml(表示层)
我现在所做的,是我所学的唯一概念:DL -> BL -> PL。
这是我的 PL:
Public Class FrmEmployee2
Public Sub New()
InitializeComponent()
MasterEmployeeBL = New MasterEmployeeBL
Employees = MasterEmployeeBL.FetchAllEmployee()
MainGrid.DataContext = Employees
End Sub
Private _employees As List(Of Employee)
Public Property Employees() As List(Of Employee)
Get
Return _employees
End Get
Set(ByVal value As List(Of Employee))
_employees = value
End Set
End Property
Public MasterEmployeeBL As MasterEmployeeBL
End Class
这是我的 WPF:
<dx:DXWindow x:Class="FrmFindEmployee2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
xmlns:dxd="http://schemas.devexpress.com/winfx/2008/xaml/docking"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
xmlns:local="clr-namespace:BMT_WPF"
dx:ThemeManager.ThemeName="MetropolisDark"
Title="Find Employee" Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}" Width="658"
WindowStartupLocation="CenterScreen" SizeToContent="Width">
<Window.Resources>
<ResourceDictionary>
<local:BooleanToStatusConverter x:Key="BoolToStatusConv" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BMT-WPF;component/Helpers/EditStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid x:Name="MainGrid" DataContext="{Binding Source=Employees}">
<DockPanel>
<dxg:GridControl ItemsSource="{Binding}" AutoPopulateColumns="True">
</dxg:GridControl>
</DockPanel>
</Grid>
</dx:DXWindow>
我认为这足以将员工列表绑定到我的 GridControl,但它什么也没显示。
任何人都可以帮助指出我可以从初学者的角度了解 WPF 的任何好的资源吗?
对不起,很长的帖子。干杯!:)