我正在使用 Object dataprovider 将数据集绑定到 XAML 中的数据网格。
这是我的代码:
<UserControl xmlns:my="clr-namespace:Pauspan_n_"
x:Class="UCitems"
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"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="1100">
<UserControl.Resources>
<ObjectDataProvider x:Key="sizes" ObjectType="{x:Type my:Item_sizes}">
</ObjectDataProvider>
<ObjectDataProvider x:Key="sizes2" ObjectInstance="{StaticResource sizes}" MethodName="Getsizes">
</ObjectDataProvider>
</UserControl.Resources>
<Grid Height="700" Width="1100">
<DataGrid AutoGenerateColumns="False" Height="154" HorizontalAlignment="Left" Margin="819,55,0,0"
Name="dgv_itemsizes" VerticalAlignment="Top" Width="242"
ItemsSource="{Binding Source={StaticResource sizes2}}" ></DataGrid>
</Grid>
</UserControl>
我的数据集名称是,数据表Item_sizes
名称是sizes
,但 datagrid 中没有显示任何内容。
我想我可能想要这样的东西:
Public Overridable Overloads Function GetSizes() As Item_sizes.sizesDataTable
Me.Adapter.SelectCommand = Me.CommandCollection(0)
Dim dataTable As Item_sizes.sizesDataTable = New Item_sizes.sizesDataTable()
Me.Adapter.Fill(dataTable)
Return dataTable
End Function