WPF How to Scroll ListView embedded in Grid - wpf

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).

Related

Merge Grid column Header in WPF

I have a wpf Grid, i want to merge the two Column Header.I have tried using the below code the problem here is the column spawn to 2 but in the cell is one that why the for each column grid line is not visible.Can any body answer the better solution to achieve this
<toolkit:DataGridTemplateColumn>
<toolkit:DataGridTemplateColumn.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" Text="Missing from FISAP Summary Part II Section F"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="A" Width="60" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="C" Width="60" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="2" Grid.Row="1" Text="D" Width="60" HorizontalAlignment="Center"/>
</Grid>
</toolkit:DataGridTemplateColumn.Header>
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=A}" Width="60" HorizontalAlignment="Right" />
<TextBlock Grid.Column="1" Text="{Binding Path=C}" Width="60" HorizontalAlignment="Right" />
<TextBlock Grid.Column="2" Text="{Binding Path=D}" Width="60" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>

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>

Set two children elements with equal width, each with 50% in wpf

If I have two elements in a stackpanel:
<StackPanel Margin="2,2,2,2" Orientation="Horizontal">
<TextBlock Grid.Column="0" Text="{Binding Name}" />
<TextBox Grid.Column="1" Text="{Binding Age}"/>
</StackPanel>
How can I set them with the width equally 50%,50%?
To answer your comment
<Grid>
<!-- Define Columns -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Name}" />
<TextBox Grid.Column="1" Text="{Binding Age}"/>
</Grid>
use UnformGrid with columns 2 or Grid with 2 columns
<UniformGrid Columns="2">
<TextBox></TextBox>
<TextBox></TextBox>
</UniformGrid>
or
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{Binding Name}" />
<TextBox Grid.Column="1"
Text="{Binding Age}" />
</Grid>

Scroll Viewer not visible in wpf DataGrid

I have a datagrid in a grid but the scrollviewer is not visibile even though I made it auto.
Below in my code. I can't figure out where's the problem.
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Doctor Name" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Doctor Address" Grid.Row="1" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Entry Note" Grid.Row="2" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Join Date" Grid.Row="3" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Default Discount" Grid.Row="4" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Discount Valid Till" Grid.Row="5" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Employee Name" Grid.Row="6" Grid.Column="0" Margin="5,5,0,0"/>
<Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Report Type" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<ComboBox Grid.Row="0" Grid.Column="1" Name="cmbReportType" Text="{Binding CurrentEntity.ReportType}"/>
<Button Grid.Row="0" Grid.Column="2" Name="btnAddDetail" Content="Add Details" Command="{Binding AddDetailsCommand}"/>
</Grid>
<TextBox Grid.Row="0" Grid.Column="1" Margin="5,5,0,0" Width="190" Name="txtDocName" Text="{Binding CurrentEntity.RefName}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="75" Name="txtDocAddress" Text="{Binding CurrentEntity.RefAddress}"/>
<TextBox Grid.Row="2" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="100" Name="txtEntryNote" Text="{Binding CurrentEntity.EntryNotes}"/>
<Custom:DatePicker Grid.Row="3" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpJoinDate" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DateStarted}" SelectedDateFormat="Short"/>
<TextBox Grid.Row="4" Grid.Column="1" Height="25" Width="75" Name="txtDefaultDiscount" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Top" Text="{Binding CurrentEntity.DefaultDiscount}"/>
<Custom:DatePicker Grid.Row="5" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpValidTill" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DefaultDiscountValidTill}" SelectedDateFormat="Short"/>
<ComboBox Grid.Row="6" Grid.Column="1" Margin="5,3,0,0" Width="190" Height="30" Name="cmbEmployeeName" ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedIndex="{Binding SelecteIndex}">
</ComboBox>
<Custom:DataGrid Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding XYZ}" AutoGenerateColumns="False" Name="grdTestDept">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding dep_id}" Width="40" Header="ID"/>
<Custom:DataGridTextColumn Binding="{Binding dep_name}" Width="125" Header="Name"/>
<Custom:DataGridTextColumn Binding="{Binding default_data}" Width="100" Header="Default Data"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
<Grid Grid.Row="0" Grid.Column="1" Grid.RowSpan="9">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="43"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="150"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="34*" ></RowDefinition>
<RowDefinition Height="337.88*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Name: " Grid.Row="0" Grid.Column="0" Margin="5,4,0,0" />
<cc:ValueEnabledCombo Grid.Column="1" x:Name="cmbfilEmployeeName" Width="150" Height="30" Margin="5,4,0,0" VerticalAlignment="Top" SelectedIndex="0"
ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedValuePath="EmployeeId" cc:ValueEnabledCombo.SelectionChanged="{Binding SelectionChangedCommand}">
</cc:ValueEnabledCombo>
<Button Grid.Column="2" Name="btnReport" Width="50" Content="Report" Height="28" Margin="5,4,0,0" Command="{Binding ReportCommand}" VerticalAlignment="Top" />
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
<Custom:DataGrid ItemsSource="{Binding DoctorList}" AutoGenerateColumns="False" Name="grdDoctor" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding RefName}" Width="Auto" Header="Doctor Name"/>
<Custom:DataGridTextColumn Binding="{Binding EmployeeFullName}" Width="Auto" Header="Employee Name"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
</Grid>
</Grid>
Kent Boogaart posted the answer here:
how can I enable scrollbars on the WPF Datagrid?
Put the DataGrid in a Grid, DockPanel, ContentControl or directly in the Window. A vertically-oriented StackPanel will give its children whatever vertical space they ask for - even if that means it is rendered out of view.
My note: It's probably best not to set the max height and width. Leave those alone and let WPF take care of the resizing for you.

Can't get WPF Listview to collapse when expanders in the listview collapse

I have a wpf ListView with two Expanders in it. When the expanders expand the listview makes room for the content. When they collapse the listview does not "take back" that extra space. I have set HorizontalAlignment and VerticalAlignment to Stretch everywhere. Is there a way to do this? The Details and Chart columns contain the expanders. See code below. Thanks.
Here at
<Window.Resources>
<DataTemplate x:Key="StockPriceChangeCell">
<StackPanel Orientation="Horizontal">
<Label Name="stockPriceChangeValue" Foreground="{Binding StockPriceChangeColor}" Content="{Binding StockPriceChange}" Width="Auto"></Label>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DetailsCell">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Expander Header="Details..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Name="stockDetailGrid" Background="Beige" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False">
<Grid.RowDefinitions>
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="96*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Name="previousClosePrompt" FontWeight="Bold" FontSize="12" Height="28" Width="Auto">Prev Close:</Label>
<Label Grid.Row="0" Grid.Column="1" Name="previousCloseValue" FontWeight="Bold" FontSize="12" Height="28" Width="Auto" Content="{Binding StockDetails.PreviousClose}"></Label>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator3" Margin="0,2" />
<Label Grid.Row="2" Grid.Column="0" Name="openPricePrompt" FontWeight="Bold" FontSize="12" Height="28">Open:</Label>
<Label Grid.Row="2" Grid.Column="1" Name="openPriceValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.OpeningPrice}"></Label>
<Separator Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator5" Margin="0,2" />
<Label Grid.Row="4" Grid.Column="0" Name="yearlyTargetEstimatePrompt" FontWeight="Bold" FontSize="12" Height="28">1y Target Est:</Label>
<Label Grid.Row="4" Grid.Column="1" Name="yearlyTargetEstimateValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearTargetEstimate}"></Label>
<Separator Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator6" Margin="0,2" />
<Label Grid.Row="6" Grid.Column="0" Name="stockDaysRangePrompt" FontWeight="Bold" FontSize="12" Height="28">Day's Range:</Label>
<Label Grid.Row="6" Grid.Column="1" Name="stockDaysRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DaysRange}"></Label>
<Separator Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator7" Margin="0,2" />
<Label Grid.Row="8" Grid.Column="0" Name="stockYearsRangePrompt" FontWeight="Bold" FontSize="12" Height="28">52wk Range:</Label>
<Label Grid.Row="8" Grid.Column="1" Name="stockYearsRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearsRange}"></Label>
<Separator Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator8" Margin="0,2" />
<Label Grid.Row="10" Grid.Column="0" Name="averageVolumePrompt" FontWeight="Bold" FontSize="12" Height="28">Avg Vol (3m):</Label>
<Label Grid.Row="10" Grid.Column="1" Name="averageVolumeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.AverageVolume}"></Label>
<Separator Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator9" Margin="0,2" />
<Label Grid.Row="12" Grid.Column="0" Name="marketCapPrompt" FontWeight="Bold" FontSize="12" Height="28">Market Cap:</Label>
<Label Grid.Row="12" Grid.Column="1" Name="marketCapValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.MarketCap}"></Label>
<Separator Grid.Row="13" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator10" Margin="0,2" />
<Label Grid.Row="14" Grid.Column="0" Name="priceEarningRatioPrompt" FontWeight="Bold" FontSize="12" Height="28">P/E (ttm):</Label>
<Label Grid.Row="14" Grid.Column="1" Name="priceEarningRatioValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.PriceEarningsRatio}"></Label>
<Separator Grid.Row="15" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator11" Margin="0,2" />
<Label Grid.Row="16" Grid.Column="0" Name="earningsPerSharePrompt" FontWeight="Bold" FontSize="12" Height="28">EPS (ttm):</Label>
<Label Grid.Row="16" Grid.Column="1" Name="earningsPerShareValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.EarningsPerShare}"></Label>
<Separator Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator12" Margin="0,2" />
<Label Grid.Row="18" Grid.Column="0" Name="dividendYieldPrompt" FontWeight="Bold" FontSize="12" Height="28">Div & Yield:</Label>
<Label Grid.Row="18" Grid.Column="1" Name="dividendYieldValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DividendYield}"></Label>
</Grid>
</Expander>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ChartCell">
<StackPanel>
<Expander Header="Chart..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image Name="stockGraph" Stretch="None" Source="{Binding StockChart}"/>
</Expander>
</StackPanel>
</DataTemplate>
</Window.Resources>
Here is the listview:
<TabItem Name="myStocksTab" Header="My Stocks" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Name="myStocksTabContainerPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Label Name="myStocksPrompt" Foreground="GhostWhite" Background="DarkBlue" FontSize="16" FontWeight="Bold">My Stocks</Label>
<ListView Name="stocksUIList" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Header="Action" CellTemplate="{StaticResource ButtonsCell}" Width="Auto"/>
<GridViewColumn Header="Company/Stock Symbol" Width="Auto" DisplayMemberBinding="{Binding CompanyName}"/>
<GridViewColumn Header="Last Trade" Width="Auto" DisplayMemberBinding="{Binding LastTrade}"/>
<GridViewColumn Header="Trade Time" Width="Auto" DisplayMemberBinding="{Binding StockDetails.TradeTime}"/>
<GridViewColumn Header="Change" CellTemplate="{StaticResource StockPriceChangeCell}"/>
<GridViewColumn Header="Volume" Width="Auto" DisplayMemberBinding="{Binding TradingVolume}"/>
<GridViewColumn Header="Details" CellTemplate="{StaticResource DetailsCell}" Width="215"/>
<GridViewColumn Header="Chart" CellTemplate="{StaticResource ChartCell}" Width="215"/>
</GridView>
</ListView.View>
</ListView>
<Button Name="addStock" FontSize="14" FontWeight="Bold" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Click="AddCompanyStock">Add Stock...</Button>
</StackPanel>
I know this is an older post, but I was looking for a solution to this problem and wanted to update it with my solution.
After some searching I was able to fix it by using the solution found here: ListView with nested Expander not collapsing
Basically I was using a ListView with Expanders in the Item Template. When collapsing the expander would not resize properly. Also when the expander content was larger than the ListView, the scroll would not work properly.
The fix was simply replacing ListView with ItemsControl and putting the ItemsControl inside a ScrollViewer.
It sounds like there may be a layout bug of sorts in the ListView. Have you tried calling InvalidateVisual() on the ListView in the Collapsed event of either of the expanders? That may do the trick.

Resources