list view population using only xaml - wpf

I read a lot about the listView and still cant understand...
I defined the following listView with 5 column, the first is label and the rest are texboxes.
I need to add 13 rows that every textbox and labels needs to be bind to something diffrent.
So I understand that listViewItem wont do it because every object in the list, binds to somethin else..
Thank you for your help.
<ListView DockPanel.Dock="Top" Width="607" Height="400" Margin="10 0" HorizontalAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="1" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="2" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="3" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="4" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="5" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

you really wane do something like this?
<Grid Height="100" HorizontalAlignment="Left" Margin="22,62,0,0" Name="listBox1" VerticalAlignment="Top" Width="607">
<Grid.ColumnDefinitions>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height='30'/>
<RowDefinition Height='30'/>
</Grid.RowDefinitions>
<!-- ROW 0-->
<Label Grid.Column='0' Grid.Row='0' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='0' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='0' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='0' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='0' Text='Text04'/>
<!--Row 1-->
<Label Grid.Column='0' Grid.Row='1' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='1' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='1' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='1' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='1' Text='Text04'/>
</Grid>

I finaly did a Grid in every item in the list like this:
<ListView DataContext="{Binding CurrentMonitorCalib}" Grid.Column="5" Grid.Row="3" Height="488" Width="444" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Cal Point" Width="80"/>
<GridViewColumn Header="Source" Width="90" />
<GridViewColumn Header="Failure Limit" Width="90" />
<GridViewColumn Header="Reference" Width="90" />
<GridViewColumn Header="# DaysLimit" Width="90" />
</GridView>
</ListView.View>
<ListViewItem>
<Grid Width="441" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Zero" Margin="5,0" />
<TextBox Grid.Column="1" Text="{Binding Path=ZeroSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=ZeroFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=ZeroRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=ZeroZNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
<ListViewItem>
<Grid Width="442" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Span" Margin="5,0"/>
<TextBox Grid.Column="1" Text="{Binding Path=SpanSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=SpanFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=SpanRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=SpanNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
and so on.....
thanks for your help!

Related

Color Change in WPF MVVM

I am completely new to wpf and MVVM. I have created a code which binds the values from the listView to the Textbox and Viceversa.
The data to the list view is sent from the database.
Now I would like to change the color of the row in the list view when text in the textbox is updated.
I also have similar connection of two checkboxes with the same listview. Could you please help since I could not find a correct solution for the same.
Below is my code:
<UserControl>
<Grid HorizontalAlignment="Center" Margin="20,20,20,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="236"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="494"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Mitarbeiter Status" Margin="0,0,0,10"/>
<TextBox Grid.Row="0" Grid.Column="1" Width="261" HorizontalAlignment="Left" HorizontalContentAlignment="Center" Text="{Binding ElementName=EmployeeStatusListView, Path=SelectedItem.Status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"/>
<CheckBox Grid.Row="1" Grid.Column="0" Content="IsAdmin" Margin="0,10,0,10" IsChecked="{Binding ElementName =EmployeeStatusListView, Path=SelectedItem.IsAdmin,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True }"/>
<CheckBox Grid.Row="1" Grid.Column="1" Content="IsMandatory" Margin="0,10,0,10" IsChecked="{Binding ElementName =EmployeeStatusListView, Path=SelectedItem.IsMandatory,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,10,0,10" >
<Button Width="100" Content="Hinzufugen" Command="{Binding Path=AddCommand}" CommandParameter="{Binding ElementName=EmployeeStatusListView ,Path=SelectedItem}" Margin="100,10,30,0"/>
<Button Width="90" Content="Update" Command="{Binding Path=UpdateCommand}" CommandParameter="{Binding ElementName=EmployeeStatusListView, Path=SelectedItem}" Height="30" Margin="20,10,30,0" />
<Button Width="90" Content="Löschen" Command="{Binding Path=DeleteCommand}" CommandParameter="{Binding ElementName=EmployeeStatusListView, Path=SelectedItem}" Height="30" Margin="20,10,30,0" />
</StackPanel>
<ListView SelectedItem="EmployeeStatusSelect" SelectedIndex="0" Grid.Row="3" Grid.ColumnSpan="2" Name="EmployeeStatusListView" ItemsSource="{Binding EmployeeStatusList}" RenderTransformOrigin="0.502,0.66" Margin="0,20,0,-19" >
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="120" DisplayMemberBinding="{Binding Id, Mode=TwoWay}"/>
<GridViewColumn Header="Mitarbeiter Admin Nummer " Width="200" DisplayMemberBinding="{Binding IsAdmin}"/>
<GridViewColumn Header="Mitarbeiter Status " Width="200" DisplayMemberBinding="{Binding Status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<GridViewColumn Header="Mandantory " Width="200" DisplayMemberBinding="{Binding IsMandatory, Mode=TwoWay}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>

ListView not stretching to fit content WPF XAML

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

How to highlight text in textbox when it gets focus

This seems a simple question but I was not able to find the answer in the web. The only thing I want consists in to get the content hightlighted in the textbox, when the user gets in ('Price' or 'Quantity' in this example). Right now it's necessary double click first in order to edit the content.
The content should be selected automatically when it get's focus.
How can I do this?
Thank you
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="350" Width="479" Name="Window1">
<Window.Resources>
<CollectionViewSource x:Key="MasterView" />
<CollectionViewSource Source="{Binding Source={StaticResource MasterView}, Path='OrderDetails'}" x:Key="DetailView" />
<CollectionViewSource x:Key="CustomerLookup" />
<CollectionViewSource x:Key="ProductLookup" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="42" />
<RowDefinition Height="110" />
<RowDefinition Height="42" />
<RowDefinition Height="147*" />
</Grid.RowDefinitions>
<Grid Grid.Row="1" Name="Grid1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="146*" />
<ColumnDefinition Width="346*" />
</Grid.ColumnDefinitions>
<StackPanel Name="StackPanel1" >
<Label Height="28" Name="Label1" Width="Auto" HorizontalContentAlignment="Right">ID:</Label>
<Label Height="28" Name="Label2" Width="Auto" HorizontalContentAlignment="Right">Customer:</Label>
<Label Height="28" Name="Label3" Width="Auto" HorizontalContentAlignment="Right">Order Date:</Label>
<Label Height="28" Name="Label4" Width="Auto" HorizontalContentAlignment="Right">Ship Date:</Label>
</StackPanel>
<StackPanel Name="StackPanel2" Grid.Column="1" DataContext="{Binding Source={StaticResource MasterView}}">
<TextBox Height="23" Name="TextBox1" Width="100" Margin="2" HorizontalAlignment="Left" IsReadOnly="True"
Text="{Binding Path=OrderID, Mode=OneWay}"/>
<ComboBox Height="23" Name="ComboBox1" Width="177" Margin="2" HorizontalAlignment="Left"
IsEditable="False"
ItemsSource="{Binding Source={StaticResource CustomerLookup}}"
SelectedValue="{Binding Path=CustomerID}"
SelectedValuePath="CustomerID"
DisplayMemberPath="Name"/>
<TextBox Height="23" Name="TextBox3" Width="100" Margin="2" HorizontalAlignment="Left"
Text="{Binding Path=OrderDate}"/>
<TextBox Height="23" Name="TextBox4" Width="100" Margin="2" HorizontalAlignment="Left"
Text="{Binding Path=ShipDate}"/>
</StackPanel>
</Grid>
<StackPanel Name="StackPanel3" Orientation="Horizontal">
<Button Height="25" Name="btnAdd" Width="Auto" Margin="3">Add Order</Button>
<Button Height="25" Name="btnDelete" Width="Auto" Margin="3">Delete Order</Button>
<Button Height="25" Name="btnPrevious" Width="75" Margin="3">Previous</Button>
<Button Height="25" Name="btnNext" Width="75" Margin="3">Next</Button>
<Button Height="25" Name="btnSave" Width="75" Margin="3">Save</Button>
</StackPanel>
<StackPanel Name="StackPanel4" Orientation="Horizontal" Grid.Row="2">
<Button Height="25" Name="btnAddDetail" Width="Auto" Margin="3">Add Detail</Button>
<Button Height="25" Name="btnDeleteDetail" Width="Auto" Margin="3">Delete Detail</Button>
</StackPanel>
<ListView Grid.Row="3" Name="ListView1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource DetailView}}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<EventSetter Event="GotFocus" Handler="Item_GotFocus" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=OrderDetailID}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="OrderID" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=OrderID}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Product" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="False"
Name="cboProduct"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Source={StaticResource ProductLookup}}"
SelectedValue="{Binding Path=ProductID}"
DisplayMemberPath="Name"
SelectedValuePath="ProductID"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Quantity" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Quantity}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Price" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Price}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
You have to use the TextBox.SelectAll property. You can manually wire it up on a per-textbox or per-window basis, or you can do it more globally. this article describes one method for doing it globally, and this answer describes another.

How to use gridsplitter on dynamic layout?

For the life of me I can't get the gridsplitter control to behave in the way I want.
In the below layout, I need a gridspliter to the right of each listview, that will expand or contract that listview and resize the other listviews appropriately.
The expanders and their (green) panels should not resize.
Please help! This control is driving me nuts.
MainWindow.xaml:
<Window x:Class="LayoutTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="400" MinWidth="1000">
<Grid Name="root" SizeChanged="root_SizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xleft" Grid.Column="1" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="2" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xmiddle" Grid.Column="3" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="4" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xright" Grid.Column="5" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
</Grid>
</Window>
MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Controls;
namespace LayoutTest
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
public partial class MainWindow : Window
{
Expander[] expanders;
Expander priority;
public MainWindow()
{
InitializeComponent();
expanders = new Expander[] {xleft,xmiddle,xright};
}
private void Expanded(object sender, RoutedEventArgs e)
{
if (sender is Expander) priority = sender as Expander;
if (root.ActualWidth > this.ActualWidth)
{
foreach (Expander ep in expanders)
{
if (ep.IsExpanded && priority != null && !ep.Name.Equals(priority.Name) )
{
ep.IsExpanded = false;
break;
}
}
}
}
private void root_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expanded(null,new RoutedEventArgs());
}
}
}
It's not ideal, but this is the solution I'm going with:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="Green">
</Border>
<Expander Name="ex1" Grid.Column="1" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Left" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Right" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<Border Grid.Column="2" Background="Green">
</Border>
<Expander Name="ex2" Grid.Column="3" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
<GridSplitter Grid.Column="3" Width="5" HorizontalAlignment="Left" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<GridSplitter Grid.Column="3" Width="5" HorizontalAlignment="Right" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<Border Grid.Column="4" Background="Green">
</Border>
<Expander Name="ex3" Grid.Column="5" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
</Grid>

WPF How to Scroll ListView embedded in Grid

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

Resources