Hi
I think I have a pretty simple goal but cant seem to reach it.
All I want to achieve is to have a ItemsControl (because I don't want the selection functionality of a list) with a header. Preferably a static header.
Currently I'm using a grid for the header and then copying that grid into the ItemTemplate (DataTemple) of the ItemsControl and then placing them one above the other in a grid. It kinda works but its it doesn't always line up nicely etc.
I then found the HeaderedItemsControl which I thought was a brilliant idea but cant get it to work, it just doesn't show the header at all. I have tried the following;
- Just entering text into the "Header" of the Xaml
- Placing a grid with TextBlocks with static text within the ItemsControl.Header tag
- Placing the grid within the HeaderTemplate (Datatemplate) and binding it to a simple object
I'm doing this all in Blend in a small project before moving it into the production app and I'm just using a simple sample data source which I created.
I might be missing the boat completely here but any help would be appreciated.
My current code is as follows, first is my HeaderedItemsControl
<HeaderedItemsControl Header="HeaderedItemsControl"
ItemsSource="{Binding Collection, Mode=Default}"
ItemTemplate="{DynamicResource ItemsControlDataTemplate}"
HeaderTemplate="{DynamicResource ItemsControlHeaderDataTemplate}"/>
then I've got a ItemTemple which works as expected
<DataTemplate x:Key="ItemsControlDataTemplate">
<Grid d:DesignWidth="268">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.754*"/>
<ColumnDefinition Width="0.246*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Property1, Mode=Default}" TextWrapping="Wrap" d:LayoutOverrides="Height" HorizontalAlignment="Stretch" Margin="0" />
<TextBlock Text="{Binding Property2, Mode=Default}" TextWrapping="Wrap" d:LayoutOverrides="Height" Grid.Column="1" HorizontalAlignment="Left" Margin="0" />
</Grid>
</DataTemplate>
and then the header which is defiantly opposing its work ethic, I've tried it with binding and with just plain text in the TextBlock.Text property
<DataTemplate x:Key="ItemsControlHeaderDataTemplate">
<Grid d:DesignWidth="268">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.754*"/>
<ColumnDefinition Width="0.246*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Header.Header1, Mode=Default, Source={StaticResource SampleDataSource6}}" TextWrapping="Wrap" HorizontalAlignment="Stretch" Margin="0"/>
<TextBlock Text="{Binding Header.Header2, Mode=Default, Source={StaticResource SampleDataSource6}}" TextWrapping="Wrap" d:LayoutOverrides="Height" Grid.Column="1" HorizontalAlignment="Left" Margin="0"/>
</Grid>
</DataTemplate>