Terje Isaksen Developer blog

2010-05-04 (Tuesday)

WPF: Missing tag gives exception “Items collection must be empty before using ItemsSource.”

Filed under: Developing — Terje Isaksen @ 14:14
Tags: , , ,

If you have a datagrid with columns and misses to use the tag <toolkit:DataGrid.Columns> – then you will get the exception “Items collection must be empty before using ItemsSource.”

Wrong:

<toolkit:DataGrid >
     <toolkit:DataGridTemplateColumn >
        <toolkit:DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
               <StackPanel>
                  <toolkit:DatePicker  SelectedDate="{Binding Date, Mode=Twoway, StringFormat=yyyy-MM-dd, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
           </DataTemplate>
        </toolkit:DataGridTemplateColumn.CellTemplate>
     </toolkit:DataGridTemplateColumn>
</toolkit:DataGrid> 

Correct:

<toolkit:DataGrid >
  <toolkit:DataGrid.Columns>
     <toolkit:DataGridTemplateColumn >
        <toolkit:DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
               <StackPanel>
                  <toolkit:DatePicker  SelectedDate="{Binding Date, Mode=Twoway, StringFormat=yyyy-MM-dd, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
           </DataTemplate>
        </toolkit:DataGridTemplateColumn.CellTemplate>
     </toolkit:DataGridTemplateColumn>
  </toolkit:DataGrid.Columns>
</toolkit:DataGrid> 

Advertisements

2 Comments »

  1. thaaaaaaaaaaaaaaaaaaaaaaanx

    Comment by maiada — 2013-01-27 (Sunday) @ 04:56 | Reply

  2. thank you!

    Comment by roarkdude — 2016-07-07 (Thursday) @ 02:22 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: