WPF Repeater (like) control for collection source??

Posted by Sonic Soul on Stack Overflow See other posts from Stack Overflow or by Sonic Soul
Published on 2010-06-09T21:35:21Z Indexed on 2010/06/09 21:42 UTC
Read the original article Hit count: 679

Filed under:
|
|

I have a WPF DataGrid bound to ObservableCollection. Each item in my collection has Property which is a List. In my row details pane, i would like to write out formatted textblocks for each item in this collection. The end result would be something equivalent to:

<TextBlock Style="{StaticResource NBBOTextBlockStyle}" HorizontalAlignment="Right">
<TextBlock.Inlines>
    <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Name}" />
    <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Price}" />
    <LineBreak />
    <Run Foreground="LightGray" Text="{Binding Path=Exchanges[0].Quantity}" />
</TextBlock.Inlines>
</TextBlock>
<TextBlock Style="{StaticResource NBBOTextBlockStyle}">
<TextBlock.Inlines>
    <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Name}" />
    <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Price}" />
    <LineBreak />
    <Run Foreground="LightGray" Text="{Binding Path=Exchanges[1].Quantity}" />
</TextBlock.Inlines>
</TextBlock>

and so on 0-n times.

I've tried using ItemsControl for this:

<ItemsControl ItemsSource="{Binding Path=Exchanges}">
    <DataTemplate>
        <Label>test</Label>
    </DataTemplate>
</ItemsControl>

however, this appears to be only meant for more static sources, as it throws the following exception (collection is not altered after creation):

ItemsControl Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead

Is there another way to achieve this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET