2 Listview Scroll Synchronization - wpf

I Need Vertical Scroll to be synchronized with 2 Listview - inside Gridview in view.
Only the Row should be scrolled not the header.
I have been used http://www.codeproject.com/Articles/39244/Scroll-Synchronization
<ListView Name="ListBox1" Margin="0,0,5,0" >
<ListView.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="local:ScrollSynchronizer.ScrollGroup" Value="Group1" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView x:Name="grid1Control" >
<GridViewColumn Header="12">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid >
<TextBox Text="123" Height="30" Width="120"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListView Name="ListBox2" Grid.Column="1" Margin="5,0,0,0" >
<ListView.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="local:ScrollSynchronizer.ScrollGroup" Value="Group1" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView x:Name="grid2Control" >
<GridViewColumn Header="12">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid >
<TextBox Text="123" Height="30" Width="120"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Above code not working

Related

Focus on unselected listViewitem

I have 2 listViews as shown below.
When I select an item in the first listView it gets Highlighted, but when I select an item in the second listView, the first selected item from the first listView losses its highlightning. I dont want this to happen, I want both items to be highlighted. Any help?
<ListView x:Name="listViewDevice" ItemsSource="{Binding NotMappedInputAttributes}" KeyboardNavigation.TabIndex="6" SelectedItem="{Binding SelectedInputAttribute}" Grid.Column="2" Margin="5,27,5,32" Grid.Row="1" Grid.ColumnSpan="2">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="150">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="150">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding TypeName}"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Device" Width="150">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding HostDevice.SimulationMemberName}"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<TextBox x:Name="textBox" Text="{Binding SearchColumns, UpdateSourceTrigger=PropertyChanged}" Margin="5,0" TextWrapping="Wrap" Height="22" VerticalAlignment="Top" KeyboardNavigation.TabIndex="0" Grid.Row="1" />
<TextBox x:Name="textBox_Copy" Text="{Binding SearchInputAttributes, UpdateSourceTrigger=PropertyChanged}" KeyboardNavigation.TabIndex="5" Margin="5,0" TextWrapping="Wrap" Grid.Column="2" Height="22" VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="2"/>
<ListView x:Name="treeViewCsvFiles" KeyboardNavigation.TabIndex="1" ItemsSource="{Binding CsvColumns}" VirtualizingPanel.IsVirtualizing="True" Margin="5,27,5,32" SelectedItem="{Binding SelectedCsvColumn}" Grid.Row="1">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="File">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding File.Name}"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Time Column">
<GridViewColumn.CellTemplate>
<HierarchicalDataTemplate>
<CheckBox IsChecked="{Binding IsTimeColumn, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"/>
</HierarchicalDataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I would recommend you to see this answer and this other answer. Some people had the same problem as you have now.

Remove Extra "Space" using List View and GridView

So I am using a Grid View inside of a List View and when I run my application I get this weird spacing stuff before the row of my items, between the items, and at the end (can't see in picture), which I want to remove. Here is my XAML.
<ListView x:Name="schemaTableListView"
Width="600"
Height="50"
Margin="0,550,0,0"
ItemsSource="{Binding phase}">
<ListView.View>
<GridView >
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="IsEnabled" Value="False" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Width="300" Header="Source Schema">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="300" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="300" Header="Source Table">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="300" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Does anyone know how to remove this? I tried setting the padding to 0 and several other things, but couldn't get it to go away. I bet it is something simple.
The easiest way is to set negativ margin
<ListView>
<ListView.View>
<GridView >
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="IsEnabled" Value="False" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Width="300" Header="Source Schema">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="300" Margin="-6,0" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="300" Header="Source Table">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="300" Margin="-6,0" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

WPF ListView cursor dosen't change when resizing a column

The cursor doesn't change when the mouse is in the header column to resize the column width. The column does resize, but the cursor remains as an arrow.
Does the ListView control not do this? If so, how to get the cursor to change when it is over the column resizing thumb?
<ListView Name="Listing"
Grid.Row="1" Grid.Column="2"
Margin="0,0,0,0"
FontSize="12"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SelectionChanged="ListView_SelectionChanged"
MouseDoubleClick="ListView_MouseDoubleClick"
>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="22" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Width="180">
<GridViewColumn.Header>
<GridViewColumnHeader Content="File" HorizontalContentAlignment="Left"/>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn Width="100" >
<GridViewColumn.Header>
<GridViewColumnHeader Content="Size" HorizontalContentAlignment="Left"/>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate >
<DataTemplate>
<TextBlock Text="{Binding Length, StringFormat={}{0:#\,##0;(#\,##0); }}" TextAlignment="Right" HorizontalAlignment="Stretch"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding LastWriteTime, StringFormat={}{0:yyyy.MMM.dd h:mm tt}}" Width="140">
<GridViewColumn.Header>
<GridViewColumnHeader Content="Date Modified" HorizontalContentAlignment="Left"/>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding FileType}" Width="180">
<GridViewColumn.Header>
<GridViewColumnHeader Content="Type" HorizontalContentAlignment="Left"/>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

Content alignment for Gridviewcolumn in the listview

Please see the picture below
Following is the code for this ::
<Grid>
<ListView Style="{StaticResource listViewStyle}" Name="transactionListView" HorizontalAlignment="Stretch" VerticalAlignment="Top" ItemsSource="{Binding}" MouseDoubleClick="transactionListView_MouseDoubleClick" IsSynchronizedWithCurrentItem="True" >
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource gridViewHeaderColumnStyle}">
<GridView.Columns>
<GridViewColumn Width="70" Header="Serial" DisplayMemberBinding="{Binding Path=Serial}" />
<GridViewColumn Width="100" Header="Date" DisplayMemberBinding="{Binding Path=Date, StringFormat={}{0:dd-MM-yyyy}}" />
<GridViewColumn Width="200" Header="Seller" DisplayMemberBinding="{Binding Path=Seller}" />
<GridViewColumn Width="200" Header="Buyer" DisplayMemberBinding="{Binding Path=Buyer}" />
<GridViewColumn Width="70" Header="Bales" DisplayMemberBinding="{Binding Path=Bales}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
Do you want to center to content for all your cells? In that case you can add HorizontalContentAlignment for ListViewItem
<ListView ...>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</ListView.ItemContainerStyle>
<!--...-->
</ListView>

Using the same style in many listviews

I want to use the same style in many listviews. And in my style i have defined the gridview columns also.
But when i try to run, it throws an exception:
View can't be shared by more than one
ListView.
How can i solve this?
XAML:
<Style x:Key="articleList" TargetType="{x:Type ListView}">
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="True"/>
<Setter Property="ListView.ItemsSource" Value="{Binding}"/>
<Setter Property="ListView.View">
<Setter.Value>
<GridView>
<GridViewColumn Header="Subject" Width="300">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Subject}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Size" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding SizeFormatted}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Poster" Width="175">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Poster}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Age" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding AgeFormatted}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</Setter.Value>
</Setter>
Add the x:Shared property to your GridView resource. Check out the GridView resource in this example.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<GridView x:Key="ViewBase1" x:Shared="False">
<GridViewColumn Header="Blah1" Width="70"/>
<GridViewColumn Header="Blah2" Width="70"/>
<GridViewColumn Header="Blah3" Width="70"/>
</GridView>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ListView Margin="0,0,0,120" View="{DynamicResource ViewBase1}" />
<ListView Margin="272,0,91,120" View="{DynamicResource ViewBase1}" />
</Grid>
</Window>

Resources