ListView not stretching to fit content WPF XAML - wpf

Hey Everyone I am trying to figure out why my content will not stretch horizontally to fit my ListView items. I have HorizontalContentAlignment set to stretch, I used almost this exact layout on a second page and the content stretches on the second page. So not exactly sure what is going on and why the content won't stretch.
Here is a picture of what I am talking about
here is the code
<Border>
<Border.Background>
<ImageBrush ImageSource="/Backgrounds/BlueWaveBackground.jpg"/>
</Border.Background>
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Center" >
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" TextBlock.TextAlignment="Center">
<Border CornerRadius="10"
Background="{StaticResource ForegroundLightBrush}"
Padding="15 10 15 15"
Width="700"
Margin="50 50 50 0">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--First Last Username-->
<StackPanel Grid.Column="0" HorizontalAlignment="Center">
<TextBlock Text="First Name:" Margin="0 10 10 0" />
<TextBlock Text="Last Name:" Margin="0 14 10 0" />
<TextBlock Text="Username:" Margin="0 16 10 0"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" >
<TextBox Grid.Row="0" Text="{Binding SelectedUser.FirstName}"/>
<TextBox Text="{Binding SelectedUser.LastName}"/>
<TextBox Text="{Binding SelectedUser.UserName}"/>
</StackPanel>
<!--Email and EmployeeType-->
<StackPanel Grid.Column="2" HorizontalAlignment="Center">
<TextBlock Text="Email:" Margin="95 10 10 0" />
<TextBlock Text="Employee Type:" Margin="10 14 10 0" />
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Vertical" >
<TextBox Grid.Row="0" Text="{Binding SelectedUser.Email}"/>
<TextBox Text="{Binding SelectedUser.EmployeeType}"/>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal">
<Button Content="Add New User" Margin="15"/>
<Button Content="Update User" Margin="15"/>
<Button Content="Delete User" Margin="15"/>
<Button Content="Clear User Info" Margin="15"/>
</StackPanel>
<!--Data grid-->
<ListView ItemsSource="{Binding Users}"
SelectedItem="{Binding SelectedUser}"
Margin="0,20,0,0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
MaxHeight="150"
x:Name="List">
<ListView.View>
<GridView AllowsColumnReorder="True" ColumnHeaderToolTip="Users">
<GridViewColumn Header="First Name" Width="Auto" DisplayMemberBinding="{Binding FirstName}"/>
<GridViewColumn Header="Last Name" Width="Auto" DisplayMemberBinding="{Binding LastName}"/>
<GridViewColumn Header="Email" Width="Auto" DisplayMemberBinding="{Binding Email}"/>
<GridViewColumn Header="UserName" Width="Auto" DisplayMemberBinding="{Binding UserName}"/>
<GridViewColumn Header="Employee Type" Width="Auto" DisplayMemberBinding="{Binding EmployeeType}"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</Border>
Thanks for any suggestions!

I found the solution. I had to set my border width to auto.
<Border CornerRadius="10"
Background="{StaticResource ForegroundLightBrush}"
Padding="15 10 15 15"
Width="auto"
Margin="50 50 50 0">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>

Related

Bind Button Command in ControlTemplate to SelectedItem from Element in DataTemplate

I have done some googling and searches and find many questions on StackOverFlow that come close to helping me but all the ideas from them still give me binding expression errors in one form or another with most always mentioning it cannot find the source.
Cannot find source for binding with reference 'ElementName=filesList'.
View that calls control template:
<Expander
DockPanel.Dock="Top"
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="3" Grid.RowSpan="1"
Header="Files"
IsExpanded="True"
ExpandDirection="Down"
Background="{DynamicResource DynamicFrmBG}" Foreground="{DynamicResource DynamicFrmFG}"
>
<ContentControl
SnapsToDevicePixels="True"
Template="{StaticResource filesTemplate}"
/>
</Expander>
Control Template Code Snippet (Comment in this code is another example of different things I have tried):
<ControlTemplate x:Key="filesTemplate">
<Grid
SnapsToDevicePixels="True"
>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<ContentControl
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="2" Grid.RowSpan="1"
Margin="0,0,0,0"
Content="{Binding Files}"
ContentTemplate="{StaticResource filesListTemplate}"
/>
<StackPanel
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="3" Grid.RowSpan="1"
Orientation="Horizontal"
>
<Button
SnapsToDevicePixels="True"
Foreground="{DynamicResource DynamicFrmFG}"
Margin="0,5,5,5"
Content="Download"
Command="{Binding SelectedItem.Content.DownloadCommand, ElementName=filesList}"
MinWidth="50"
>
<!--Command="{Binding SelectedItem.Content.DownloadCommand, Source={StaticResource ResourceKey=filesListTemplate}, ElementName=filesList}"-->
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource DynamicFrmBGColor}" Offset="0"/>
<GradientStop Color="{DynamicResource DynamicFrmFGColor}" Offset="2"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</StackPanel>
</Grid>
Code snippet for the DataTemplate (The ListView datasource is set to an ObservableCollection and the FilesViewModel contains a Download command):
<DataTemplate x:Key="filesListTemplate">
<ListView
x:Name="filesList"
SnapsToDevicePixels="True"
IsTextSearchEnabled="False"
ItemsSource="{Binding }"
HorizontalContentAlignment="Stretch"
BorderBrush="{DynamicResource DynamicFrmFG}" Foreground="{DynamicResource DynamicFrmFG}" Background="{DynamicResource DynamicFrmBG}"
ItemContainerStyle="{DynamicResource ListViewItemStyle_Gray}"
>
<ListView.View>
<GridView
AllowsColumnReorder="False"
ColumnHeaderContainerStyle="{DynamicResource SpecialityHeader}"
>
<GridViewColumn
Width="200" Header="ID">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding ID}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="200" Header="File Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding Filename}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="250" Header="Uploaded By">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding Role}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="200" Header="Uploaded When">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding UploadedWhen}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
What I am trying to do is this; Bind the button in my control template to the selected FileViewModel, from the ListView, download command. This command, however, is located up in a DataTemplate. Can someone please assist me in doing this successfully?
Edit at 1705EST: Added the View that calls the control template.

Placing a textblock in a certain grid column

I populate a textblock with data from Service and I bind the data to Listbox and then display it in textblocks, so far so good. My problem is that I want each textblock content to be placed in certain space in certain column, but this doesn't seem to work as my text is just put in each line and is not alligned as it should be.
here is my code:
<Grid x:Name="BranchesGrid" Margin="12,0,-12,6" Grid.Row="2" Height="542" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<ListBox Height="530" HorizontalAlignment="Left" Margin="12,6,0,0" Name="listBox1" VerticalAlignment="Top" Width="456" Grid.ColumnSpan="4">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ID}" FontSize="20" Grid.Column="0" Padding="55,10,5,10" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Name}" FontSize="20" Grid.Column="1" Padding="110,10,5,10" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding City}" FontSize="20" Grid.Column="2" Padding="70,10,5,10" HorizontalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Where seems to be the problem?
Try this:
<Grid x:Name="BranchesGrid" Margin="12,0,-12,6" Grid.Row="2" Height="542" VerticalAlignment="Bottom">
<ListBox Height="530" HorizontalAlignment="Left" Margin="12,6,0,0" Name="listBox1" VerticalAlignment="Top" Width="456" Grid.ColumnSpan="4">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding ID}" FontSize="20" Grid.Column="0" Padding="55,10,5,10" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Name}" FontSize="20" Grid.Column="1" Padding="110,10,5,10" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding City}" FontSize="20" Grid.Column="2" Padding="70,10,5,10" HorizontalAlignment="Center"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>

list view population using only xaml

I read a lot about the listView and still cant understand...
I defined the following listView with 5 column, the first is label and the rest are texboxes.
I need to add 13 rows that every textbox and labels needs to be bind to something diffrent.
So I understand that listViewItem wont do it because every object in the list, binds to somethin else..
Thank you for your help.
<ListView DockPanel.Dock="Top" Width="607" Height="400" Margin="10 0" HorizontalAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="1" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="2" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="3" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="4" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="5" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
you really wane do something like this?
<Grid Height="100" HorizontalAlignment="Left" Margin="22,62,0,0" Name="listBox1" VerticalAlignment="Top" Width="607">
<Grid.ColumnDefinitions>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height='30'/>
<RowDefinition Height='30'/>
</Grid.RowDefinitions>
<!-- ROW 0-->
<Label Grid.Column='0' Grid.Row='0' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='0' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='0' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='0' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='0' Text='Text04'/>
<!--Row 1-->
<Label Grid.Column='0' Grid.Row='1' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='1' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='1' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='1' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='1' Text='Text04'/>
</Grid>
I finaly did a Grid in every item in the list like this:
<ListView DataContext="{Binding CurrentMonitorCalib}" Grid.Column="5" Grid.Row="3" Height="488" Width="444" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Cal Point" Width="80"/>
<GridViewColumn Header="Source" Width="90" />
<GridViewColumn Header="Failure Limit" Width="90" />
<GridViewColumn Header="Reference" Width="90" />
<GridViewColumn Header="# DaysLimit" Width="90" />
</GridView>
</ListView.View>
<ListViewItem>
<Grid Width="441" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Zero" Margin="5,0" />
<TextBox Grid.Column="1" Text="{Binding Path=ZeroSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=ZeroFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=ZeroRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=ZeroZNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
<ListViewItem>
<Grid Width="442" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Span" Margin="5,0"/>
<TextBox Grid.Column="1" Text="{Binding Path=SpanSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=SpanFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=SpanRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=SpanNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
and so on.....
thanks for your help!

Button alignment problem in listbox in WPF

I have a listbox containing itemtemplate like this
<ListBox Name="lstCompany" Grid.Column="0" MinWidth="200" Grid.Row="1" HorizontalAlignment="Stretch" Margin="2,2,2,2" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" ItemsSource="{Binding}" SelectionChanged="lstCompany_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<Grid Name="grid1" VerticalAlignment="Top" Margin="2" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding [0]}" FontWeight="Bold" />
<TextBlock Text="{Binding [1]}"></TextBlock>
<StackPanel.ToolTip>
<ToolTip>asdf</ToolTip>
</StackPanel.ToolTip>
</StackPanel>
</Grid>
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Right" DockPanel.Dock="Right">
<Button Content="X" Tag="{Binding [2]}" Width="20" Click="btnRemove_Click" Name="btnRemove1" HorizontalAlignment="Right"></Button>
</StackPanel>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This listbox is in first column of a grid which has a splitter.
Now problem is that I am not able to align the button to right side of listbox item.
One Grid is enough here. You only need one star-sized column (for content) and one Auto-sized column (for the button):
<ListBox Name="lstCompany" Grid.Column="0" MinWidth="200" Grid.Row="1" HorizontalAlignment="Stretch" Margin="2,2,2,2" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" ItemsSource="{Binding}" SelectionChanged="lstCompany_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate >
<Grid Name="grid1" VerticalAlignment="Top" Margin="2" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding [0]}" FontWeight="Bold"/>
<TextBlock Text="{Binding [1]}" ></TextBlock>
<StackPanel.ToolTip>
<ToolTip>asdf</ToolTip>
</StackPanel.ToolTip>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right">
<Button Content="X" Tag="{Binding [2]}" Width="20" Click="btnRemove_Click" Name="btnRemove1"></Button>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

WPF How to Scroll ListView embedded in Grid

I am trying to scroll a listview control in WPF which is embedded in a Grid layout control. I can't seem to achieve this. Any ideas anyone?
By the way i have set the following properties on the list view in the xaml markup:
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--Top Area-->
<GroupBox Grid.Row="0" Header="Price, Volume and Ratio Stats">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--Row 1-->
<TextBlock x:Name="tbSellInstrumentCode" Grid.Column="0" Grid.Row="0">Sell Share</TextBlock>
<TextBox x:Name="txtSellInstrumentCode" Grid.Column="1" Grid.Row="0" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbBuyInstrumentCode" Grid.Column="2" Grid.Row="0">Buy Share</TextBlock>
<TextBox x:Name="txtBuyInstrumentCode" Grid.Column="3" Grid.Row="0" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbTargetPriceRatio" Grid.Column="4" Grid.Row="0">Target Trigger</TextBlock>
<TextBox x:Name="txtTargetPriceRatio" Grid.Column="5" Grid.Row="0" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbTradedPriceRatio" Grid.Column="6" Grid.Row="0">Traded Price Ratio</TextBlock>
<TextBox x:Name="txtTradedPriceRatio" Grid.Column="7" Grid.Row="0" IsEnabled="False"></TextBox>
<!--Row 2-->
<TextBlock x:Name="tbBidPrice" Grid.Column="0" Grid.Row="1">Bid Price</TextBlock>
<TextBox x:Name="txtBidPrice" Grid.Column="1" Grid.Row="1" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbAskPrice" Grid.Column="2" Grid.Row="1">Ask Price</TextBlock>
<TextBox x:Name="txtAskPrice" Grid.Column="3" Grid.Row="1" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbMarketPriceRatio" Grid.Column="4" Grid.Row="1">Market Trigger</TextBlock>
<TextBox x:Name="txtMarketPriceRatio" Grid.Column="5" Grid.Row="1" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbTradedVolumeRatio" Grid.Column="6" Grid.Row="1">Traded Volume Ratio</TextBlock>
<TextBox x:Name="txtTradedVolumeRatio" Grid.Column="7" Grid.Row="1" IsEnabled="False"></TextBox>
<!--Row 3-->
<TextBlock x:Name="tbBidVolume" Grid.Column="0" Grid.Row="2">Bid Volume</TextBlock>
<TextBox x:Name="txtBidVolume" Grid.Column="1" Grid.Row="2" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbAskVolume" Grid.Column="2" Grid.Row="2">Ask Volume</TextBlock>
<TextBox x:Name="txtAskVolume" Grid.Column="3" Grid.Row="2" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbTradedSpread" Grid.Column="4" Grid.Row="2">Traded Spread</TextBlock>
<TextBox x:Name="txtTradedSpread" Grid.Column="5" Grid.Row="2" IsEnabled="False"></TextBox>
<TextBlock x:Name="tbTradedAmountRatio" Grid.Column="6" Grid.Row="2">Traded Amount Ratio</TextBlock>
<TextBox x:Name="txtTradedAmountRatio" Grid.Column="7" Grid.Row="2" IsEnabled="False"></TextBox>
</Grid>
</GroupBox>
<!--Middle Area-->
<GroupBox Grid.Row="1" Header="Average Price, Total Volumes and Averages Stats">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--Row 1-->
<TextBlock Grid.Column="0" Grid.Row="0">Total Sell Volume</TextBlock>
<TextBox x:Name="txtTotalSellVolume" Grid.Column="1" Grid.Row="0" IsEnabled="False"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="0">Total Buy Volume</TextBlock>
<TextBox x:Name="txtTotalBuyVolume" Grid.Column="3" Grid.Row="0" IsEnabled="False"></TextBox>
<!--Row 2-->
<TextBlock Grid.Column="0" Grid.Row="1">Total Sell Amount (ZAR)</TextBlock>
<TextBox x:Name="txtTotalSellAmount" Grid.Column="1" Grid.Row="1" IsEnabled="False"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="1">Total Buy Amount (ZAR)</TextBlock>
<TextBox x:Name="txtTotalBuyAmount" Grid.Column="3" Grid.Row="1" IsEnabled="False"></TextBox>
<!--Row 3-->
<TextBlock Grid.Column="0" Grid.Row="2">Average Sell Price (ZAR)</TextBlock>
<TextBox x:Name="txtAverageSellPrice" Grid.Column="1" Grid.Row="2" IsEnabled="False"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="2">Average Buy Price (ZAR)</TextBlock>
<TextBox x:Name="txtAverageBuyPrice" Grid.Column="3" Grid.Row="2" IsEnabled="False"></TextBox>
<!--Row 4-->
<TextBlock Grid.Column="0" Grid.Row="3">Number of Unfilled Orders</TextBlock>
<TextBox x:Name="txtNumberOfUnfilledOrders" Grid.Column="1" Grid.Row="3" IsEnabled="False"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="3">Slippage (ZAR)</TextBlock>
<TextBox x:Name="txtSlippage" Grid.Column="3" Grid.Row="3" IsEnabled="False"></TextBox>
</Grid>
</GroupBox>
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView x:Name="lvSellTrades" Grid.Column="0" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Date, StringFormat=hh:mm:ss tt}" Header="Date"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=AccountCode}" Header="Account Code"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat={}{0:N0}}" Header="Sell Price"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Volume, StringFormat={}{0:N0}}" Header="Sell Volume"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Amount, StringFormat=R {0:N2}}" Header="Amount"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="lvBuyTrades" Grid.Column="1" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Date, StringFormat=hh:mm:ss tt}" Header="Date"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=AccountCode}" Header="Account Code"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat={}{0:N0}}" Header="Buy Price"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Volume, StringFormat={}{0:N0}}" Header="Buy Volume"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Amount, StringFormat=R {0:N2}}" Header="Amount"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
Any help would be much appreciated.
From what i've gathered from this prior question, If your grid is hosted inside a stackpanel, it could cause issues.
Try to set VerticalAlignment property on ListView to Top. If this does not help try to wrap ListView with ScrollViewer (ListView.VerticalAlignment should have Top value).

Resources