How do I set the ItemsSource of a DataGrid in XAML?

Posted by Ben McCormack on Stack Overflow See other posts from Stack Overflow or by Ben McCormack
Published on 2010-06-14T18:22:56Z Indexed on 2010/06/14 18:32 UTC
Read the original article Hit count: 450

Filed under:
|
|
|
|

I'm trying to set the ItemsSource property of a DataGrid named dgIssueSummary to be an ObservableCollection named IssueSummaryList. Currently, everything is working when I set the ItemsSource property in my code-behind:

public partial class MainPage : UserControl
{
    private ObservableCollection<IssueSummary> IssueSummaryList = new ObservableCollection<IssueSummary>

    public MainPage()
    {
        InitializeComponent();
        dgIssueSummary.ItemsSource = IssueSummaryList
    }
}

However, I'd rather set the ItemsSource property in XAML, but I can't get it to work. Here's the XAML code I have:

<sdk:DataGrid x:Name="dgIssueSummary" AutoGenerateColumns="False"
                ItemsSource="{Binding IssueSummaryList}" >
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn Binding="{Binding ProblemType}" Header="Problem Type"/>
        <sdk:DataGridTextColumn Binding="{Binding Count}" Header="Count"/>
    </sdk:DataGrid.Columns>
</sdk:DataGrid>

What do I need to do to set the ItemsSource property to be the IssueSummaryList in XAML rather than C#?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET