vb.net WPF 中的同步网格

vb.net syncfusion grid in WPF

我正在尝试创建一个非常简单的 WPF 应用程序来测试 VB.NET

中的 Syncfusion Grid

我创建了一个简单的 window 并在设计器中插入了一个 ScrollViewer 和一个 Syncfusion GridControl。

这是windowxaml

<Window
        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:ExpenseIt"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="Window2"
        mc:Ignorable="d"
        Title="Window2" Height="300" Width="537.398">
    <Grid>
        <ScrollViewer HorizontalAlignment="Left" Height="194" Margin="10,10,0,0" VerticalAlignment="Top" Width="380">
            <syncfusion:GridControl Height="100" Width="100"/>
        </ScrollViewer>

    </Grid>
</Window>

现在我尝试在相应的 xaml.vb 文件中创建网格实例

Public Class Window2
    Dim gridControl As Syncfusion.Windows.Controls.Grid

    Private Sub Window2_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

    End Sub
End Class

但是 "Dim" 行显示一个错误,说它需要类型。 我做错了什么?

您正在 XAML 中创建 GridControl 的实例。给它一个 x:Name:

<syncfusion:GridControl x:Name="grid" Height="100" Width="100"/>

...您可以使用此名称在代码隐藏中访问此实例:

Private Sub Window2_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    Dum theGrid = grid
    '...
End Sub

如果您尝试创建另一个实例,您应该使用正确的类型名称:

Dim gridControl As Syncfusion.Windows.Controls.Grid.GridControl