How can I use a parent content control from a sub binding?

Posted by MGSoto on Stack Overflow See other posts from Stack Overflow or by MGSoto
Published on 2010-04-13T16:12:11Z Indexed on 2010/04/13 16:12 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I have the following code currently:

<DataTemplate DataType="{x:Type vm:SectionViewModel}">
    <ScrollViewer>
        <ItemsControl ItemsSource="{Binding ViewModels}">
            <Grid/>
        </ItemsControl>
    </ScrollViewer>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:StringViewModel}">
   <Label Name="Left" Grid.Row="0" Grid.Column="0" Content="{Binding Label}"/>
   <TextBox Name="Right" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" Text="{Binding Value}"/>
</DataTemplate>

The ViewModels property bound to SectionViewModel ItemsControl is a list of StringViewModel. I want to insert each StringViewModel into some sort of content control in the ItemsControl. Originally I just had each StringViewModel to make its own Grid, but that left things unaligned. I'd like to insert these items into some sort of content control in ItemsControl, it doesn't necessarily have to be a grid, but it should be within the ItemsControl. How can I do this? I'm also following MVVM, using MVVM Light.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#