datepicker issue- calendar size is too big - wpf

The following xaml date picker (dropdown) calender and its days width is too big. how to reduce width of calender and days of calender.
Please help me to solve this issue
<Grid Grid.Column="0">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="134"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions >
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Client Name" Grid.Row="0" Grid.Column="0"/>
<TextBox Text="{Binding DataContext.client_name, ElementName=Parant}"
MaxLength="50"
Padding="2"
Height="25"
Grid.Row="0" Grid.Column="1"/>
<TextBlock Text="Building Location" Grid.Row="1" Grid.Column="0"/>
<TextBox MaxLength="255"
Text="{Binding DataContext.location, ElementName=Parant}"
Grid.Row="1"
AcceptsReturn="True"
TextWrapping="Wrap"
Height="40"
Grid.Column="1" />
<TextBlock Text="Date" Grid.Row="2" Grid.Column="0"/>
<!--<TextBox MaxLength="255"
Text="{Binding DataContext.survey_date, ElementName=Parant}"
Grid.Row="2" Grid.Column="1"/>-->
<DatePicker Name="DtpFromDate"
SelectedDate="{Binding DataContext.SurvayDatetime , ElementName=Parant}"
Margin="5"
Width="230"
HorizontalAlignment="Left"
Height="25" Grid.Row="2" Grid.Column="1" />
<!--<TextBlock Text="Edit Lock:" Grid.Row="3" Grid.Column="0"/>
<ComboBox ItemsSource= "{Binding DataContext.elockList, ElementName=Parant}"
SelectedValue="{Binding DataContext.elock, ElementName=Parant}"
Grid.Row="3" Grid.Column="1" />-->
<TextBlock Text="Turn Around Time" Grid.Row="3" Grid.Column="0"/>
<ComboBox ItemsSource="{Binding DataContext.turnaroundList, ElementName=Parant}"
SelectedValue ="{Binding DataContext.turnaround, ElementName=Parant}"
Height ="25"
Grid.Row="3"
Grid.Column="1"/>
please see the picture of calender, and give solution for solve this issue.
My date picker is shown like:

after adding calender custom style the problem solved

Related

Perform calculation in TexBox from values in 2 Texboxes binded do sliders

I have this code:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="300*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label x:Name="labelMultiplicador" Grid.Row="0" Grid.Column="0" Content="Multiplicador:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<Slider x:Name="sliderMultiplicador" Grid.Row="0" Grid.Column="1" Orientation="Horizontal" SmallChange="1" IsSnapToTickEnabled="True" Minimum="1" VerticalAlignment="Center" Height="1" MinHeight="30" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" MinWidth="300" Margin="5" TickPlacement="TopLeft" />
<TextBox x:Name="textBoxMultiplicador" Grid.Row="0" Grid.Column="2" Width="50" Text="{Binding ElementName=sliderMultiplicador,Path=Value}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MinHeight="30" />
<Label x:Name="labelMultiplicando" Grid.Row="1" Grid.Column="0" Content="Multiplicando:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<Slider x:Name="sliderMultiplicando" Grid.Row="1" Grid.Column="1" Orientation="Horizontal" SmallChange="1" IsSnapToTickEnabled="True" Minimum="1" VerticalAlignment="Center" MinHeight="30" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" MinWidth="300" Margin="5" Height="1" TickPlacement="TopLeft" />
<TextBox x:Name="textBoxMultiplicando" Grid.Row="1" Grid.Column="2" Width="50" Text="{Binding ElementName=sliderMultiplicando,Path=Value}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MinHeight="30" />
<Label x:Name="labelProduto" Grid.Row="2" Grid.Column="0" Content="Produto:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<TextBox x:Name="textBoxProduto" Grid.Row="2" Grid.Column="2" Width="50" Text="" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" MinHeight="30" />
</Grid>
I want to calculate the product (textBoxProduto) using the values from textBoxMultiplicador and textBoxMultiplicando.
I'm new to WPF so this might be a "stupid" question!!!
If i try to calculate the product using the textBoxMultiplicador_TextChanged event, for example, e get a "'System.NullReferenceException'".
What is the best approach in this case?
Thanks
Full example here: https://www.dropbox.com/s/e8w9t59vjhnqjbb/tabuada.zip?dl=0

doesn't wrap the text in the textbox in WPF

Got stuck up with wrap the text when user enters in the text box,used "MaxWidth to control the text box and wrap the text but it shrink the textbox size.am not sure how i have to strecth it,eventhoug am using HorizantalAlignment ="Stretch" but it doesn't match with the other text box.
If i don't wrap the text then the whole grid is moving to if the text is larger than the text box,is this anyway to fix the size and wrap the text please.
Here is my xaml code
<DockPanel Grid.Row="1">
<Grid Name="gLeftContent" Grid.Row="0" Background="Transparent" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="30" />
<RowDefinition Height="20"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0" />
<RowDefinition Height="25" />
<!-- Row 14 -->
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<TextBox
Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Width="{Binding ActualWidth, ElementName=tbName}" **//used ActualWidth but it shrinks the text box and doesn't match with the other text box.**
Grid.Column="1"
Grid.Row="5"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbSlug_LostFocus"
>
<TextBox
Name="tbHeadline"
Text="{Binding SelectedStory.Headline, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="6"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbHeadline_LostFocus"
/>
</TextBox>
<ItemsControl
Grid.Column="1"
Grid.Row="14"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.MetadataGenerateImagesRegion}"/>
</Grid>
</DockPanel>
Thanks in Advance.
Let's start again with a clean answer:
<TextBox Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Width="Auto" Height="Auto"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="2"
TextWrapping="Wrap" AcceptsReturn="True"
LostFocus="tbSlug_LostFocus" >
Please replace it entirely in your code to avoid any omision.
You need to set the RowDefinition Height="Auto" do it can grow to fit additional lines.
Definitely should not be binding width to itself.
Try
<TextBox
Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="5"
Grid.ColumnSpan="2"
TextWrapping="Wrap"
HorizontalAlignment="Stretch"
LostFocus="tbSlug_LostFocus" />
Try to add to your textbox:
AcceptsReturn="True"
Although your control may present wrapped text, currently it is unable to accept enter keystrokes.

Datatemplate binding should work but doesn't. is there an external source for this?

I have a content control that doesn't show the binding data only the static texts:
<ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3"
ContentTemplate="{StaticResource detailsAdListingTemplate}"
Margin="9,0,0,0"/>
<DataTemplate x:Key="detailsAdListingTemplate" >
<Grid Margin="5,5,5,10">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="113"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0"
Name="title"
Style="{StaticResource smallTitleStyle}">Title:</TextBlock>
<TextBlock Name="DescriptionDTKey" Grid.Row="0" Grid.Column="1"
Text="{Binding Path=Title}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,8,0"
Name="price"
Style="{StaticResource smallTitleStyle}">Price:</TextBlock>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
<TextBlock Text="$" Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Name="PriceDTKey"
Text="{Binding Path=Price}"
Style="{StaticResource textStyleTextBlock}"/>
</StackPanel>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,8,0"
Name="date"
Style="{StaticResource smallTitleStyle}">Date:</TextBlock>
<TextBlock Name="DateDTKey" Grid.Row="2" Grid.Column="1"
Text="{Binding Path=Date}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Margin="0,0,8,0"
Name="subCategory"
Style="{StaticResource smallTitleStyle}">Subcategory: </TextBlock>
<TextBlock Name="SubCategoryDTKey" Grid.Row="3" Grid.Column="1"
Text="{Binding Path=SubCategory.Name}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Margin="0,0,8,0"
Name="owner"
Style="{StaticResource smallTitleStyle}">Owner:</TextBlock>
<TextBlock Name="OwnerDTKey" Grid.Row="4" Grid.Column="1"
Text="{Binding Path=User.Username}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="5" Grid.Column="0" Margin="0,0,8,0"
Name="location"
Style="{StaticResource smallTitleStyle}">Location: </TextBlock>
<TextBlock Name="locationDTKey" Grid.Row="5" Grid.Column="1"
Text="{Binding Path=Location}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="6" Grid.Column="0" Margin="0,0,8,0"
Name="Body"
Style="{StaticResource smallTitleStyle}">Body:</TextBlock>
<TextBlock Name="BodyDTKey" Grid.Row="6" Grid.Column="1"
Text="{Binding Path=Body}"
Style="{StaticResource textStyleTextBlock}"/>
</Grid>
</DataTemplate>
I set the Detail.DataContext=ad; (where ad is a proper Ad object that has all the data and all the properties in the {Binding Path=Property}.
IT USED TO WORK FINE. I don't remember editing it. I don't know what I did to the application but now the data template
only shows the static texts - for example Title: but no actual title.So only the bindings don't work.
I'm sure there is nothing wrong with the xaml code above and it should work.
Is there an "external" other source that may be causing this problem?
ContentTemplate is the template used to display ContentControl.Content, which you are leaving as null
Either set Detail.Content = ad; (instead of Detail.DataContext), or bind your ContentControl.Content property to the current DataContext.
<ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3" Margin="9,0,0,0"
Content="{Binding }"
ContentTemplate="{StaticResource detailsAdListingTemplate}" />

How to better present this data in WPF grid?

I have some data presented in WPF Grid as follows:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="150"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Style="{StaticResource SectionNumber}" Content="1.3"/>
<Label Grid.Row="1" Grid.Column="0" Margin="5 2">Number of grid in X:</Label>
<Label Grid.Row="1" Grid.Column="1" Margin="5 2">NX</Label>
<lib:NumericTextBox Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" Text="{Binding Parameters.NX}"/>
<Label Grid.Row="2" Grid.Column="0" Margin="5 2">Number of grid in Y:</Label>
<Label Grid.Row="2" Grid.Column="1" Margin="5 2">NY</Label>
<lib:NumericTextBox Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" Text="{Binding Parameters.NY}"/>
<Label Grid.Row="3" Grid.Column="0" Margin="5 2">Type of data:</Label>
<Label Grid.Row="3" Grid.Column="1" Margin="5 2">MD</Label>
<ComboBox x:Name="cmbMD" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" SelectedItem="{Binding Data.MD}"/>
<Label Grid.Row="4" Grid.Column="0" Margin="5 2">Data value:</Label>
<Label Grid.Row="4" Grid.Column="1" Margin="5 2">D</Label>
<TextBox Grid.Row="4" Grid.Column="2" Margin="5 2" Text="{Binding Data.D}"/>
<TextBox Grid.Row="4" Grid.Column="3" Margin="5 2" Text="{Binding Unit.LengthUnit, Mode=OneWay}" IsReadOnly="True" />
...
The problem is that I have hundreds of rows to write. In WinForms, I would probably write a user control to present a row of data, and I just need one line of code to create a row.
How can I simplify it here? Can DataTemplate help somehow? I know i can use DataTemplate in a listbox to make it easier. However, I need the columns to be aligned vertically, so I think Grid is the only way to go, right?
WPF ListView or DataGrid is the way to go.
I am writing a simple DataGrid XAML for you.
<DataGrid ItemsSource="{Binding YourCollection}" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="YourColumnHeader1" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Property1}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="YourColumnHeader2" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<lib:NumericTextBox Text="{Binding Property2}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
It sounds like what you want is a DataGrid, not a Grid.

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