views:

172

answers:

1

How can I bind a wpf control to a SQL Server property. Like say a Listbox

 <ListView>
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name">
                <GridViewColumn Header="Date Assigned">
                <GridViewColumn Header="Date Due">
            </GridView>
        </ListView.View>
        <!-- iterate through all the Names in the database and output under GridViewColumn Name -->
        <!-- iterate through all the DateAssigned in the database and output under GridViewColumn Date Assigned -->
        <!-- iterate through all the DateDue in the database and output under GridViewColumn Date Due -->
    </ListView>

I am using the entity framework and the repository pattern. So I'd call all the names to a list by _repository.ToList();

+2  A: 

Try this: listViewName.ItemsSource = _repository.ToList();

I'd also simplify the Xaml, like this:

<ListBox x:Name="listViewName">
    <ListBox.Resources>
        <DataTemplate>
            <Grid Height="22" Width="Auto">
                <TextBlock Text="{Binding Name}" />
                <TextBlock  Text="{Binding DateAssigned}" />
                <TextBlock Text="{Binding DateDue}" />
            </Grid>
        </DataTemplate>
    </ListBox.Resources>
</ListBox>

Where the text after {Binding is the name of the property of the item in the collection you return from _repository.

Nate Bross