如何在XAML中将数据集绑定到datagrid?

时间:2013-11-04 17:43:54

标签: wpf xaml datagrid

我使用Object dataprovider将数据集绑定到XAML中的datagrid。

这是我的代码:

    <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

0 个答案:

没有答案