In WPF I have a ListView that is bound to a table in a Dataset. If I use (Commented out in full code view:
<ListView.View>
<GridView>
<GridViewColumn>
I get the rows displayed and I can see multiple rows and scroll through the rest.
If I try
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
'Put a bunch of controls here bound to various columns in my data table
I can only see one row/record at one time. Am I missing a setting on one of the controls or is the ListView.ItemTemplate only going to show one record at a time.
I’m looking for something in WPF that is more like a Repeater control where I can have different controls for each record in a particular layout.
Full xaml:
<Window x:Class="GridTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="GridTest" Height="661" Width="750">
<ListView Margin="4,1,8,1"
Name="ListView_Transactions" ItemsSource="{Binding}">
<!--<ListView.View>
<GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Transactions">
<GridViewColumn DisplayMemberBinding="{Binding Path=TransactionHeaderID}" />
</GridView>
</ListView.View>-->
<ListView.ItemTemplate>
<DataTemplate>
<Grid MaxHeight="600">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Key" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Amount}" Height="25" Name="Label_Amount" VerticalAlignment="Top" Width="134" Margin="50,201,526,0" />
<Label Content="{Binding ActivityCategory}" Height="24" HorizontalAlignment="Left" Name="Label_ActivityCategory" VerticalAlignment="Top" Width="161" Margin="208,201,0,0" />
<TextBox Height="23" HorizontalAlignment="Left" Name="TextBox_Customer" VerticalAlignment="Top" Width="163" Margin="440,201,0,0" />
<Button Content="Breakout" Height="20" Name="Button_Breakout" Width="90" BorderThickness="0" ClickMode="Press" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,244,0,223">
</Button>
<Label Content="{Binding ShortDescription}" Height="27" HorizontalAlignment="Left" Name="Label_ShortDescription" VerticalAlignment="Top" Width="480" Margin="50,270,0,0" />
<TextBlock Height="65" HorizontalAlignment="Left" Name="TextBlock_LogDescription" Text="{Binding LongDescription}" VerticalAlignment="Top" Width="480" Margin="50,303,0,0" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Window>

Cleaned Up My Mess:
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
<ItemsControl Name="ItemsC" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Left">
<DockPanel >
<Label Content="{Binding Amount}" Height="25" DockPanel.Dock="Left" Name="Label_Amount" Width="100" />
<Label Content="{Binding ActivityCategory}" DockPanel.Dock="Left" Height="24" Name="Label_ActivityCategory" Width="100" />
<TextBox Height="25" DockPanel.Dock="Left" Name="TextBox_Customer" Width="123" />
</DockPanel>
<StackPanel HorizontalAlignment="Left">
<Button Content="Breakout" Height="25" Name="Button_Breakout" Width="90" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Content="{Binding ShortDescription}" Name="Label_ShortDescription" Width="550" />
<TextBlock Height="200" Name="TextBlock_LogDescription" Text="{Binding LongDescription}" Width="550" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
Maybe you do not need a
ListView.ItemsControlin my opinion is direct equivalent forRepeaterYour
ItemTemplateis messed up completely – I believe it causes your problems. Instead of putting everything into oneGridyou should use several (probably nested)DockPanels/StackPanels. Remove all your fantastic margins – it should help. VS designer does his job badly creating a XAML, that’s why I prefer editing XAML on my own.