WPF Labels 2-n in StackPanel not visible - wpf

I am going through the tutorial here and for whatever reason, the labels for FirstName, LastName, and City are not visible, neither at design time nor at runtime. I've tried deleting them and re-adding and I get the same result. Can anyone see what is causing them to be hidden?
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="73*"/>
<RowDefinition Height="247*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="259*"/>
<ColumnDefinition Width="258*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnSave" Content="Save" Grid.Column="1" HorizontalAlignment="Right" Margin="0,10,10,0" Width="60" Height="22" VerticalAlignment="Top"/>
<Button x:Name="btnRevert" Content="Revert" Grid.Column="1" HorizontalAlignment="Right" Margin="0,10,86,0" Width="60" RenderTransformOrigin="-0.047,0.36" Height="22" VerticalAlignment="Top"/>
<Button x:Name="btnAdd" Content="Add" Grid.Column="1" HorizontalAlignment="Right" Margin="0,10,162,0" VerticalAlignment="Top" Width="60"/>
<Button x:Name="btnDelete" Content="Delete" HorizontalAlignment="Right" Margin="0,10,238,0" VerticalAlignment="Top" Width="60" RenderTransformOrigin="-1.521,0.477" Grid.Column="1"/>
<Button x:Name="btnFirst" Content="|<" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="35"/>
<Button x:Name="btnFirst_Copy" Content="|<" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="35"/>
<Button x:Name="btnPrevious" Content="<" HorizontalAlignment="Left" Margin="54,10,0,0" VerticalAlignment="Top" Width="35"/>
<Button x:Name="btnNext" Content=">" HorizontalAlignment="Left" Margin="94,10,0,0" VerticalAlignment="Top" Width="35"/>
<Button x:Name="btnLast" Content=">|" HorizontalAlignment="Left" Margin="134,10,0,0" VerticalAlignment="Top" Width="35" RenderTransformOrigin="4.102,1.005"/>
<StackPanel HorizontalAlignment="Left" Height="28" Grid.Row="1" VerticalAlignment="Top" Width="304">
<Label x:Name="lblCustomerID" Content="Customer ID" Height="28"/>
<Label x:Name="lblFirstName" Content="First Name" Height="28"/>
<Label x:Name="lblLastName" Content="Last Name" Height="28"/>
<Label x:Name="lblCity1" Content="City" Height="28"/>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Left" Height="251" Grid.Row="1" VerticalAlignment="Top" Width="297">
<TextBox x:Name="txtCustomerID" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=CustomerID, Mode=OneWay}"/>
<TextBox x:Name="txtLastName" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=LastName}"/>
<TextBox x:Name="txtFirstName" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=FirstName}"/>
<TextBox x:Name="txtCity" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=City}"/>
</StackPanel>
</Grid>

Remove your StackPanel's Height. Let it fill its height automatically. You set it to 28 which makes the other children get cutted off.
<StackPanel HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="304">
<Label x:Name="lblCustomerID" Content="Customer ID" Height="28"/>
<Label x:Name="lblFirstName" Content="First Name" Height="28"/>
<Label x:Name="lblLastName" Content="Last Name" Height="28"/>
<Label x:Name="lblCity1" Content="City" Height="28"/>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="297">
<TextBox x:Name="txtCustomerID" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=CustomerID, Mode=OneWay}"/>
<TextBox x:Name="txtLastName" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=LastName}"/>
<TextBox x:Name="txtFirstName" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=FirstName}"/>
<TextBox x:Name="txtCity" Height="28" TextWrapping="Wrap" Width="Auto" Text="{Binding Path=City}"/>
</StackPanel>

Related

Orientation of WPF status bar and label are in wrong place when the window is maximised

In my serial port WPF application , the labels (BaudRate,Parity,DataBits and stopBit) and the StatusBar (for displaying PortStatus) are in wrong place when I maximise the window.
I would like to have suggestion from expertise to resolve my issue.
So please let me know if I can make any changes/edit on my xaml file to have these orientation on the same place as it is in Normal window mode.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SerialReadAndWrite"
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="ATR220ReadAndWrite.MainWindow"
mc:Ignorable="d"
Title="ATR220ReadAndWrite" Height="450" Width="800">
<Grid Margin="0,0,-71,-107">
<ComboBox x:Name="ComPortComboBox" HorizontalAlignment="Left" Height="14" Margin="115,20,0,0" VerticalAlignment="Top" Width="98" SelectionChanged="ComPort_SelectionChanged" DropDownOpened="ComPort_DropDownOpened" VerticalContentAlignment="Stretch" IsSynchronizedWithCurrentItem="False" FontSize="9" FontFamily="Arial"/>
<Label Content="PortNumber :" HorizontalAlignment="Left" Margin="21,14,0,0" VerticalAlignment="Top"/>
<Label Content="PortSettings :" HorizontalAlignment="Left" Margin="21,58,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.546,3.143" FontSize="10" FontFamily="Arial"/>
<Image HorizontalAlignment="Left" Height="26" Margin="359,14,0,0" VerticalAlignment="Top" Width="29" RenderTransformOrigin="-0.23,0.36"/>
<ComboBox x:Name="BaudRateComboBox" HorizontalAlignment="Left" Margin="115,84,0,0" VerticalAlignment="Top" Width="98" Height="17" SelectionChanged="BaudRate_SelectionChanged" IsEnabled="False" IsReadOnly="True" FontSize="9" FontFamily="Arial">
<System:String>115200</System:String>
<System:String>57600</System:String>
<System:String>38400</System:String>
<System:String>19200</System:String>
<System:String>14400</System:String>
<System:String>9600</System:String>
<System:String>4800</System:String>
</ComboBox>
<ComboBox x:Name="ParityComboBox" HorizontalAlignment="Left" Height="17" Margin="308,86,0,0" VerticalAlignment="Top" Width="98" SelectionChanged="Parity_SelectionChanged" IsEnabled="False" FontSize="9" FontFamily="Arial">
<System:String>Even</System:String>
<System:String>Mark</System:String>
<System:String>None</System:String>
<System:String>Odd</System:String>
<System:String>Space</System:String>
</ComboBox>
<ComboBox x:Name="DataBitsComboBox" HorizontalAlignment="Left" Height="17" Margin="115,125,0,0" VerticalAlignment="Top" Width="98" SelectionChanged="DataBits_SelectionChanged" IsEnabled="False" FontSize="8" FontFamily="Arial">
<System:String>5</System:String>
<System:String>6</System:String>
<System:String>7</System:String>
<System:String>8</System:String>
</ComboBox>
<ComboBox x:Name="StopBitsComboBox" HorizontalAlignment="Left" Height="17" Margin="308,123,0,0" VerticalAlignment="Top" Width="98" SelectionChanged="StopBits_SelectionChanged" IsEnabled="False" FontSize="10" FontFamily="Arial">
<System:String>One</System:String>
<System:String>Two</System:String>
<System:String>OnePointFive</System:String>
</ComboBox>
<Label Content="Baudrate :" HorizontalAlignment="Center" Margin="47,81,753,423" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Height="22" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="10" FontStyle="Italic" Width="63"/>
<Label Content="Parity :" HorizontalAlignment="Center" Margin="234,81,573,423" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Height="22" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="10" FontStyle="Italic" Width="56"/>
<Label Content="DataBits :" HorizontalAlignment="Center" Margin="48,123,753,382" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Height="22" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="10" FontStyle="Italic" Width="62"/>
<Label Content="StopBit :" HorizontalAlignment="Center" Margin="238,123,567,382" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Height="22" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="10" FontStyle="Italic" Width="58"/>
<Button x:Name="ConnectButton" Content="Connect" HorizontalAlignment="Left" Margin="308,20,0,0" VerticalAlignment="Top" Width="75" Click="ConnectButton_Click" IsEnabled="False" Height="14" FontSize="10" FontFamily="Arial"/>
<Label Content="ProtocolCustomWndow :" HorizontalAlignment="Left" Margin="21,172,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.546,3.143" FontSize="10" FontFamily="Arial"/>
<ComboBox x:Name="ProtocolTypeComboBox" HorizontalAlignment="Left" Height="14" Margin="141,177,0,0" VerticalAlignment="Top" Width="98" SelectionChanged="ProtocolTypeComboBox_SelectionChanged" VerticalContentAlignment="Stretch" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" FontSize="9" FontFamily="Arial" IsEnabled="False">
<System:String>WLink</System:String>
</ComboBox>
***<StatusBar HorizontalAlignment="Left" Height="28" Margin="0,396,0,0" VerticalAlignment="Top" Width="794">
<StatusBarItem FontSize="9" FontFamily="Arial" TextOptions.TextHintingMode="Fixed">
<TextBlock Name= "PortStatus"/>
</StatusBarItem>
</StatusBar>***
</Grid>
</Window>
Images of the correct and wrong pics are attached.
wrong position
Wrong Position
Correct position
Correct position
Try something like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="PortNumber :" HorizontalAlignment="Center"/>
<ComboBox FontSize="9" FontFamily="Arial" Grid.Column="1">
<ComboBoxItem IsSelected="True">COM 3</ComboBoxItem>
</ComboBox>
<Button Content="Connect" Grid.Row="0" Grid.Column="3"></Button>
<TextBlock Text="PortSettings :" FontSize="10" FontFamily="Arial" Grid.Row="1" HorizontalAlignment="Center"/>
<TextBlock Text="Baudrate :" FontStyle="Italic" Grid.Row="2" HorizontalAlignment="Center"/>
<ComboBox IsEnabled="False" IsReadOnly="True" FontSize="9" FontFamily="Arial" Grid.Row="2" Grid.Column="1">
<System:String>115200</System:String>
<System:String>57600</System:String>
<System:String>38400</System:String>
<System:String>19200</System:String>
<System:String>14400</System:String>
<System:String>9600</System:String>
<System:String>4800</System:String>
</ComboBox>
<TextBlock Text="Parity :" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center"/>
<ComboBox Grid.Row="2" Grid.Column="3"/>
</Grid>
Pay special attention to use of Grid.Row and Grid.Column, you will need to set the Horizontal Alignment on these elements but this will show you how to position things in WPF.

Keeping correct XAML layout when browser is resized

I have a XAML window that the layout is done using a main grid. The problem is when the browser is resized the controls in the second and third columns move to the right and the window's layout is no longer correct. I have pasted the XAML below. I think the layout of a WPF window should be grid based with all controls residing in the window's master grid. Is this the proper layout design for WPF or is there a different recommended layout pattern?
<Window x:Class="MasterPage.Intake1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage.View"
Title="Intake 1" Height="900" Width="1000" Background="#FFD9DDE8" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="190*"/>
<RowDefinition Height="275*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="300*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0">
<Image Source="Images\header.jpg" Height="47" Margin="0,0,0,0" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Grid.Column="0" Height="80" Width="350" Grid.ColumnSpan="1" Grid.Row="1" Margin="0,-23,0,0">
<Image Source="Images\DSPASS_logo.png" Stretch="Fill" DockPanel.Dock="Top" Height="70" />
</StackPanel>
<StackPanel Grid.Column="4" Grid.Row="1" Grid.ColumnSpan="1" Margin="0,0,0,0">
<TextBlock FontSize="15" Margin="0,0,0,0" Height="25" Width="300" TextWrapping="WrapWithOverflow">
<Label FontSize="10" Name="Namelabel" Width="250" FontWeight="Bold" Foreground="#1664A1" Content="Welcome to DS PASS:"/>
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="10,10,0,0" Height="290" Width="975" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.RowSpan="1">
<Label Height="36" FontSize="16" Content="Post Identification" Background="#FF014E7E" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_wordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="ApplicantType_TextBlock" Text="Applicant Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_integerWordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="textBlockIntegerWordLength" Text="Person Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxIntegerWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_Post" Orientation="Horizontal" Margin="235,0,200,20">
<TextBlock Height="20" x:Name="Post_TextBlock" Text="Post" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="Post_TextBox" Width="400" Margin="10,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Height="130" Margin="15,-120,0,0" VerticalAlignment="Top" Grid.ColumnSpan="3" >
<Label Height="36" FontSize="16" Content="Applicant Employment" Background="#FF004A78" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_max1" Orientation="Vertical" Margin="1,0,355,0">
<TextBlock Height="20" x:Name="maxTextBlock1" Text="Employee ID" Width="100" Foreground="Black" Margin="0,15,459,5" TextAlignment="Right"/>
<TextBox Height="25" x:Name="maxTextBox1" Width="400" Margin="0,-5,90,25"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Orientation="Vertical" HorizontalAlignment="Left" Height="330" Margin="0,10,0,0" VerticalAlignment="Top" Width="965" Grid.RowSpan="2">
<Label Height="36" FontSize="16" Content="English Version of Name" Background="#FF005183" Grid.Row="4" FontWeight="Bold" Margin="10,10,0,0" Foreground="White" Padding="4,5,5,5"/>
<StackPanel x:Name="_LastName" Orientation="Vertical">
<TextBlock Height="20" x:Name="LastName_TextBlock" Text="Last Name/Surname" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="LastName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_FirstName" Orientation="Vertical">
<TextBlock Height="20" x:Name="FirstName_TextBlock" Text="First Name" Margin="55,0,459,0" TextAlignment="Left"/>
<TextBox Height="25" x:Name="FirstName_TextBox" Width="500" Margin="55,0,459,0"/>
</StackPanel>
<StackPanel x:Name="_MiddleName" Orientation="Vertical">
<TextBlock Height="20" x:Name="MiddleName_TextBlock" Text="Middle Name" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="MiddleName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_ExtendedName" Orientation="Vertical">
<TextBlock Height="20" x:Name="ExtendedName_TextBlock" Text="Extended name (Tribal, Jr., III, etc.)" Margin="55,5,372,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Extended_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.RowSpan="4" Grid.Column="4" HorizontalAlignment="Left" Height="230" Margin="-250,400,0,0" Width="480" Grid.ColumnSpan="1">
<StackPanel x:Name="_Aliases" Orientation="Vertical" Margin="-15,0,0,0" Height="144">
<TextBlock Height="20" x:Name="Aliases_TextBlock" Text="Aliases" Margin="40,-5,0,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Aliases_TextBox" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox1" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox2" Width="500" Margin="43,5"/>
</StackPanel>
</StackPanel>
<!--<Label HorizontalAlignment="Left" Margin="4,132,0,0" Grid.Row="3" VerticalAlignment="Top" Background="#FF72C772" Grid.ColumnSpan="3" Width="1242" Height="36"/>
<Button Content="Continue" Grid.Column="2" HorizontalAlignment="Left" Margin="16,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125" Click="Page1_Continue_Click"/>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="336,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125"/>-->
<Label HorizontalAlignment="Left" Margin="4,400,0,0" Grid.Row="4" VerticalAlignment="Top" Background="#FF52BB52" Grid.ColumnSpan="3" Width="983" Height="36">
</Label>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="150,408,0,0" Grid.Row="5" VerticalAlignment="Top" Width="125" />
<Button x:Name="ContinueButton_Page2" Content="Continue" Grid.Column="1" Width="125" Grid.Row="5" VerticalAlignment="Top" Margin="200,408,0,0" Grid.ColumnSpan="2" Click="btnContinue_Click"/>
</Grid>
</Window>
When you want control of the alignment during resizing, think Grid. In more complex situations, think Grids inside a Grid. A picture says it better
You have your MainGrid with only rows, no columns. The blue headers get rows of their own and
the orange containers are Grids themselves (with possibly a margin left and right).
Now you shouldn't try to divide the available space with all "...*" width values.
In this example you could use it for dead space only, e.g. the yellow columns with Width="*".
The blue columns would be Width="Auto" (or pixels).
Topping it off with a MinWidth for the Window corresponding with the width you need for the bottom Grid. Also consider wrapping your MainGrid in a ScrollViewer.
What I needed was to not allow resizing of the web browser. To do this I removed the minimize/maximize buttons To do that I used the following attribute:
ResizeMode="NoResize"

Textbox Border Not Showing - WPF

The textbox top and bottom border is not showing.
I have provided the entire XAML code for the main window. I have tried increasing the BorderThickness and also changed the BorderBrush. That did not work.
XAML:
<Window x:Class="WpfApplication6.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication6"
mc:Ignorable="d"
Title="Activation Window" Height="300" Width="518.797">
<Grid>
<TextBox x:Name="txtFirstDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="23,171,0,76" BorderThickness="1" BorderBrush="Black" />
<TextBox x:Name="txtSecondDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="81,171,0,76"/>
<TextBox x:Name="txtThirdDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="138,171,0,76"/>
<TextBox x:Name="txtFourthDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="195,171,0,76"/>
<TextBox x:Name="txtFifthDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="252,171,0,76"/>
<Label x:Name="label" Content="Product key:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,142,0,0"/>
<TextBox x:Name="txtFirstDigit_Copy" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="274" Margin="23,111,0,136" />
<Label x:Name="label_Copy" Content="Email:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,81,0,0"/>
<TextBox x:Name="txtFirstDigit_Copy1" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="130" Margin="23,55,0,192" />
<Label x:Name="label_Copy1" Content="First Name:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,25,0,0"/>
<TextBox x:Name="txtFirstDigit_Copy2" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="130" Margin="167,55,0,192" />
<Button x:Name="button" Content="Next" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="142,220,0,0"/>
<Button x:Name="button1" Content="Cancel" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="222,220,0,0" Click="button1_Click"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Margin="350,147,0,0"/>
</Grid>
</Window>
I'd try something like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="label_Copy1" Grid.Row="0" Content="First Name:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,0,0,0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBox x:Name="txtFirstDigit_Copy1" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="130" Margin="23,0,0,0" />
<TextBox x:Name="txtFirstDigit_Copy2" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="130" Margin="11.5,0,0,0" />
</StackPanel>
<Label x:Name="label_Copy" Grid.Row="2" Content="Email:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,0,0,0" />
<TextBox x:Name="txtFirstDigit_Copy" Grid.Row="3" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="270" Margin="23,0,0,0" />
<Label x:Name="label" Grid.Row="4" Content="Product key:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="23,0,0,0" />
<StackPanel Orientation="Horizontal" Grid.Row="5">
<TextBox x:Name="txtFirstDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="23,0,0,0" BorderThickness="1" />
<TextBox x:Name="txtSecondDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="11.5,0,0,0" />
<TextBox x:Name="txtThirdDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="11.5,0,0,0" />
<TextBox x:Name="txtFourthDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="11.5,0,0,0" />
<TextBox x:Name="txtFifthDigit" HorizontalAlignment="Left" Height="22" TextWrapping="Wrap" VerticalAlignment="Center" Width="45" Margin="11.5,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="6">
<Button x:Name="button" Content="Next" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="132,0,0,0" />
<Button x:Name="button1" Content="Cancel" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="11.5,0,0,0" />
</StackPanel>
</Grid>

Overlapping Grids inside a Tab

I have two grids inside a TabItem and in the code-behind I want to be able to add controls to both grids and have all the controls visible at run-time. Currently at run-time the controls added to "Grid3" are not visible while he controls added to "Grid4" are visible.
The overlapping grids have the same rows but a different set of columns.
I'm trying to do this with two grids so that I can vary the number of controls I can add per row in the code-behind by adding the controls to one of the two grids.
Here's the XML:
<Grid Name="TabControlGrid" Margin="20,171,0,70">
<TabControl >
<TabItem Header="Tab1" >
<Grid Name="InnerTabControlGrid">
<!--Start Grid3-->
<Grid Name="Grid3" Background="#FFE3EFFF" Height="188">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="98*" />
<ColumnDefinition Width="296*" />
<ColumnDefinition Width="88*" />
<ColumnDefinition Width="327*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="30*" />
</Grid.RowDefinitions>
<Grid Name="InnerGrid3" Grid.ColumnSpan="4" Grid.RowSpan="8" VerticalAlignment="Top" HorizontalAlignment="Left" Width="807">
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBlock1" Text="Row 1, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,35,0,0" Name="TextBlock2" Text="Row 2, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,60,0,0" Name="TextBlock3" Text="Row 3, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,85,0,0" Name="TextBlock4" Text="Row 4, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,110,0,0" Name="TextBlock5" Text="Row 5, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,135,0,0" Name="TextBlock6" Text="Row 6, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,160,0,0" Name="TextBlock7" Text="Row 7, Col 1" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="405,10,0,0" Name="TextBlock8" Text="Row 1, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="405,35,0,0" Name="TextBlock9" Text="Row 2, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="405,60,0,0" Name="TextBlock10" Text="Row 3, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="405,85,0,0" Name="TextBlock11" Text="Row 4, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="405,110,0,0" Name="TextBlock12" Text="Row 5, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="403,135,0,0" Name="TextBlock13" Text="Row 6, Col 2:" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="403,160,0,0" Name="TextBlock14" Text="Row 7, Col 2" VerticalAlignment="Top" Width="71" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,11,0,0" Name="ComboBox9" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,10,0,0" Name="ComboBox10" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,35,0,0" Name="ComboBox11" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,35,0,0" Name="ComboBox12" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,60,0,0" Name="ComboBox13" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,60,0,0" Name="ComboBox14" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,85,0,0" Name="ComboBox15" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,85,0,0" Name="ComboBox16" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,110,0,0" Name="ComboBox17" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,111,0,0" Name="ComboBox18" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,135,0,0" Name="ComboBox19" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,136,0,0" Name="ComboBox20" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="98,160,0,0" Name="ComboBox21" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,160,0,0" Name="ComboBox22" VerticalAlignment="Top" Width="291" Visibility="Collapsed"/>
</Grid>
</Grid>
<!--End Grid3-->
<Grid Name="Grid4" Background="#FFE3EFFF">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="97*" />
<ColumnDefinition Width="102*" />
<ColumnDefinition Width="91*" />
<ColumnDefinition Width="102*" />
<ColumnDefinition Width="87*" />
<ColumnDefinition Width="102*" />
<ColumnDefinition Width="99*" />
<ColumnDefinition Width="125*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="26*" />
<RowDefinition Height="30*" />
</Grid.RowDefinitions>
<Grid Name="InnerGrid4" Grid.ColumnSpan="8" Grid.RowSpan="8" VerticalAlignment="Top" HorizontalAlignment="Left" Width="803" Height="193">
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBlock15" Text="Row 1, Col 1" VerticalAlignment="Top" Width="73" Visibility="Collapsed" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="98,11,0,0" Name="TextBox13a" VerticalAlignment="Top" Width="100" Visibility="Collapsed" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="210,10,0,0" Name="TextBlock16" Text="Row 1, Col 2" VerticalAlignment="Top" Width="73" Visibility="Collapsed" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="289,11,0,0" Name="TextBox14a" VerticalAlignment="Top" Width="100" Visibility="Collapsed" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="410,12,0,0" Name="TextBlock17" Text="Row 1, Col 3" VerticalAlignment="Top" Width="67" Visibility="Collapsed" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,10,0,0" Name="ComboBox23" VerticalAlignment="Top" Width="100" Visibility="Collapsed" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="600,14,0,0" Name="TextBlock18" Text="Row 1, Col 4" VerticalAlignment="Top" Width="71" Visibility="Collapsed" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="680,11,0,0" Name="TextBox18a" VerticalAlignment="Top" Width="100" Visibility="Collapsed" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,35,0,0" Name="TextBlock19" Text="Row 2, Col 1" VerticalAlignment="Top" Visibility="Collapsed" Width="73" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="98,36,0,0" Name="TextBox1" VerticalAlignment="Top" Visibility="Collapsed" Width="100" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="210,35,0,0" Name="TextBlock20" Text="Row 2, Col 2" VerticalAlignment="Top" Visibility="Collapsed" Width="73" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="289,36,0,0" Name="TextBox2" VerticalAlignment="Top" Visibility="Collapsed" Width="100" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="410,37,0,0" Name="TextBlock21" Text="Row 2, Col 3" VerticalAlignment="Top" Visibility="Collapsed" Width="67" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="479,35,0,0" Name="ComboBox24" VerticalAlignment="Top" Visibility="Collapsed" Width="100" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="600,39,0,0" Name="TextBlock22" Text="Row 2, Col 4" VerticalAlignment="Top" Visibility="Collapsed" Width="71" />
<TextBox BorderBrush="#FF898C95" Height="23" HorizontalAlignment="Left" Margin="680,36,0,0" Name="TextBox3" VerticalAlignment="Top" Visibility="Collapsed" Width="100" />
</Grid>
</Grid>
</Grid>
</TabItem>
<TabItem Header="Tab2" >
</TabItem>
</TabControl>
</Grid>
The controls in the XML are just place holders for the controls I am adding to the grids in the code-behind.
If anyone can suggest a solution I'd appreciate it.
Thanks!
-mg
Remove the background from the grid. You can not see through a solid color.
Your InnerTabControlGrid does not define any Row or Column Definitions, so both child grids are placed on top of each other in a single grid cell.
Change InnerTabControlGrid to a DockPanel or a UniformGrid, or give it some Grid.ColumnDefinitions or Grid.RowDefinitions and assign your child grid's Grid.Column or Grid.Row

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