Я использую MVVM, связывающий ObservableCollection
детей с ItemsControl
. ItemsControl
содержит UserControl, используемый для стилизации пользовательского интерфейса для детей.
<ItemsControl ItemsSource="{Binding Documents}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<View:DocumentView Margin="0, 10, 0, 0" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Я хочу показать строку заголовка для содержимого ItemsControl
, но хочу показать это только один раз вверху (не для каждого дочернего элемента). Как я могу реализовать это поведение в пользовательском элементе управления DocumentView
? Кстати, я использую Grid
макет для Style
дочерних строк:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="34"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.ColumnSpan="4" Grid.Row="0" Text="Should only show this at the top"></TextBlock>
<Image Grid.Column="0" Grid.Row="1" Height="24" Width="24" Source="/Beazley.Documents.Presentation;component/Icons/error.png"></Image>
<ComboBox Grid.Column="1" Grid.Row="1" Name="ContentTypes" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type View:MainView}}, Path=DataContext.ContentTypes}" SelectedValue="{Binding ContentType}"/>
<TextBox Grid.Column="2" Grid.Row="1" Text="{Binding Path=FileName}"/>
<Button Grid.Column="3" Grid.Row="1"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type View:MainView}}, Path=DataContext.RemoveFile}"
CommandParameter="{Binding}">Remove</Button>
</Grid>