ItemsControl layout with nested list - each wrapper under self - wpf

my goal is to put 3rd wrapper under the 2nd. For this layout I'm using mix of dockpanel + stackpanel.
1st wrapper is a stackpanel of label's
2nd wrapper is item control (list of members) with dockpanel as template
3rd wrapper is item control with dockpanel as template (nested list of addresses of each member)
View
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<Label Style="{StaticResource MinWidthLeft}" Content="Typ Adresu"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Imie"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Nazwisko"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Nazwa Firmy"/>
<Label Style="{StaticResource MinWidthLeft}" Content="NIP"/>
<Label Style="{StaticResource MinWidthLeft}" Content="REGON"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Ulica"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Adres"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Kod pocztowy"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Miasto"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Kraj"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Dodatkowe informacje"/>
</StackPanel>
<ItemsControl ItemsSource = "{Binding listContractorAddAddress}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<Button Style="{StaticResource MinWidth}" Content="Dodaj Adres" Command="{Binding Path=AddAddress}"/>
<TextBlock Style="{StaticResource MinWidth}" Text="{Binding Member.Login}"/>
<TextBlock Style="{StaticResource MinWidth}" Text="{Binding Member.Email}"/>
<ItemsControl ItemsSource = "{Binding Addresses}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<Button Style="{StaticResource MinWidth}" Content="Edytuj" Command="{Binding Path=EditAddress}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.TypAdresu}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Imie}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Nazwisko}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.NazwaFirmy}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.NIP}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.REGON}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Ulica}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Adres}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.KodPocztowy}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Miasto}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Kraj}"/>
<TextBlock Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.DodatkoweInformacje}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!--<DockPanel/>-->
<StackPanel DockPanel.Dock="Top" Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!--<DockPanel/>-->
<StackPanel DockPanel.Dock="Top" Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
</ScrollViewer>
</Grid>
I spent a lot of time on this, I tried to use:
only stackpanel with horizontal/vertical orientation (I made the
same layout as using dockpanel).
only grid, but this dosent work for me - disaster and waste of time
(it's hard for me to say what I was doing wrong, every row was the
right side and not one below the other)
Thanks!

I had to rebuild everything and reconsider the grid pattern:
<Grid IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<Label Style="{StaticResource MinWidthLeft}" Content="Typ Adresu"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Imie"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Nazwisko"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Nazwa Firmy"/>
<Label Style="{StaticResource MinWidthLeft}" Content="NIP"/>
<Label Style="{StaticResource MinWidthLeft}" Content="REGON"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Ulica"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Adres"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Kod pocztowy"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Miasto"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Kraj"/>
<Label Style="{StaticResource MinWidthLeft}" Content="Dodatkowe informacje"/>
</StackPanel>
<ItemsControl Grid.Row="1" Grid.Column="0" ItemsSource="{Binding listContractorAddAddress}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Style="{StaticResource MinWidth}" Content="Dodaj Adres" Command="{Binding Path=AddAddress}"/>
<TextBlock Style="{StaticResource MinWidth}" Text="{Binding Member.Login}"/>
<TextBlock Style="{StaticResource MinWidth}" Text="{Binding Member.Email}"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<ItemsControl ItemsSource="{Binding Addresses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Style="{StaticResource MinWidth}" Content="Edytuj" Command="{Binding Path=EditAddress}"/>
<TextBlock Grid.Column="1" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.TypAdresu}"/>
<TextBlock Grid.Column="2" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Imie}"/>
<TextBlock Grid.Column="3" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Nazwisko}"/>
<TextBlock Grid.Column="4" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.NazwaFirmy}"/>
<TextBlock Grid.Column="5" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.NIP}"/>
<TextBlock Grid.Column="6" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.REGON}"/>
<TextBlock Grid.Column="7" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Ulica}"/>
<TextBlock Grid.Column="8" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Adres}"/>
<TextBlock Grid.Column="9" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.KodPocztowy}"/>
<TextBlock Grid.Column="10" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Miasto}"/>
<TextBlock Grid.Column="11" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.Kraj}"/>
<TextBlock Grid.Column="12" Style="{StaticResource MinWidthLeft}" Text="{Binding MemberAddress.DodatkoweInformacje}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Html + css is much more intuitive for me than xaml.
Uff that was crazy 5h :)
Foggy Finder thank you for your interesting.
this is a template that helped me solve the problem

Related

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>

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}" />

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>

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