With ObjectDataProvider you can easily instantiate LINQ to SQL DataContext and request desired ITable using GetTable method:

<Window x:Class="WpfObjectProviderWithLinqToSql.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:local="clr-namespace:WpfObjectProviderWithLinqToSql"
    Title="How to bind declaratively LINQ to SQL DataContext using ObjectDataProvider" 
    Height="400" Width="500" ResizeMode="NoResize">
    <Grid>
        <Grid.Resources>
            <ObjectDataProvider x:Key="customers" 
                ObjectType="{x:Type local:NorthwindDataContext}" MethodName="GetTable">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:Customer" />
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </Grid.Resources>
        <telerik:RadGridView Name="RadGridView1" telerik:Theming.Theme="Vista" 
            ItemsSource="{Binding Source={StaticResource customers}}">
        </telerik:RadGridView>
    </Grid>
</Window>

The result – completely codeless data-binding to LINQ to SQL context:
 Untitled

Enjoy!

[Download]


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.